Can't paste together `use` import
thomwiggers opened this issue · 2 comments
thomwiggers commented
I'm trying to construct an identifier of a namespace from parts, but that does not seem to be supported.
use paste::paste;
mod test {
const X: u32 = 2;
}
use paste!{ [< te st >] }::X;
fn main() {
println!("Hello, world!, {}", X);
}
results in
Compiling playground v0.0.1 (/playground)
error: expected one of `::`, `;`, or `as`, found `!`
--> src/main.rs:7:10
|
7 | use paste!{ [< te st >] }::X;
| ^ expected one of `::`, `;`, or `as`
error: aborting due to previous error
error: could not compile `playground`
marmidr commented
I think this is not related to the use
keyword, but rather attempt to glue tokens with special characters, like :
.
In my case, I can't glue Enum class name and it's enumerator
enum States{
Unknowm,
On,
Off
}
let x = paste!{ [<States:: Off>] ; }
error: expected identifier after :
Surprised BTW - the ## operator in C/C++ is so simple and obvious :/
dtolnay commented
In @thomwiggers snippet use macroname!{...}
is not valid Rust syntax. You'd want to write:
paste! {
use [<te st>]::X;
}