← 返回起始笔记位置

知识卡片

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

组合独立的编译诊断

理解等级:中级

独立的签名验证和语句验证可以都执行,再决定是否提交语法树改写。两者成功则保留改写,两者都失败时用 syn::Error::combine 合并诊断,使使用者在同一轮编译看到两个位置。若语句内部还通过 collect::<Result<_, _>>() 首错返回,这一层依旧只保留一个语句错误。

相关卡片 [[用跨度指向宏输入错误]]、[[收集结果决定首错返回]]。

这张卡片看不懂?

已有反馈 · 0 条

    还没有人提交反馈。

    在整书笔记中的位置

    原书出处 · 1 处

    • From panic to result: Error handling 传播或组合诊断 · 查看原书依据

      Instead of handling the statements and signature separately, we now check their combined outputs in a match arm, which will allow us to take action when we have multiple errors. We handle the happy path by mutating the AST. Separate errors are also handled in the same way as before, by returning the one error. The final match is for when we have two errors. If that is the case, we combine them before returning.

    参考来源

    - 位置:《Write Powerful Rust Macros》第07章《From panic to result: Error handling》(book-source:extracted/Write Powerful Rust Macros/_epub-src/OEBPS/Text/chapter-7.xhtml#p160) - 结论依据:清单 7.22 分别求签名与语句处理结果,再在两处都有错误时调用 combine。 - 原始内容:Instead of handling the statements and signature separately, we now check their combined outputs in a match arm, which will allow us to take action when we have multiple errors. We handle the happy path by mutating the AST. Separate errors are also handled in the same way as before, by returning the one error. The final match is for when we have two errors. If that is the case, we combine them before returning.