Skip to content

Don't return dummy MacroData in get_macro#156151

Open
mejrs wants to merge 1 commit intorust-lang:mainfrom
mejrs:non_macro_attr
Open

Don't return dummy MacroData in get_macro#156151
mejrs wants to merge 1 commit intorust-lang:mainfrom
mejrs:non_macro_attr

Conversation

@mejrs
Copy link
Copy Markdown
Contributor

@mejrs mejrs commented May 4, 2026

I was experimenting with tool attributes and ast manipulation, and wasted some time figuring out that this was happening. AFAIK all users of get_macro are expecting an actual macro (and none were reading the dummy MacroData) so there should be no change in behavior.

@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. labels May 4, 2026
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented May 4, 2026

r? @JohnTitor

rustbot has assigned @JohnTitor.
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

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: compiler
  • compiler expanded to 73 candidates
  • Random selection from 20 candidates

@petrochenkov petrochenkov self-assigned this May 4, 2026
Comment thread compiler/rustc_resolve/src/macros.rs Outdated
@JohnTitor
Copy link
Copy Markdown
Member

r? petrochenkov for further review

Comment thread compiler/rustc_resolve/src/build_reduced_graph.rs Outdated
Comment thread compiler/rustc_resolve/src/build_reduced_graph.rs
@petrochenkov petrochenkov 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 May 5, 2026
@mejrs mejrs force-pushed the non_macro_attr branch from 98db5e2 to a2efa01 Compare May 5, 2026 20:29
@mejrs mejrs 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 May 5, 2026
@rust-log-analyzer

This comment has been minimized.

@mejrs mejrs force-pushed the non_macro_attr branch from a2efa01 to b4d656a Compare May 5, 2026 21:16
Comment thread tests/ui/cfg/reserved-macro-names-rename.rs Outdated
Comment thread compiler/rustc_resolve/src/macros.rs
Comment thread compiler/rustc_resolve/src/build_reduced_graph.rs
@petrochenkov petrochenkov 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 May 6, 2026
@mejrs mejrs force-pushed the non_macro_attr branch from b4d656a to 9ecd36b Compare May 6, 2026 11:48
@mejrs mejrs 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 May 6, 2026
Comment thread compiler/rustc_resolve/src/build_reduced_graph.rs Outdated
}
_ => None,
},
None => self.get_macro(res).map(|macro_data| Arc::clone(&macro_data.ext)),
Copy link
Copy Markdown
Contributor

@petrochenkov petrochenkov May 6, 2026

Choose a reason for hiding this comment

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

This change is also no longer necessary.

View changes since the review

Copy link
Copy Markdown
Contributor Author

@mejrs mejrs May 6, 2026

Choose a reason for hiding this comment

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

My primary motivation for this change here (and this PR in general) is that this is something I ran into while trying to make a diagnostic attribute act like a syntax extension; a macro named (say) "on_unimplemented" in a module named "diagnostic" takes precedence over a similarly named tool attribute, so I can't use (just) get_macro to tell whether to insert that syntax extension or not.

But I'll need to think some more about how to best do that; I think that's going to end up looking like this change. Happy to do it later though; I've dropped it.

@petrochenkov petrochenkov 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 May 6, 2026
@mejrs mejrs force-pushed the non_macro_attr branch from 9ecd36b to 6312fbd Compare May 6, 2026 12:25
@rust-log-analyzer
Copy link
Copy Markdown
Collaborator

The job pr-check-2 failed! Check out the build log: (web) (plain enhanced) (plain)

Click to see the possible cause of the failure (guessed by this bot)
[RUSTC-TIMING] rustc_log test:false 0.078
[RUSTC-TIMING] thiserror test:false 0.033
    Checking jiff v0.2.16
[RUSTC-TIMING] shlex test:false 0.099
error[E0609]: no field `ext` on type `&Arc<SyntaxExtension>`
   --> compiler/rustc_resolve/src/macros.rs:885:81
    |
885 |             None => self.get_macro(res).map(|macro_data| Arc::clone(&macro_data.ext)),
    |                                                                                 ^^^ unknown field
    |
    = note: available fields are: `kind`, `span`, `allow_internal_unstable`, `stability`, `deprecation` ... and 7 others

For more information about this error, try `rustc --explain E0609`.
[RUSTC-TIMING] rustc_resolve test:false 3.133
error: could not compile `rustc_resolve` (lib) due to 1 previous error
warning: build failed, waiting for other jobs to finish...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants