在标记内设置程序宏编译错误点

And*_*kin 7 rust

当 Rust 编译器等宏报告错误时,println!会显示格式字符串中出现问题的精确位置,例如:

11 |     println!("I'm going to substitute {foo}... or not");
   |                                       ^^^^^ not found in this scope
Run Code Online (Sandbox Code Playgroud)

format!我如何为我的类似宏做同样的事情?报告过程宏中的错误的两种方法quote_spanned!( +compile_error!或实验性DiagnosticAPI)都依赖于proc_macro::Span并且我看不到一种为令牌内的Span位置构造a的方法,即使通过实验性API也是如此。