Show proc-macro loading errors in unresolved-proc-macro diagnostics

This commit is contained in:
Lukas Wirth 2022-06-15 17:33:55 +02:00
parent 15c63c4119
commit 7d51fc4640
14 changed files with 149 additions and 114 deletions

View file

@ -29,19 +29,23 @@ pub(crate) fn unresolved_proc_macro(
Some(name) => format!("proc macro `{}` not expanded", name),
None => "proc macro not expanded".to_string(),
};
let (message, severity) = if config_enabled {
(message, Severity::Error)
} else {
let message = match d.kind {
hir::MacroKind::Attr if proc_macros_enabled => {
format!("{message}{}", " (attribute macro expansion is disabled)")
let severity = if config_enabled { Severity::Error } else { Severity::WeakWarning };
let message = format!(
"{message}: {}",
if config_enabled {
match &d.proc_macro_err {
Some(e) => e,
None => "proc macro not found",
}
_ => {
format!("{message}{}", " (proc-macro expansion is disabled)")
} else {
match d.kind {
hir::MacroKind::Attr if proc_macros_enabled => {
"attribute macro expansion is disabled"
}
_ => "proc-macro expansion is disabled",
}
};
(message, Severity::WeakWarning)
};
},
);
Diagnostic::new("unresolved-proc-macro", message, display_range).severity(severity)
}