mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-28 04:44:57 +00:00
internal: Report macro definition errors on the definition
This commit is contained in:
parent
0bb9a17312
commit
a5558cdfe5
10 changed files with 115 additions and 14 deletions
|
@ -9,6 +9,16 @@ pub(crate) fn macro_error(ctx: &DiagnosticsContext<'_>, d: &hir::MacroError) ->
|
|||
Diagnostic::new("macro-error", d.message.clone(), display_range).experimental()
|
||||
}
|
||||
|
||||
// Diagnostic: macro-error
|
||||
//
|
||||
// This diagnostic is shown for macro expansion errors.
|
||||
pub(crate) fn macro_def_error(ctx: &DiagnosticsContext<'_>, d: &hir::MacroDefError) -> Diagnostic {
|
||||
// Use more accurate position if available.
|
||||
let display_range =
|
||||
ctx.resolve_precise_location(&d.node.clone().map(|it| it.syntax_node_ptr()), d.name);
|
||||
Diagnostic::new("macro-def-error", d.message.clone(), display_range).experimental()
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::{
|
||||
|
@ -188,6 +198,7 @@ fn f() {
|
|||
"#,
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn dollar_crate_in_builtin_macro() {
|
||||
check_diagnostics(
|
||||
|
@ -209,6 +220,24 @@ macro_rules! outer {
|
|||
fn f() {
|
||||
outer!();
|
||||
} //^^^^^^^^ error: leftover tokens
|
||||
"#,
|
||||
)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn def_diagnostic() {
|
||||
check_diagnostics(
|
||||
r#"
|
||||
macro_rules! foo {
|
||||
//^^^ error: expected subtree
|
||||
f => {};
|
||||
}
|
||||
|
||||
fn f() {
|
||||
foo!();
|
||||
//^^^ error: invalid macro definition: expected subtree
|
||||
|
||||
}
|
||||
"#,
|
||||
)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue