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

/// # Panics
///
/// Panics if `pat.kind` is `PatKind::Missing`.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could've made Missing an intra-doc link to ensure that we update the docs if it were to get removed or renamed (hypothetically). Doesn't really matter though.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

No, it can also appear in trait methods in the 2015 edition:

trait Trait { fn method(Option<i32>); }

However, since we explicitly handle items in visit_items (like we handle types now, too, in visit_ty), that didn't lead to an ICE in rustdoc.

@fmease
Copy link
Member

fmease commented Dec 21, 2025

@bors r+ rollup

@bors
Copy link
Collaborator

bors commented Dec 21, 2025

📌 Commit 74af408 has been approved by fmease

It is now in the queue for this repository.

@bors bors removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Dec 21, 2025
@bors bors added the S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. label Dec 21, 2025
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Dec 21, 2025
…ease

rustdoc: handle macro expansions in types

- Closes rust-lang#150154.
- Closes rust-lang#150197.

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:
<img width="419" height="182" alt="image" src="https://github.com/user-attachments/assets/89627230-032d-4ba1-af2e-8aa9a9cc6627" />
After:
<img width="288" height="107" alt="image" src="https://github.com/user-attachments/assets/c06caeda-28b7-45b8-845a-e7fe784a82e4" />
bors added a commit that referenced this pull request Dec 21, 2025
…uwer

Rollup of 4 pull requests

Successful merges:

 - #149512 (Fix d32 usage in Arm target specs )
 - #150210 (tests/debuginfo/function-arg-initialization.rs: Stop disabling SingleUseConsts MIR pass)
 - #150221 (rustdoc: handle macro expansions in types)
 - #150223 (GVN: Adds the `insert_unique` method)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit e0dba51 into rust-lang:main Dec 22, 2025
11 checks passed
@rustbot rustbot added this to the 1.94.0 milestone Dec 22, 2025
rust-timer added a commit that referenced this pull request Dec 22, 2025
Rollup merge of #150221 - el-ev:missing-par-ice-150154, r=fmease

rustdoc: handle macro expansions in types

- Closes #150154.
- Closes #150197.

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:
<img width="419" height="182" alt="image" src="https://github.com/user-attachments/assets/89627230-032d-4ba1-af2e-8aa9a9cc6627" />
After:
<img width="288" height="107" alt="image" src="https://github.com/user-attachments/assets/c06caeda-28b7-45b8-845a-e7fe784a82e4" />
@el-ev el-ev deleted the missing-par-ice-150154 branch December 22, 2025 05:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. 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

6 participants