2021-06-14 13:15:05 +03:00
|
|
|
use crate::{Diagnostic, DiagnosticsContext};
|
2021-06-13 17:06:36 +03:00
|
|
|
|
|
|
|
// Diagnostic: unresolved-macro-call
|
|
|
|
//
|
|
|
|
// This diagnostic is triggered if rust-analyzer is unable to resolve the path
|
|
|
|
// to a macro in a macro invocation.
|
2021-06-14 19:32:39 +03:00
|
|
|
pub(crate) fn unresolved_macro_call(
|
2021-06-13 17:06:36 +03:00
|
|
|
ctx: &DiagnosticsContext<'_>,
|
|
|
|
d: &hir::UnresolvedMacroCall,
|
|
|
|
) -> Diagnostic {
|
2022-06-24 13:03:13 +02:00
|
|
|
// Use more accurate position if available.
|
2022-11-19 10:32:32 +01:00
|
|
|
let display_range = ctx.resolve_precise_location(&d.macro_call, d.precise_location);
|
2022-04-27 20:03:57 +02:00
|
|
|
let bang = if d.is_bang { "!" } else { "" };
|
2021-06-13 17:06:36 +03:00
|
|
|
Diagnostic::new(
|
|
|
|
"unresolved-macro-call",
|
2022-04-27 20:03:57 +02:00
|
|
|
format!("unresolved macro `{}{}`", d.path, bang),
|
2022-06-24 13:03:13 +02:00
|
|
|
display_range,
|
2021-06-13 17:06:36 +03:00
|
|
|
)
|
|
|
|
.experimental()
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
mod tests {
|
2021-06-14 13:15:05 +03:00
|
|
|
use crate::tests::check_diagnostics;
|
2021-06-13 17:06:36 +03:00
|
|
|
|
2021-06-13 18:45:38 +03:00
|
|
|
#[test]
|
|
|
|
fn unresolved_macro_diag() {
|
|
|
|
check_diagnostics(
|
|
|
|
r#"
|
|
|
|
fn f() {
|
|
|
|
m!();
|
2021-06-14 22:06:28 +03:00
|
|
|
} //^ error: unresolved macro `m!`
|
2021-06-13 18:45:38 +03:00
|
|
|
|
|
|
|
"#,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-06-13 17:06:36 +03:00
|
|
|
#[test]
|
|
|
|
fn test_unresolved_macro_range() {
|
|
|
|
check_diagnostics(
|
|
|
|
r#"
|
|
|
|
foo::bar!(92);
|
2021-06-14 22:06:28 +03:00
|
|
|
//^^^ error: unresolved macro `foo::bar!`
|
2021-06-13 17:06:36 +03:00
|
|
|
"#,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn unresolved_legacy_scope_macro() {
|
|
|
|
check_diagnostics(
|
|
|
|
r#"
|
|
|
|
macro_rules! m { () => {} }
|
|
|
|
|
|
|
|
m!(); m2!();
|
2021-07-26 19:58:14 +02:00
|
|
|
//^^ error: unresolved macro `m2!`
|
2021-06-13 17:06:36 +03:00
|
|
|
"#,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn unresolved_module_scope_macro() {
|
|
|
|
check_diagnostics(
|
|
|
|
r#"
|
|
|
|
mod mac {
|
|
|
|
#[macro_export]
|
|
|
|
macro_rules! m { () => {} } }
|
|
|
|
|
|
|
|
self::m!(); self::m2!();
|
2021-06-14 22:06:28 +03:00
|
|
|
//^^ error: unresolved macro `self::m2!`
|
2021-06-13 17:06:36 +03:00
|
|
|
"#,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|