llo*_*giq 8 compiler-errors rust rust-macros
我想在编译时发出警告,可能来自宏。它不应该被 静音cap_lints。我当前的用例是功能弃用,但还有其他可能的用途。
目前这在稳定的 Rust 中是不可能的。然而,有一个不稳定的特性,程序宏诊断,它通过DiagnosticAPI为程序宏提供了这个功能。
要从过程宏内部发出编译器警告,您可以像这样使用它:
#![feature(proc_macro_diagnostic)]
use proc_macro::Diagnostic;
Diagnostic::new()
.warning("This method is deprecated")
.emit();
Run Code Online (Sandbox Code Playgroud)
要将警告与特定令牌范围相关联,您可以spanned_warning改用。这使得警告输出显示相关的源标记以及消息下划线。