aboutsummaryrefslogtreecommitdiff
path: root/crates/hir/src/diagnostics.rs
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2021-06-13 15:09:41 +0100
committerGitHub <[email protected]>2021-06-13 15:09:41 +0100
commit3d8df2aef87bca7ec3f0994d799462f08d1ad449 (patch)
treea43b94510193f1f58ec7bfc39814ae58f673ceca /crates/hir/src/diagnostics.rs
parente6fa9b016fab4bf38f4e2a798fcabcc13b58e9ab (diff)
parentfa9ed4e0ce633e51d1411951bf044719e6837457 (diff)
Merge #9248
9248: internal: refactor unresolved macro call diagnostic r=matklad a=matklad bors r+ 🤖 Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/hir/src/diagnostics.rs')
-rw-r--r--crates/hir/src/diagnostics.rs60
1 files changed, 10 insertions, 50 deletions
diff --git a/crates/hir/src/diagnostics.rs b/crates/hir/src/diagnostics.rs
index ec0a8fe41..718c86b3a 100644
--- a/crates/hir/src/diagnostics.rs
+++ b/crates/hir/src/diagnostics.rs
@@ -17,7 +17,7 @@ pub use crate::diagnostics_sink::{
17}; 17};
18 18
19macro_rules! diagnostics { 19macro_rules! diagnostics {
20 ($($diag:ident),*) => { 20 ($($diag:ident,)*) => {
21 pub enum AnyDiagnostic {$( 21 pub enum AnyDiagnostic {$(
22 $diag(Box<$diag>), 22 $diag(Box<$diag>),
23 )*} 23 )*}
@@ -32,7 +32,13 @@ macro_rules! diagnostics {
32 }; 32 };
33} 33}
34 34
35diagnostics![UnresolvedModule, UnresolvedExternCrate, MissingFields]; 35diagnostics![
36 UnresolvedModule,
37 UnresolvedExternCrate,
38 UnresolvedImport,
39 UnresolvedMacroCall,
40 MissingFields,
41];
36 42
37#[derive(Debug)] 43#[derive(Debug)]
38pub struct UnresolvedModule { 44pub struct UnresolvedModule {
@@ -47,61 +53,15 @@ pub struct UnresolvedExternCrate {
47 53
48#[derive(Debug)] 54#[derive(Debug)]
49pub struct UnresolvedImport { 55pub struct UnresolvedImport {
50 pub file: HirFileId, 56 pub decl: InFile<AstPtr<ast::UseTree>>,
51 pub node: AstPtr<ast::UseTree>,
52}
53
54impl Diagnostic for UnresolvedImport {
55 fn code(&self) -> DiagnosticCode {
56 DiagnosticCode("unresolved-import")
57 }
58 fn message(&self) -> String {
59 "unresolved import".to_string()
60 }
61 fn display_source(&self) -> InFile<SyntaxNodePtr> {
62 InFile::new(self.file, self.node.clone().into())
63 }
64 fn as_any(&self) -> &(dyn Any + Send + 'static) {
65 self
66 }
67 fn is_experimental(&self) -> bool {
68 // This currently results in false positives in the following cases:
69 // - `cfg_if!`-generated code in libstd (we don't load the sysroot correctly)
70 // - `core::arch` (we don't handle `#[path = "../<path>"]` correctly)
71 // - proc macros and/or proc macro generated code
72 true
73 }
74} 57}
75 58
76// Diagnostic: unresolved-macro-call
77//
78// This diagnostic is triggered if rust-analyzer is unable to resolve the path to a
79// macro in a macro invocation.
80#[derive(Debug, Clone, Eq, PartialEq)] 59#[derive(Debug, Clone, Eq, PartialEq)]
81pub struct UnresolvedMacroCall { 60pub struct UnresolvedMacroCall {
82 pub file: HirFileId, 61 pub macro_call: InFile<AstPtr<ast::MacroCall>>,
83 pub node: AstPtr<ast::MacroCall>,
84 pub path: ModPath, 62 pub path: ModPath,
85} 63}
86 64
87impl Diagnostic for UnresolvedMacroCall {
88 fn code(&self) -> DiagnosticCode {
89 DiagnosticCode("unresolved-macro-call")
90 }
91 fn message(&self) -> String {
92 format!("unresolved macro `{}!`", self.path)
93 }
94 fn display_source(&self) -> InFile<SyntaxNodePtr> {
95 InFile::new(self.file, self.node.clone().into())
96 }
97 fn as_any(&self) -> &(dyn Any + Send + 'static) {
98 self
99 }
100 fn is_experimental(&self) -> bool {
101 true
102 }
103}
104
105// Diagnostic: inactive-code 65// Diagnostic: inactive-code
106// 66//
107// This diagnostic is shown for code with inactive `#[cfg]` attributes. 67// This diagnostic is shown for code with inactive `#[cfg]` attributes.