From fa9ed4e0ce633e51d1411951bf044719e6837457 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sun, 13 Jun 2021 17:06:36 +0300 Subject: internal: refactor unresolved macro call diagnostic --- crates/hir/src/diagnostics.rs | 35 +++++++++-------------------------- crates/hir/src/lib.rs | 22 ++++++++++------------ 2 files changed, 19 insertions(+), 38 deletions(-) (limited to 'crates/hir') diff --git a/crates/hir/src/diagnostics.rs b/crates/hir/src/diagnostics.rs index 70a4d000d..718c86b3a 100644 --- a/crates/hir/src/diagnostics.rs +++ b/crates/hir/src/diagnostics.rs @@ -17,7 +17,7 @@ pub use crate::diagnostics_sink::{ }; macro_rules! diagnostics { - ($($diag:ident),*) => { + ($($diag:ident,)*) => { pub enum AnyDiagnostic {$( $diag(Box<$diag>), )*} @@ -32,7 +32,13 @@ macro_rules! diagnostics { }; } -diagnostics![UnresolvedModule, UnresolvedExternCrate, UnresolvedImport, MissingFields]; +diagnostics![ + UnresolvedModule, + UnresolvedExternCrate, + UnresolvedImport, + UnresolvedMacroCall, + MissingFields, +]; #[derive(Debug)] pub struct UnresolvedModule { @@ -50,35 +56,12 @@ pub struct UnresolvedImport { pub decl: InFile>, } -// Diagnostic: unresolved-macro-call -// -// This diagnostic is triggered if rust-analyzer is unable to resolve the path to a -// macro in a macro invocation. #[derive(Debug, Clone, Eq, PartialEq)] pub struct UnresolvedMacroCall { - pub file: HirFileId, - pub node: AstPtr, + pub macro_call: InFile>, pub path: ModPath, } -impl Diagnostic for UnresolvedMacroCall { - fn code(&self) -> DiagnosticCode { - DiagnosticCode("unresolved-macro-call") - } - fn message(&self) -> String { - format!("unresolved macro `{}!`", self.path) - } - fn display_source(&self) -> InFile { - InFile::new(self.file, self.node.clone().into()) - } - fn as_any(&self) -> &(dyn Any + Send + 'static) { - self - } - fn is_experimental(&self) -> bool { - true - } -} - // Diagnostic: inactive-code // // This diagnostic is shown for code with inactive `#[cfg]` attributes. diff --git a/crates/hir/src/lib.rs b/crates/hir/src/lib.rs index d32246709..0a9414013 100644 --- a/crates/hir/src/lib.rs +++ b/crates/hir/src/lib.rs @@ -580,11 +580,13 @@ impl Module { DefDiagnosticKind::UnresolvedMacroCall { ast, path } => { let node = ast.to_node(db.upcast()); - sink.push(UnresolvedMacroCall { - file: ast.file_id, - node: AstPtr::new(&node), - path: path.clone(), - }); + acc.push( + UnresolvedMacroCall { + macro_call: InFile::new(ast.file_id, AstPtr::new(&node)), + path: path.clone(), + } + .into(), + ); } DefDiagnosticKind::MacroError { ast, message } => { @@ -1060,13 +1062,9 @@ impl Function { precise_location: None, macro_name: None, }), - BodyDiagnostic::UnresolvedMacroCall { node, path } => { - sink.push(UnresolvedMacroCall { - file: node.file_id, - node: node.value.clone(), - path: path.clone(), - }) - } + BodyDiagnostic::UnresolvedMacroCall { node, path } => acc.push( + UnresolvedMacroCall { macro_call: node.clone(), path: path.clone() }.into(), + ), } } -- cgit v1.2.3