aboutsummaryrefslogtreecommitdiff
path: root/crates/hir/src
diff options
context:
space:
mode:
Diffstat (limited to 'crates/hir/src')
-rw-r--r--crates/hir/src/diagnostics.rs35
-rw-r--r--crates/hir/src/lib.rs22
2 files changed, 19 insertions, 38 deletions
diff --git a/crates/hir/src/diagnostics.rs b/crates/hir/src/diagnostics.rs
index 70a4d000d..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, UnresolvedImport, 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 {
@@ -50,35 +56,12 @@ pub struct UnresolvedImport {
50 pub decl: InFile<AstPtr<ast::UseTree>>, 56 pub decl: InFile<AstPtr<ast::UseTree>>,
51} 57}
52 58
53// Diagnostic: unresolved-macro-call
54//
55// This diagnostic is triggered if rust-analyzer is unable to resolve the path to a
56// macro in a macro invocation.
57#[derive(Debug, Clone, Eq, PartialEq)] 59#[derive(Debug, Clone, Eq, PartialEq)]
58pub struct UnresolvedMacroCall { 60pub struct UnresolvedMacroCall {
59 pub file: HirFileId, 61 pub macro_call: InFile<AstPtr<ast::MacroCall>>,
60 pub node: AstPtr<ast::MacroCall>,
61 pub path: ModPath, 62 pub path: ModPath,
62} 63}
63 64
64impl Diagnostic for UnresolvedMacroCall {
65 fn code(&self) -> DiagnosticCode {
66 DiagnosticCode("unresolved-macro-call")
67 }
68 fn message(&self) -> String {
69 format!("unresolved macro `{}!`", self.path)
70 }
71 fn display_source(&self) -> InFile<SyntaxNodePtr> {
72 InFile::new(self.file, self.node.clone().into())
73 }
74 fn as_any(&self) -> &(dyn Any + Send + 'static) {
75 self
76 }
77 fn is_experimental(&self) -> bool {
78 true
79 }
80}
81
82// Diagnostic: inactive-code 65// Diagnostic: inactive-code
83// 66//
84// This diagnostic is shown for code with inactive `#[cfg]` attributes. 67// This diagnostic is shown for code with inactive `#[cfg]` attributes.
diff --git a/crates/hir/src/lib.rs b/crates/hir/src/lib.rs
index d32246709..0a9414013 100644
--- a/crates/hir/src/lib.rs
+++ b/crates/hir/src/lib.rs
@@ -580,11 +580,13 @@ impl Module {
580 580
581 DefDiagnosticKind::UnresolvedMacroCall { ast, path } => { 581 DefDiagnosticKind::UnresolvedMacroCall { ast, path } => {
582 let node = ast.to_node(db.upcast()); 582 let node = ast.to_node(db.upcast());
583 sink.push(UnresolvedMacroCall { 583 acc.push(
584 file: ast.file_id, 584 UnresolvedMacroCall {
585 node: AstPtr::new(&node), 585 macro_call: InFile::new(ast.file_id, AstPtr::new(&node)),
586 path: path.clone(), 586 path: path.clone(),
587 }); 587 }
588 .into(),
589 );
588 } 590 }
589 591
590 DefDiagnosticKind::MacroError { ast, message } => { 592 DefDiagnosticKind::MacroError { ast, message } => {
@@ -1060,13 +1062,9 @@ impl Function {
1060 precise_location: None, 1062 precise_location: None,
1061 macro_name: None, 1063 macro_name: None,
1062 }), 1064 }),
1063 BodyDiagnostic::UnresolvedMacroCall { node, path } => { 1065 BodyDiagnostic::UnresolvedMacroCall { node, path } => acc.push(
1064 sink.push(UnresolvedMacroCall { 1066 UnresolvedMacroCall { macro_call: node.clone(), path: path.clone() }.into(),
1065 file: node.file_id, 1067 ),
1066 node: node.value.clone(),
1067 path: path.clone(),
1068 })
1069 }
1070 } 1068 }
1071 } 1069 }
1072 1070