aboutsummaryrefslogtreecommitdiff
path: root/crates/hir/src
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2021-06-13 14:06:27 +0100
committerGitHub <[email protected]>2021-06-13 14:06:27 +0100
commite6fa9b016fab4bf38f4e2a798fcabcc13b58e9ab (patch)
tree3e01ba8fb758b685abc4ea0fa162aa48aa81efd5 /crates/hir/src
parentcc6d761a99ab3b7e28ed13ca3839358f3341da4d (diff)
parent39f190b72ccab9a166529f6ae1c8d5d562b15571 (diff)
Merge #9247
9247: internal: refactor unresolved extern crate diagnostic r=matklad a=matklad bors r+ 🤖 Co-authored-by: Aleksey Kladov <[email protected]>
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 } => {