#[macro_export]
macro_rules! diagnostic {
($err:expr) => { $crate::Diagnostic::from($err) };
($span:expr, $level:expr, $fmt:expr, $($args:expr),+ ; $($rest:tt)+) => {{
#[allow(unused_imports)]
use $crate::__export::{DoubleSpanToTokens, DoubleSpanSingleSpan, DoubleSpanSingleSpan2};
let (start, end) = (&$span).FIRST_ARG_MUST_EITHER_BE_SPAN_OR_IMPLEMENT_TO_TOKENS();
let diag = $crate::Diagnostic::double_spanned(
start,
end,
$level,
format!($fmt, $($args),*)
);
$crate::__pme__suggestions!(diag $($rest)*);
diag
}};
($span:expr, $level:expr, $msg:expr ; $($rest:tt)+) => {{
#[allow(unused_imports)]
use $crate::__export::{DoubleSpanToTokens, DoubleSpanSingleSpan, DoubleSpanSingleSpan2};
let (start, end) = (&$span).FIRST_ARG_MUST_EITHER_BE_SPAN_OR_IMPLEMENT_TO_TOKENS();
let diag = $crate::Diagnostic::double_spanned(start, end, $level, $msg.to_string());
$crate::__pme__suggestions!(diag $($rest)*);
diag
}};
($span:expr, $level:expr, $fmt:expr, $($args:expr),+) => {{
#[allow(unused_imports)]
use $crate::__export::{DoubleSpanToTokens, DoubleSpanSingleSpan, DoubleSpanSingleSpan2};
let (start, end) = (&$span).FIRST_ARG_MUST_EITHER_BE_SPAN_OR_IMPLEMENT_TO_TOKENS();
$crate::Diagnostic::double_spanned(
start,
end,
$level,
format!($fmt, $($args),*)
)
}};
($span:expr, $level:expr, $msg:expr) => {{
#[allow(unused_imports)]
use $crate::__export::{DoubleSpanToTokens, DoubleSpanSingleSpan, DoubleSpanSingleSpan2};
let (start, end) = (&$span).FIRST_ARG_MUST_EITHER_BE_SPAN_OR_IMPLEMENT_TO_TOKENS();
$crate::Diagnostic::double_spanned(start, end, $level, $msg.to_string())
}};
($span:expr, $level:expr, $fmt:expr, $($args:expr),+, ; $($rest:tt)+) => {
$crate::diagnostic!($span, $level, $fmt, $($args),* ; $($rest)*)
};
($span:expr, $level:expr, $msg:expr, ; $($rest:tt)+) => {
$crate::diagnostic!($span, $level, $msg ; $($rest)*)
};
($span:expr, $level:expr, $fmt:expr, $($args:expr),+,) => {
$crate::diagnostic!($span, $level, $fmt, $($args),*)
};
($span:expr, $level:expr, $msg:expr,) => {
$crate::diagnostic!($span, $level, $msg)
};
}
#[macro_export]
macro_rules! abort {
($err:expr) => {
$crate::diagnostic!($err).abort()
};
($span:expr, $($tts:tt)*) => {
$crate::diagnostic!($span, $crate::Level::Error, $($tts)*).abort()
};
}
#[macro_export]
macro_rules! abort_call_site {
($($tts:tt)*) => {
$crate::diagnostic!(
$crate::proc_macro2::Span::call_site(),
$crate::Level::Error,
$($tts)*
).abort()
};
}
#[macro_export]
macro_rules! emit_error {
($err:expr) => {
$crate::diagnostic!($err).emit()
};
($span:expr, $($tts:tt)*) => {{
let level = $crate::Level::Error;
$crate::diagnostic!($span, level, $($tts)*).emit()
}};
}
#[macro_export]
macro_rules! emit_call_site_error {
($($tts:tt)*) => {
$crate::diagnostic!(
$crate::proc_macro2::Span()::call_site(),
$crate::Level::Error,
$($tts)*
).emit()
};
}
#[macro_export]
macro_rules! emit_warning {
($span:expr, $($tts:tt)*) => {
$crate::diagnostic!($span, $crate::Level::Warning, $($tts)*).emit()
};
}
#[macro_export]
macro_rules! emit_call_site_warning {
($($tts:tt)*) => {{
let span = $crate::proc_macro2::Span()::call_site();
$crate::diagnostic!(span, $crate::Level::Warning, $($tts)*).emit()
}};
}
#[doc(hidden)]
#[macro_export]
macro_rules! __pme__suggestions {
($var:ident) => ();
($var:ident $help:ident =? $msg:expr) => {
let $var = if let Some(msg) = $msg {
$var.suggestion(stringify!($help), msg.to_string())
} else {
$var
};
};
($var:ident $help:ident =? $span:expr => $msg:expr) => {
let $var = if let Some(msg) = $msg {
$var.span_suggestion($span.into(), stringify!($help), msg.to_string())
} else {
$var
};
};
($var:ident $help:ident =? $msg:expr ; $($rest:tt)*) => {
$crate::__pme__suggestions!($var $help =? $msg);
$crate::__pme__suggestions!($var $($rest)*);
};
($var:ident $help:ident =? $span:expr => $msg:expr ; $($rest:tt)*) => {
$crate::__pme__suggestions!($var $help =? $span => $msg);
$crate::__pme__suggestions!($var $($rest)*);
};
($var:ident $help:ident = $msg:expr) => {
let $var = $var.suggestion(stringify!($help), $msg.to_string());
};
($var:ident $help:ident = $fmt:expr, $($args:expr),+) => {
let $var = $var.suggestion(
stringify!($help),
format!($fmt, $($args),*)
);
};
($var:ident $help:ident = $span:expr => $msg:expr) => {
let $var = $var.span_suggestion($span.into(), stringify!($help), $msg.to_string());
};
($var:ident $help:ident = $span:expr => $fmt:expr, $($args:expr),+) => {
let $var = $var.span_suggestion(
$span.into(),
stringify!($help),
format!($fmt, $($args),*)
);
};
($var:ident $help:ident = $msg:expr ; $($rest:tt)*) => {
$crate::__pme__suggestions!($var $help = $msg);
$crate::__pme__suggestions!($var $($rest)*);
};
($var:ident $help:ident = $fmt:expr, $($args:expr),+ ; $($rest:tt)*) => {
$crate::__pme__suggestions!($var $help = $fmt, $($args),*);
$crate::__pme__suggestions!($var $($rest)*);
};
($var:ident $help:ident = $span:expr => $msg:expr ; $($rest:tt)*) => {
$crate::__pme__suggestions!($var $help = $span => $msg);
$crate::__pme__suggestions!($var $($rest)*);
};
($var:ident $help:ident = $span:expr => $fmt:expr, $($args:expr),+ ; $($rest:tt)*) => {
$crate::__pme__suggestions!($var $help = $span => $fmt, $($args),*);
$crate::__pme__suggestions!($var $($rest)*);
};
($var:ident $help:ident = $msg:expr,) => {
$crate::__pme__suggestions!($var $help = $msg)
};
($var:ident $help:ident = $fmt:expr, $($args:expr),+,) => {
$crate::__pme__suggestions!($var $help = $fmt, $($args)*)
};
($var:ident $help:ident = $span:expr => $msg:expr,) => {
$crate::__pme__suggestions!($var $help = $span => $msg)
};
($var:ident $help:ident = $span:expr => $fmt:expr, $($args:expr),*,) => {
$crate::__pme__suggestions!($var $help = $span => $fmt, $($args)*)
};
($var:ident $help:ident = $msg:expr, ; $($rest:tt)*) => {
$crate::__pme__suggestions!($var $help = $msg; $($rest)*)
};
($var:ident $help:ident = $fmt:expr, $($args:expr),+, ; $($rest:tt)*) => {
$crate::__pme__suggestions!($var $help = $fmt, $($args),*; $($rest)*)
};
($var:ident $help:ident = $span:expr => $msg:expr, ; $($rest:tt)*) => {
$crate::__pme__suggestions!($var $help = $span => $msg; $($rest)*)
};
($var:ident $help:ident = $span:expr => $fmt:expr, $($args:expr),+, ; $($rest:tt)*) => {
$crate::__pme__suggestions!($var $help = $span => $fmt, $($args),*; $($rest)*)
};
}