Skip to content

Conversation

@el-ev
Copy link
Contributor

@el-ev el-ev commented Dec 21, 2025

This PR implements visit_ty in ExpandedCodeVisitor to correctly handle macro expansions in type positions (e.g., let _: foo!();). This also fixes a crash in rustdoc caused by the same issue.

Before:
image
After:
image

@rustbot
Copy link
Collaborator

rustbot commented Dec 21, 2025

r? @notriddle

rustbot has assigned @notriddle.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. T-rustdoc-frontend Relevant to the rustdoc-frontend team, which will review and decide on the web UI/UX output. labels Dec 21, 2025
/* Pat isn't normalized, but the beauty of it is that it doesn't matter */
match &pat.kind {
PatKind::Missing => unreachable!(),
PatKind::Missing => {}
Copy link
Member

@fmease fmease Dec 21, 2025

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.

Copy link
Member

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.

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Dec 21, 2025
@rustbot
Copy link
Collaborator

rustbot commented Dec 21, 2025

Reminder, once the PR becomes ready for a review, use @rustbot ready.

@fmease fmease assigned fmease and unassigned notriddle Dec 21, 2025
@el-ev el-ev force-pushed the missing-par-ice-150154 branch from 39601b4 to b996a98 Compare December 21, 2025 13:08
@el-ev el-ev changed the title rustdoc: tolerate PatKind::Missing in rustc_ast_pretty rustdoc: skip PatKind::Missing in visit_pat Dec 21, 2025
@el-ev
Copy link
Contributor Author

el-ev commented Dec 21, 2025

@rustbot ready

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Dec 21, 2025
@el-ev
Copy link
Contributor Author

el-ev commented Dec 21, 2025

Maybe this is not needed, as PatKind::Missing only appears in types. ccc3e42 should handle the two issues at once.

@el-ev el-ev force-pushed the missing-par-ice-150154 branch from b996a98 to d3fc809 Compare December 21, 2025 15:14
@el-ev el-ev changed the title rustdoc: skip PatKind::Missing in visit_pat rustdoc: handle macro expansions in types Dec 21, 2025
@el-ev el-ev requested a review from fmease December 21, 2025 15:18
@rust-log-analyzer

This comment has been minimized.

@el-ev el-ev force-pushed the missing-par-ice-150154 branch from d3fc809 to 74af408 Compare December 21, 2025 15:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. T-rustdoc-frontend Relevant to the rustdoc-frontend team, which will review and decide on the web UI/UX output.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

rustdoc: generate-macro-expansion produces incorrect expansion for macros in type position ICE: rustdoc: unreachable

5 participants