dtolnay / paste

Macros for all your token pasting needs
Apache License 2.0
983 stars 53 forks source link

Cannot use with an expr containing "::": expected identifier after `:` #97

Closed awoimbee closed 1 year ago

awoimbee commented 1 year ago

I want to use this crate to template function names that are not in the current module. It's because I have a weird use-case where I have routes like get_blob, get_blob_2level, ... here.

This example speaks for itself:

/// calls ${fn}(), ${fn}_1(), ${fn}_2()
macro_rules! super_caller {
    ($fn:expr) => {
        paste::paste! {
            $fn();
            [< $fn _1 >]();
            [< $fn _2 >]();
        }
    }
}

fn toto() {}
fn toto_1() {}
fn toto_2() {}

fn main() {
    super_caller!(toto); // OK
    super_caller!(crate::toto); // expected identifier after `:`
}
dtolnay commented 1 year ago

I think this is working as intended -- crate::toto_1 is not a valid identifier.