知识卡片

普通读书笔记卡 · 743.d.2.b.5.a.2.a.4.a.5 · 生成模型:GPT-6

诊断提示正确的属性写法

理解等级:中级

语法不接受的输入也可能反映清楚的用户意图。书中跟读的 Tokio 实现要求属性选项写成键值对,也识别传成裸路径的已知选项。比如看到 #[tokio::main(multi_thread)] 时,诊断提供 flavor = "multi_thread" 的写法,并用原有 token 的 span 标出问题位置。

已知的误写形式可以用有针对性的错误帮助修复,其余输入则返回通用的未知属性诊断。接受的语法仍取决于正式的匹配分支。

相关卡片 [[Tokio宏生成运行时包装]]、[[编辑距离提示相近拼写]]。

这张卡片看不懂?

已有反馈 · 0 条

    还没有人提交反馈。

    在整书笔记中的位置

    原书出处 · 1 处

    • Macros and the outside world 真实 crate 如何分发和展开宏 · 查看原书依据

      The given path attribute is checked against known names. That way, the error can give a hint on how you should set that particular argument. For example, adding #[tokio::main(multi_thread)] to a function results in error: Set the runtime flavor with #[tokio::main(flavor = "multi_thread")]. For unknown path arguments, as well as miscellaneous unrecognized arguments, a generic “unknown attribute” error is thrown, pointing to the correct token.

    参考来源

    - 位置:《Write Powerful Rust Macros》第10章《Macros and the outside world》(book-source:extracted/Write Powerful Rust Macros/_epub-src/OEBPS/Text/chapter-10.xhtml#p125) - 结论依据:原文解释了为什么只接受键值对的实现仍匹配路径形式,并用 multi_thread 拼法展示可直接执行的修正建议。 - 原始内容:The given path attribute is checked against known names. That way, the error can give a hint on how you should set that particular argument. For example, adding #[tokio::main(multi_thread)] to a function results in error: Set the runtime flavor with #[tokio::main(flavor = "multi_thread")]. For unknown path arguments, as well as miscellaneous unrecognized arguments, a generic “unknown attribute” error is thrown, pointing to the correct token.