proc-diag

Crates.ioproc-diag
lib.rsproc-diag
version0.2.0
created_at2025-08-10 20:15:47.146526+00
updated_at2025-08-11 21:44:40.14239+00
descriptionLeverage compiler-provided functionality to emit custom error messages in procedural macros.
homepage
repositoryhttps://github.com/jhpratt/proc-diag
max_upload_size
id1789262
size23,915
Jacob Pratt (jhpratt)

documentation

README

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:

  • quote enables an implementation of quote::ToTokens. This also enables the proc-macro2 feature.
  • proc-macro2 enables passing proc_macro2::Span and (proc_macro2::Span, proc_macro2::Span) to the span method.
  • 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.
Commit count: 0

cargo fmt