Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

count(ident, depth)这一节的语法错误 #13

Closed
yIllusionSky opened this issue Dec 2, 2024 · 2 comments
Closed

count(ident, depth)这一节的语法错误 #13

yIllusionSky opened this issue Dec 2, 2024 · 2 comments

Comments

@yIllusionSky
Copy link

我的rust版本是1.85.0-nightly

这是书中的写法:

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, 0)});
        println!("count(inner, 1): $inner repeats {} times in the inner repetitions", ${count(inner, 1)});
    };
}

这种写法会导致错误

在我添加$后写法正确,可能是因为后面版本语法改了?

修改后的写法:

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, 0)});
        println!("count(inner, 1): $inner repeats {} times in the inner repetitions", ${count($inner, 1)});
    };
}
@yIllusionSky
Copy link
Author

看了下ignore也有同样问题,需要加$。
再就是length(depth)变成了len(depth)
可能跟新版本变动有关

@zjp-CN
Copy link
Owner

zjp-CN commented Dec 2, 2024

谢谢你发现的问题。

是的,这些最近变化了: rust-lang/rust#122808

我现在更新一下它们。

@zjp-CN zjp-CN closed this as completed in 2508e7c Dec 2, 2024
github-actions bot added a commit that referenced this issue Dec 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants