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

「第十二章」代码清单 12-52 断言测试用例错误 #131

Closed
micooz opened this issue Feb 8, 2019 · 4 comments
Closed

「第十二章」代码清单 12-52 断言测试用例错误 #131

micooz opened this issue Feb 8, 2019 · 4 comments
Labels
已修订 已经修订并提交给出版社 第十二章 第十二章 精选

Comments

@micooz
Copy link

micooz commented Feb 8, 2019

页码与行数

  • 代码清单 12-52 第 8 行

代码错误

#![feature(proc_macro_hygiene)]

#[test]
fn test_hashmap() {
    let hm = hashmap!{ "a": 1, "b": 2 };
    assert_eq!(hm["a"], 1);
    let hm = hashmap!{ "a" => 1, "b" => 2, "c" => 3 };
    assert_eq!(hm["d"], 4); // 此处断言不通过
}

Rust版本

$ rustc -V
rustc 1.34.0-nightly (d17318011 2019-02-07)

错误信息

thread 'test_hashmap' panicked at 'no entry found for key', src/libcore/option.rs:1038:5
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
@ZhangHanDong
Copy link
Owner

@micooz 感谢反馈,我再确认下。 应该是可以通过的。需要加#![feature(proc_macro_non_items)]。我知道你的编译环境是什么?加那个feature了吗?用Nightly了吗?报的错误是什么呢?

@ZhangHanDong ZhangHanDong added 待确认 待确认的问题 第十二章 第十二章 labels Feb 9, 2019
@ZhangHanDong ZhangHanDong added this to the 第三次印刷 milestone Feb 9, 2019
@micooz
Copy link
Author

micooz commented Feb 9, 2019

@ZhangHanDong

已补充版本和错误信息。proc_macro_* 系列特性已经被合并为 proc_macro_hygiene,因此我测试时用的是后者,但我认为是断言本身就写错了,和这个特性无关。

PR: rust-lang/rust#52121

@ZhangHanDong
Copy link
Owner

@micooz 那个错误的断言应该是故意为之,可能书上没写明确,就是想让大家看一下编译器对这种情况的错误信息。我再完善一下,感谢反馈。

@ZhangHanDong ZhangHanDong added 已修订 已经修订并提交给出版社 精选 and removed 待确认 待确认的问题 labels Feb 11, 2019
@ZhangHanDong
Copy link
Owner

proc_macro_* 系列特性已经被合并为 proc_macro_hygiene

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
已修订 已经修订并提交给出版社 第十二章 第十二章 精选
Projects
None yet
Development

No branches or pull requests

2 participants