1 use crate::{Diagnostic, DiagnosticsContext, Severity};
3 // Diagnostic: unresolved-proc-macro
5 // This diagnostic is shown when a procedural macro can not be found. This usually means that
6 // procedural macro support is simply disabled (and hence is only a weak hint instead of an error),
7 // but can also indicate project setup problems.
9 // If you are seeing a lot of "proc macro not expanded" warnings, you can add this option to the
10 // `rust-analyzer.diagnostics.disabled` list to prevent them from showing. Alternatively you can
11 // enable support for procedural macros (see `rust-analyzer.procMacro.attributes.enable`).
12 pub(crate) fn unresolved_proc_macro(
13 ctx: &DiagnosticsContext<'_>,
14 d: &hir::UnresolvedProcMacro,
15 proc_macros_enabled: bool,
16 proc_attr_macros_enabled: bool,
18 // Use more accurate position if available.
21 .unwrap_or_else(|| ctx.sema.diagnostics_display_range(d.node.clone()).range);
23 let config_enabled = match d.kind {
24 hir::MacroKind::Attr => proc_macros_enabled && proc_attr_macros_enabled,
25 _ => proc_macros_enabled,
28 let message = match &d.macro_name {
29 Some(name) => format!("proc macro `{}` not expanded", name),
30 None => "proc macro not expanded".to_string(),
32 let (message, severity) = if config_enabled {
33 (message, Severity::Error)
35 let message = match d.kind {
36 hir::MacroKind::Attr if proc_macros_enabled => {
37 format!("{message}{}", " (attribute macro expansion is disabled)")
40 format!("{message}{}", " (proc-macro expansion is disabled)")
43 (message, Severity::WeakWarning)
46 Diagnostic::new("unresolved-proc-macro", message, display_range).severity(severity)