Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Macro hygiene for patterns breaks due to static/const in scope #22462

Copy link
Copy link
@pnkfelix

Description

@pnkfelix
Issue body actions

Does macro hygiene simply not work with respect to static identifiers in our model of syntax expansion?

For example:

macro_rules! foo {
    ($e:expr) => ({
        let value = $e;
        value
    })
}

fn main() {
    static value: i32 = 4; // comment out this line and things work
    let x = foo!(3);
    println!("x: {}", x);
}

I would have hoped that my use of the name value in the macro foo is irrelevant to the use of the name value in the body of main.

But currently one gets:

<anon>:3:13: 3:18 error: static variables cannot be referenced in a pattern, use a `const` instead
<anon>:3         let value = $e;
                     ^~~~~
<anon>:1:1: 6:2 note: in expansion of foo!
<anon>:10:13: 10:21 note: expansion site
error: aborting due to previous error
playpen: application terminated with error code 101

This is a shame because the box-desugaring #22181 expands into a { ... let value = ...; ... }, and there is a static binding of value in src/test/run-pass/drop-struct-as-object.rs

Metadata

Metadata

Assignees

Labels

A-macrosArea: All kinds of macros (custom derive, macro_rules!, proc macros, ..)Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..)

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

    Morty Proxy This is a proxified and sanitized view of the page, visit original site.