forked from Veykril/tlborm
-
Notifications
You must be signed in to change notification settings - Fork 35
Open
Description
在2.3.3章中,我使用count示例去测试: 如下是我的代码:
#![feature(macro_metavar_expr)]
macro_rules! foo {
( $( $outer:ident ( $( $inner:ident ),* ) ; )* ) => {
println!("count(outer, 0): $outer repeats {} times", ${count(outer)});
println!("count(inner, 0): The $inner repetition repeats {} times in the outer repetition", ${count(inner)});
println!("count(inner, 1): $inner repeats {} times in the inner repetitions", ${count(inner, 1)});
};
}
fn main() {
foo! {
outer () ;
outer ( inner , inner ) ;
outer () ;
outer ( inner ) ;
};
}这时候的输出是:
count(outer, 0): $outer repeats 4 times
count(inner, 0): The $inner repetition repeats 3 times in the outer repetition
count(inner, 1): $inner repeats 3 times in the inner repetitions
而如果我把${count(inner)改为${count(inner, 0)后, 输出变成了:
count(outer, 0): $outer repeats 4 times
count(inner, 0): The $inner repetition repeats 4 times in the outer repetition
count(inner, 1): $inner repeats 3 times in the inner repetitions
我的版本是:
rustup 1.24.3 (ce5817a94 2021-05-31)
info: This is the version for the rustup toolchain manager, not the rustc compiler.
info: The currently active rustc version is rustc 1.64.0-nightly (2f3ddd9f5 2022-06-27)
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels