macro_rules! diagnostic {
($fmt:literal $($arg:tt)*) => { ... };
($($key:ident = $value:expr,)+ $fmt:literal $($arg:tt)*) => { ... };
}
Expand description
Construct a MietteDiagnostic
in more user-friendly way.
ยงExamples
use miette::{diagnostic, LabeledSpan, Severity};
let source = "(2 + 2".to_string();
let diag = diagnostic!(
// Those fields are optional
severity = Severity::Error,
code = "expected::rparen",
help = "always close your parens",
labels = vec![LabeledSpan::at_offset(6, "here")],
url = "https://example.com",
// Rest of the arguments are passed to `format!`
// to form diagnostic message
"expected closing ')'",
);
Diagnostic without any fields:
let x = 1;
let y = 2;
let diag = diagnostic!("{x} + {} = {z}", y, z = x + y);
assert_eq!(diag.message, "1 + 2 = 3");
let z = x + y;
let diag = diagnostic!("{x} + {y} = {z}");
assert_eq!(diag.message, "1 + 2 = 3");