aboutsummaryrefslogtreecommitdiff
path: root/crates/hir/src/diagnostics.rs
diff options
context:
space:
mode:
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.