A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/rust-lang/rust/issues/22462 below:

Macro hygiene for patterns breaks due to static/const in scope · Issue #22462 · rust-lang/rust · GitHub

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


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4