dtolnay/paste

Ident concatenation doesn't work

BratSinot opened this issue · 1 comments

Greetings!

Ident concatenation doesn't work for some reason:

macro_rules! gen_limit {
    ($name:ident, $limit:literal) => {
        paste::paste! {
            let [<number_of_ $name>] = std::env::var(stringify!([<NUMBER_OF_ $name:upper>]))
                .as_deref()
                .unwrap_or($limit)
                .parse::<usize>()
                .expect(concat!("Wrong ", stringify!([<NUMBER_OF_ $name:upper>])));
        }
    };
}

fn main() {
    gen_limit!(test, "100");
    println!("{number_of_test}");
}
error[E0425]: cannot find value `number_of_test` in this scope
  --> src/main.rs:15:16
   |
15 |     println!("{number_of_test}");
   |                ^^^^^^^^^^^^^^ not found in this scope

error: aborting due to previous error

For more information about this error, try `rustc --explain E0425`.
error: could not compile `playground` due to 2 previous errors
Process finished with exit code 101

But without it everything work fine:

macro_rules! gen_limit {
    ($name:ident, $limit:literal) => {
        paste::paste! {
            let $name = std::env::var(stringify!([<$name:upper>]))
                .as_deref()
                .unwrap_or($limit)
                .parse::<usize>()
                .expect(concat!("Wrong ", stringify!([<$name:upper>])));
        }
    };
}

fn main() {
    gen_limit!(number_of_test, "100");
    println!("{number_of_test}");
}
100

Closing as a duplicate of #80.