rust/crates/ide-diagnostics/src/handlers/unresolved_macro_call.rs
Yuri Astrakhan e16c76e3c3 Inline all format arguments where possible
This makes code more readale and concise,
moving all format arguments like `format!("{}", foo)`
into the more compact `format!("{foo}")` form.

The change was automatically created with, so there are far less change
of an accidental typo.

```
cargo clippy --fix -- -A clippy::all -W clippy::uninlined_format_args
```
2022-12-24 14:36:10 -05:00

74 lines
1.5 KiB
Rust

use crate::{Diagnostic, DiagnosticsContext};
// Diagnostic: unresolved-macro-call
//
// This diagnostic is triggered if rust-analyzer is unable to resolve the path
// to a macro in a macro invocation.
pub(crate) fn unresolved_macro_call(
ctx: &DiagnosticsContext<'_>,
d: &hir::UnresolvedMacroCall,
) -> Diagnostic {
// Use more accurate position if available.
let display_range = ctx.resolve_precise_location(&d.macro_call, d.precise_location);
let bang = if d.is_bang { "!" } else { "" };
Diagnostic::new(
"unresolved-macro-call",
format!("unresolved macro `{}{bang}`", d.path),
display_range,
)
.experimental()
}
#[cfg(test)]
mod tests {
use crate::tests::check_diagnostics;
#[test]
fn unresolved_macro_diag() {
check_diagnostics(
r#"
fn f() {
m!();
} //^ error: unresolved macro `m!`
"#,
);
}
#[test]
fn test_unresolved_macro_range() {
check_diagnostics(
r#"
foo::bar!(92);
//^^^ error: unresolved macro `foo::bar!`
"#,
);
}
#[test]
fn unresolved_legacy_scope_macro() {
check_diagnostics(
r#"
macro_rules! m { () => {} }
m!(); m2!();
//^^ error: unresolved macro `m2!`
"#,
);
}
#[test]
fn unresolved_module_scope_macro() {
check_diagnostics(
r#"
mod mac {
#[macro_export]
macro_rules! m { () => {} } }
self::m!(); self::m2!();
//^^ error: unresolved macro `self::m2!`
"#,
);
}
}