Skip to content

fresh binding should shallow the def after expand #143141

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

bvanjoi
Copy link
Contributor

@bvanjoi bvanjoi commented Jun 28, 2025

@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 Jun 28, 2025
@@ -217,6 +217,8 @@ pub(crate) enum RibKind<'ra> {
/// We passed through a `macro_rules!` statement
MacroDefinition(DefId),

LookAheadMacroDefinition(DefId),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The reason for using RibKind::LookAheadMacroDefinition instead of RibKind::MacroDefinition is to prevent cases like:

fn f() {
    let x = 0;
    macro_rules! foo { () => {
        assert_eq!(x, 0); // it will make `x` equal `1` if we use `RibKind::MacroDefinition`
    } }

    let x = 1;
    foo!();
}

fn f3() {
let f = || -> i16 { 42 };

let a: i16 = m!();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This case would previously fail to compile.

fn f() -> i8 { 42 }
let f = || -> i16 { 42 };

let a: i16 = m!();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is breaking changes, should we run crate tests?

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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Hygiene of used macro item is weird.
3 participants