Skip to content

Fix resolution in macro-generated items within the same block - #162545

Open
Elizafox wants to merge 1 commit into
rust-lang:mainfrom
Elizafox:issue-52389
Open

Elizafox wants to merge 1 commit into
rust-lang:mainfrom
Elizafox:issue-52389

Conversation

@Elizafox

@Elizafox Elizafox commented Sep 9, 2026

Copy link
Copy Markdown

This is a simple one-line fix and regression test for macro-generated items within the same block.

Fixes #52389

@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 Sep 9, 2026
@rustbot

rustbot commented Sep 9, 2026

Copy link
Copy Markdown
Collaborator

Thanks for the pull request, and welcome! The Rust Project has assigned @chenyukang (or someone else) to review your changes, you should hear from them (or someone else) within the next two weeks.

Please see the contribution instructions and our LLM policy for more information.

Why was this reviewer chosen?

The reviewer was selected based on:

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

@rustbot

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

} else if let RibKind::Block(Some(module)) = rib.kind
&& let Ok(binding) = self.cm_mut().resolve_ident_in_scope_set(
ident,
orig_ident,

@chenyukang chenyukang Sep 11, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

You can not just or orig_ident, this program:

#![feature(decl_macro)]

fn main() {
    let helper = || "outer local";
    {
        fn helper() -> &'static str {
            "inner item"
        }
        macro call_helper() {
            helper()
        }
        assert_eq!(call_helper!(), "inner item");
    }
}

compiled and will find wrong helper with this change:

thread 'main' (57310377) panicked at /tmp/now.rs:12:9:
assertion `left == right` failed
  left: "outer local"
 right: "inner item"
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

View changes since the review

@chenyukang

Copy link
Copy Markdown
Member

@rustbot author

@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 Sep 15, 2026
@rustbot

rustbot commented Sep 15, 2026

Copy link
Copy Markdown
Collaborator

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

This branch has not been deployed

No deployments
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.

Macros 2.0: macro defined and used in same function-like scope can't resolve its own items

4 participants