Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/ide-diagnostics/src/handlers/macro_error.rs')
-rw-r--r--crates/ide-diagnostics/src/handlers/macro_error.rs32
1 files changed, 16 insertions, 16 deletions
diff --git a/crates/ide-diagnostics/src/handlers/macro_error.rs b/crates/ide-diagnostics/src/handlers/macro_error.rs
index 53d0131e02..83f2bc2237 100644
--- a/crates/ide-diagnostics/src/handlers/macro_error.rs
+++ b/crates/ide-diagnostics/src/handlers/macro_error.rs
@@ -4,12 +4,12 @@ use crate::{Diagnostic, DiagnosticsContext};
//
// This diagnostic is shown for macro expansion errors.
pub(crate) fn macro_error(ctx: &DiagnosticsContext<'_>, d: &hir::MacroError) -> Diagnostic {
- Diagnostic::new(
- "macro-error",
- d.message.clone(),
- ctx.sema.diagnostics_display_range(d.node.clone()).range,
- )
- .experimental()
+ // Use more accurate position if available.
+ let display_range = d
+ .precise_location
+ .unwrap_or_else(|| ctx.sema.diagnostics_display_range(d.node.clone()).range);
+
+ Diagnostic::new("macro-error", d.message.clone(), display_range).experimental()
}
#[cfg(test)]
@@ -30,10 +30,10 @@ macro_rules! include { () => {} }
macro_rules! compile_error { () => {} }
include!("doesntexist");
-//^^^^^^^^^^^^^^^^^^^^^^^^ error: failed to load file `doesntexist`
+//^^^^^^^ error: failed to load file `doesntexist`
compile_error!("compile_error macro works");
-//^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: compile_error macro works
+//^^^^^^^^^^^^^ error: compile_error macro works
"#,
);
}
@@ -111,7 +111,7 @@ macro_rules! env { () => {} }
macro_rules! concat { () => {} }
include!(concat!(env!("OUT_DIR"), "/out.rs"));
-//^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: `OUT_DIR` not set, enable "build scripts" to fix
+//^^^^^^^ error: `OUT_DIR` not set, enable "build scripts" to fix
"#,
);
}
@@ -153,23 +153,23 @@ fn main() {
// Test a handful of built-in (eager) macros:
include!(invalid);
- //^^^^^^^^^^^^^^^^^ error: could not convert tokens
+ //^^^^^^^ error: could not convert tokens
include!("does not exist");
- //^^^^^^^^^^^^^^^^^^^^^^^^^^ error: failed to load file `does not exist`
+ //^^^^^^^ error: failed to load file `does not exist`
env!(invalid);
- //^^^^^^^^^^^^^ error: could not convert tokens
+ //^^^ error: could not convert tokens
env!("OUT_DIR");
- //^^^^^^^^^^^^^^^ error: `OUT_DIR` not set, enable "build scripts" to fix
+ //^^^ error: `OUT_DIR` not set, enable "build scripts" to fix
compile_error!("compile_error works");
- //^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: compile_error works
+ //^^^^^^^^^^^^^ error: compile_error works
// Lazy:
format_args!();
- //^^^^^^^^^^^^^^ error: no rule matches input tokens
+ //^^^^^^^^^^^ error: no rule matches input tokens
}
"#,
);
@@ -186,7 +186,7 @@ fn f() {
m!();
m!(hi);
- //^^^^^^ error: leftover tokens
+ //^ error: leftover tokens
}
"#,
);