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
@JohnTitor
Copy link
Copy Markdown
Member

r? petrochenkov for further review

@@ -204,7 +204,6 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
pub(crate) fn get_macro(&self, res: Res) -> Option<&'ra MacroData> {
Copy link
Copy Markdown
Contributor

@petrochenkov petrochenkov May 5, 2026

Choose a reason for hiding this comment

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

Suggested change
pub(crate) fn get_macro(&self, res: Res) -> Option<&'ra MacroData> {
pub(crate) fn get_macro(&self, res: Res) -> Option<&'ra Arc<SyntaxExtension>> {

Looks like the MacroData parts are never actually used.

View changes since the review

pub(crate) fn get_macro(&self, res: Res) -> Option<&'ra MacroData> {
match res {
Res::Def(DefKind::Macro(..), def_id) => Some(self.get_macro_by_def_id(def_id)),
Res::NonMacroAttr(_) => Some(self.non_macro_attr),
Copy link
Copy Markdown
Contributor

@petrochenkov petrochenkov May 5, 2026

Choose a reason for hiding this comment

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

I think this is incorrect in the check_reserved_macro_name case as well, not just in resolve_macro_or_delegation_path.
Something like use ignore as cfg; will now be accepted.

I'd rather not make this change in general, it seems error-prone.

View changes since the review

@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
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.

4 participants