diff options
Diffstat (limited to 'crates/hir/src/diagnostics.rs')
-rw-r--r-- | crates/hir/src/diagnostics.rs | 32 |
1 files changed, 3 insertions, 29 deletions
diff --git a/crates/hir/src/diagnostics.rs b/crates/hir/src/diagnostics.rs index 718c86b3a..03e7f5e84 100644 --- a/crates/hir/src/diagnostics.rs +++ b/crates/hir/src/diagnostics.rs | |||
@@ -5,11 +5,10 @@ | |||
5 | //! be expressed in terms of hir types themselves. | 5 | //! be expressed in terms of hir types themselves. |
6 | use std::any::Any; | 6 | use std::any::Any; |
7 | 7 | ||
8 | use cfg::{CfgExpr, CfgOptions, DnfExpr}; | 8 | use cfg::{CfgExpr, CfgOptions}; |
9 | use either::Either; | 9 | use either::Either; |
10 | use hir_def::path::ModPath; | 10 | use hir_def::path::ModPath; |
11 | use hir_expand::{name::Name, HirFileId, InFile}; | 11 | use hir_expand::{name::Name, HirFileId, InFile}; |
12 | use stdx::format_to; | ||
13 | use syntax::{ast, AstPtr, SyntaxNodePtr, TextRange}; | 12 | use syntax::{ast, AstPtr, SyntaxNodePtr, TextRange}; |
14 | 13 | ||
15 | pub use crate::diagnostics_sink::{ | 14 | pub use crate::diagnostics_sink::{ |
@@ -38,6 +37,7 @@ diagnostics![ | |||
38 | UnresolvedImport, | 37 | UnresolvedImport, |
39 | UnresolvedMacroCall, | 38 | UnresolvedMacroCall, |
40 | MissingFields, | 39 | MissingFields, |
40 | InactiveCode, | ||
41 | ]; | 41 | ]; |
42 | 42 | ||
43 | #[derive(Debug)] | 43 | #[derive(Debug)] |
@@ -62,39 +62,13 @@ pub struct UnresolvedMacroCall { | |||
62 | pub path: ModPath, | 62 | pub path: ModPath, |
63 | } | 63 | } |
64 | 64 | ||
65 | // Diagnostic: inactive-code | ||
66 | // | ||
67 | // This diagnostic is shown for code with inactive `#[cfg]` attributes. | ||
68 | #[derive(Debug, Clone, Eq, PartialEq)] | 65 | #[derive(Debug, Clone, Eq, PartialEq)] |
69 | pub struct InactiveCode { | 66 | pub struct InactiveCode { |
70 | pub file: HirFileId, | 67 | pub node: InFile<SyntaxNodePtr>, |
71 | pub node: SyntaxNodePtr, | ||
72 | pub cfg: CfgExpr, | 68 | pub cfg: CfgExpr, |
73 | pub opts: CfgOptions, | 69 | pub opts: CfgOptions, |
74 | } | 70 | } |
75 | 71 | ||
76 | impl Diagnostic for InactiveCode { | ||
77 | fn code(&self) -> DiagnosticCode { | ||
78 | DiagnosticCode("inactive-code") | ||
79 | } | ||
80 | fn message(&self) -> String { | ||
81 | let inactive = DnfExpr::new(self.cfg.clone()).why_inactive(&self.opts); | ||
82 | let mut buf = "code is inactive due to #[cfg] directives".to_string(); | ||
83 | |||
84 | if let Some(inactive) = inactive { | ||
85 | format_to!(buf, ": {}", inactive); | ||
86 | } | ||
87 | |||
88 | buf | ||
89 | } | ||
90 | fn display_source(&self) -> InFile<SyntaxNodePtr> { | ||
91 | InFile::new(self.file, self.node.clone()) | ||
92 | } | ||
93 | fn as_any(&self) -> &(dyn Any + Send + 'static) { | ||
94 | self | ||
95 | } | ||
96 | } | ||
97 | |||
98 | // Diagnostic: unresolved-proc-macro | 72 | // Diagnostic: unresolved-proc-macro |
99 | // | 73 | // |
100 | // This diagnostic is shown when a procedural macro can not be found. This usually means that | 74 | // This diagnostic is shown when a procedural macro can not be found. This usually means that |