From 39f190b72ccab9a166529f6ae1c8d5d562b15571 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sun, 13 Jun 2021 16:05:43 +0300 Subject: internal: refactor unresolved extern crate diagnostic --- crates/hir/src/diagnostics.rs | 23 ++--------------------- crates/hir/src/lib.rs | 10 ++++++---- 2 files changed, 8 insertions(+), 25 deletions(-) (limited to 'crates/hir') diff --git a/crates/hir/src/diagnostics.rs b/crates/hir/src/diagnostics.rs index 158626dc0..ec0a8fe41 100644 --- a/crates/hir/src/diagnostics.rs +++ b/crates/hir/src/diagnostics.rs @@ -32,7 +32,7 @@ macro_rules! diagnostics { }; } -diagnostics![UnresolvedModule, MissingFields]; +diagnostics![UnresolvedModule, UnresolvedExternCrate, MissingFields]; #[derive(Debug)] pub struct UnresolvedModule { @@ -40,28 +40,9 @@ pub struct UnresolvedModule { pub candidate: String, } -// Diagnostic: unresolved-extern-crate -// -// This diagnostic is triggered if rust-analyzer is unable to discover referred extern crate. #[derive(Debug)] pub struct UnresolvedExternCrate { - pub file: HirFileId, - pub item: AstPtr, -} - -impl Diagnostic for UnresolvedExternCrate { - fn code(&self) -> DiagnosticCode { - DiagnosticCode("unresolved-extern-crate") - } - fn message(&self) -> String { - "unresolved extern crate".to_string() - } - fn display_source(&self) -> InFile { - InFile::new(self.file, self.item.clone().into()) - } - fn as_any(&self) -> &(dyn Any + Send + 'static) { - self - } + pub decl: InFile>, } #[derive(Debug)] diff --git a/crates/hir/src/lib.rs b/crates/hir/src/lib.rs index 373134f62..f7883c469 100644 --- a/crates/hir/src/lib.rs +++ b/crates/hir/src/lib.rs @@ -484,10 +484,12 @@ impl Module { } DefDiagnosticKind::UnresolvedExternCrate { ast } => { let item = ast.to_node(db.upcast()); - sink.push(UnresolvedExternCrate { - file: ast.file_id, - item: AstPtr::new(&item), - }); + acc.push( + UnresolvedExternCrate { + decl: InFile::new(ast.file_id, AstPtr::new(&item)), + } + .into(), + ); } DefDiagnosticKind::UnresolvedImport { id, index } => { -- cgit v1.2.3