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 ++------------------------- crates/hir/src/lib.rs | 5 ++++- 2 files changed, 6 insertions(+), 26 deletions(-) (limited to 'crates/hir/src') 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 diff --git a/crates/hir/src/lib.rs b/crates/hir/src/lib.rs index f7883c469..d32246709 100644 --- a/crates/hir/src/lib.rs +++ b/crates/hir/src/lib.rs @@ -498,7 +498,10 @@ impl Module { let import = &item_tree[id.value]; let use_tree = import.use_tree_to_ast(db.upcast(), file_id, *index); - sink.push(UnresolvedImport { file: file_id, node: AstPtr::new(&use_tree) }); + acc.push( + UnresolvedImport { decl: InFile::new(file_id, AstPtr::new(&use_tree)) } + .into(), + ); } DefDiagnosticKind::UnconfiguredCode { ast, cfg, opts } => { -- cgit v1.2.3