diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2021-06-13 14:06:27 +0100 |
---|---|---|
committer | GitHub <[email protected]> | 2021-06-13 14:06:27 +0100 |
commit | e6fa9b016fab4bf38f4e2a798fcabcc13b58e9ab (patch) | |
tree | 3e01ba8fb758b685abc4ea0fa162aa48aa81efd5 /crates/hir/src | |
parent | cc6d761a99ab3b7e28ed13ca3839358f3341da4d (diff) | |
parent | 39f190b72ccab9a166529f6ae1c8d5d562b15571 (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.rs | 23 | ||||
-rw-r--r-- | crates/hir/src/lib.rs | 10 |
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 | ||
35 | diagnostics![UnresolvedModule, MissingFields]; | 35 | diagnostics![UnresolvedModule, UnresolvedExternCrate, MissingFields]; |
36 | 36 | ||
37 | #[derive(Debug)] | 37 | #[derive(Debug)] |
38 | pub struct UnresolvedModule { | 38 | pub 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)] |
47 | pub struct UnresolvedExternCrate { | 44 | pub struct UnresolvedExternCrate { |
48 | pub file: HirFileId, | 45 | pub decl: InFile<AstPtr<ast::ExternCrate>>, |
49 | pub item: AstPtr<ast::ExternCrate>, | ||
50 | } | ||
51 | |||
52 | impl 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 } => { |