Expand description
Leverage compiler-provided functionality to emit custom error messages in procedural macros.
§Example
ⓘ
use proc_diag::Error;
Error::new("custom error message")
.label("inline label")
.note("some context")
.note("additional context")
.span(some_span) // or .span((start_span, end_span))
.to_tokens(&mut output);error[E0277]: custom error message
--> src/main.rs:L:11
|
L | demo!("macro input");
| ^^^^^^^^^^^^^ inline label
|
= help: the trait `DiagnosticHack` is not implemented for `*const ()`
= note: some context
= note: additional context
note: required by a bound in `diagnostic_hack`
--> src/main.rs:L:5
|
L | demo!("macro input");
| ^^^^^^^^^^^^^^^^^^^^ required by this bound in `diagnostic_hack`
= note: this error originates in the macro `demo` (in Nightly builds, run with -Z macro-backtrace for more info)§Feature flags
This crate has three feature flags:
quoteenables an implementation ofquote::ToTokens. This also enables theproc-macro2feature.proc-macro2enables passingproc_macro2::Spanand(proc_macro2::Span, proc_macro2::Span)to thespanmethod.msrv-1-78, which lowers the minimum supported Rust version from 1.85 to 1.78. The side effect of enabling this is an additional (irrelevant) line in the diagnostic output.
Structs§
- Error
- A structure representing an error message.