Skip to content

break and continue are not hygienic #12262

Closed
@flaper87

Description

@flaper87

Working on #6993 specifically on #12179 raised the fact that break and continue use Name as opposed of Ident. This was introduced in #9103 and unfortunately this change seems to have made them non-hygienic.

An example taken from @huonw comment:

#[feature(macro_rules)];

macro_rules! foo {
    ($e: expr) => {
        // $e shouldn't be able to interact with this 'x
        'x: loop { $e }
    }
}

fn main() {
    'x: loop {
        // i.e. this 'x should refer to the outer loop, but may be "captured"
        // by the 'x declaration inside foo
        foo!(break 'x);
        println!("should not be printed")
    }
}

Presumably, reverting the change should make them hygienic again.

I volunteer as a mentor for this fix.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-parserArea: The lexing & parsing of Rust source code to an ASTA-resolveArea: Name/path resolution done by `rustc_resolve` specificallyA-syntaxextArea: Syntax extensionsE-mentorCall for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions