-
-
Notifications
You must be signed in to change notification settings - Fork 14.3k
rustdoc: handle macro expansions in types #150221
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
|
r? @notriddle rustbot has assigned @notriddle. Use |
| /* Pat isn't normalized, but the beauty of it is that it doesn't matter */ | ||
| match &pat.kind { | ||
| PatKind::Missing => unreachable!(), | ||
| PatKind::Missing => {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not the way to go about it. This should remain a panic since the callers should handle this pattern in a special way.
I'm pretty sure that this will lead to fn(: Ty) getting printed instead of fn(Ty). To fix this, callers should only print the pattern & the colon if the pattern isn't missing.
On my phone but I'm curious why we're only seeing this ICE now. This should be super simple to trigger via rustc -Zunpretty=normal or rustc -Zunpretty=expanded. Need to check.
Edit: Curiously, rustc correctly prints such signatures under both these modes, whether macro-generated or not, so I'm not sure yet how rustdoc is able to make ast-pretty reach this case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah okay, so rustdoc manually calls pat_to_string inside macro_expansion. We should probably add a Panics section to pat_to_string instructing users to never print Missing since they should handle it on their own. And then we need to update rustdoc to do exactly that.
|
Reminder, once the PR becomes ready for a review, use |
39601b4 to
b996a98
Compare
PatKind::Missing in rustc_ast_prettyPatKind::Missing in visit_pat
|
@rustbot ready |
|
Maybe this is not needed, as |
b996a98 to
d3fc809
Compare
PatKind::Missing in visit_pat
This comment has been minimized.
This comment has been minimized.
d3fc809 to
74af408
Compare
generate-macro-expansionproduces incorrect expansion for macros in type position #150197.This PR implements
visit_tyinExpandedCodeVisitorto correctly handle macro expansions in type positions (e.g.,let _: foo!();). This also fixes a crash in rustdoc caused by the same issue.Before:


After: