aboutsummaryrefslogtreecommitdiff
path: root/crates/hir/src
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2021-06-13 14:05:43 +0100
committerAleksey Kladov <[email protected]>2021-06-13 14:05:43 +0100
commit39f190b72ccab9a166529f6ae1c8d5d562b15571 (patch)
treeb9035504de80a31b9071da6102a983e7ee260d18 /crates/hir/src
parent6383252cc2770545505d40217732f14e93a396c4 (diff)
internal: refactor unresolved extern crate diagnostic
Diffstat (limited to 'crates/hir/src')
-rw-r--r--crates/hir/src/diagnostics.rs23
-rw-r--r--crates/hir/src/lib.rs10
2 files changed, 8 insertions, 25 deletions
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 {
32 }; 32 };
33} 33}
34 34
35diagnostics![UnresolvedModule, MissingFields]; 35diagnostics![UnresolvedModule, UnresolvedExternCrate, MissingFields];
36 36
37#[derive(Debug)] 37#[derive(Debug)]
38pub struct UnresolvedModule { 38pub struct UnresolvedModule {
@@ -40,28 +40,9 @@ pub struct UnresolvedModule {
40 pub candidate: String, 40 pub candidate: String,
41} 41}
42 42
43// Diagnostic: unresolved-extern-crate
44//
45// This diagnostic is triggered if rust-analyzer is unable to discover referred extern crate.
46#[derive(Debug)] 43#[derive(Debug)]
47pub struct UnresolvedExternCrate { 44pub struct UnresolvedExternCrate {
48 pub file: HirFileId, 45 pub decl: InFile<AstPtr<ast::ExternCrate>>,
49 pub item: AstPtr<ast::ExternCrate>,
50}
51
52impl Diagnostic for UnresolvedExternCrate {
53 fn code(&self) -> DiagnosticCode {
54 DiagnosticCode("unresolved-extern-crate")
55 }
56 fn message(&self) -> String {
57 "unresolved extern crate".to_string()
58 }
59 fn display_source(&self) -> InFile<SyntaxNodePtr> {
60 InFile::new(self.file, self.item.clone().into())
61 }
62 fn as_any(&self) -> &(dyn Any + Send + 'static) {
63 self
64 }
65} 46}
66 47
67#[derive(Debug)] 48#[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 {
484 } 484 }
485 DefDiagnosticKind::UnresolvedExternCrate { ast } => { 485 DefDiagnosticKind::UnresolvedExternCrate { ast } => {
486 let item = ast.to_node(db.upcast()); 486 let item = ast.to_node(db.upcast());
487 sink.push(UnresolvedExternCrate { 487 acc.push(
488 file: ast.file_id, 488 UnresolvedExternCrate {
489 item: AstPtr::new(&item), 489 decl: InFile::new(ast.file_id, AstPtr::new(&item)),
490 }); 490 }
491 .into(),
492 );
491 } 493 }
492 494
493 DefDiagnosticKind::UnresolvedImport { id, index } => { 495 DefDiagnosticKind::UnresolvedImport { id, index } => {