From 6d104de15aee6a24a442871c59528c39d410c161 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sun, 13 Jun 2021 16:42:34 +0300 Subject: internal: refactor unresolved import diagnostic --- crates/hir/src/diagnostics.rs | 27 ++------------------------- 1 file changed, 2 insertions(+), 25 deletions(-) (limited to 'crates/hir/src/diagnostics.rs') diff --git a/crates/hir/src/diagnostics.rs b/crates/hir/src/diagnostics.rs index ec0a8fe41..70a4d000d 100644 --- a/crates/hir/src/diagnostics.rs +++ b/crates/hir/src/diagnostics.rs @@ -32,7 +32,7 @@ macro_rules! diagnostics { }; } -diagnostics![UnresolvedModule, UnresolvedExternCrate, MissingFields]; +diagnostics![UnresolvedModule, UnresolvedExternCrate, UnresolvedImport, MissingFields]; #[derive(Debug)] pub struct UnresolvedModule { @@ -47,30 +47,7 @@ pub struct UnresolvedExternCrate { #[derive(Debug)] pub struct UnresolvedImport { - pub file: HirFileId, - pub node: AstPtr, -} - -impl Diagnostic for UnresolvedImport { - fn code(&self) -> DiagnosticCode { - DiagnosticCode("unresolved-import") - } - fn message(&self) -> String { - "unresolved import".to_string() - } - 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 { - // This currently results in false positives in the following cases: - // - `cfg_if!`-generated code in libstd (we don't load the sysroot correctly) - // - `core::arch` (we don't handle `#[path = "../"]` correctly) - // - proc macros and/or proc macro generated code - true - } + pub decl: InFile>, } // Diagnostic: unresolved-macro-call -- cgit v1.2.3 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 +++++++++-------------------------- 1 file changed, 9 insertions(+), 26 deletions(-) (limited to 'crates/hir/src/diagnostics.rs') 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. -- cgit v1.2.3