aboutsummaryrefslogtreecommitdiff
path: root/crates/hir_def/src/diagnostics.rs
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2020-10-23 11:38:30 +0100
committerGitHub <[email protected]>2020-10-23 11:38:30 +0100
commit81609960fa30ea92e37b23dc7b025d1939626812 (patch)
tree835866b358bd597e1a2c481b93641418c2562c86 /crates/hir_def/src/diagnostics.rs
parent8b3c851dd37f39f79e7e8807378f45fdde7f6411 (diff)
parenta246d4f599dcf2612fa99720fb4ca98101ed93fb (diff)
Merge #6324
6324: Improve #[cfg] diagnostics r=jonas-schievink a=jonas-schievink Unfortunately I ran into https://github.com/rust-analyzer/rust-analyzer/issues/4058 while testing this on https://github.com/nrf-rs/nrf-hal/, so I didn't see much of it in action yet, but it does seem to work. Co-authored-by: Jonas Schievink <[email protected]> Co-authored-by: Jonas Schievink <[email protected]>
Diffstat (limited to 'crates/hir_def/src/diagnostics.rs')
-rw-r--r--crates/hir_def/src/diagnostics.rs17
1 files changed, 13 insertions, 4 deletions
diff --git a/crates/hir_def/src/diagnostics.rs b/crates/hir_def/src/diagnostics.rs
index c9c08b01f..532496b62 100644
--- a/crates/hir_def/src/diagnostics.rs
+++ b/crates/hir_def/src/diagnostics.rs
@@ -1,11 +1,12 @@
1//! Diagnostics produced by `hir_def`. 1//! Diagnostics produced by `hir_def`.
2 2
3use std::any::Any; 3use std::any::Any;
4use stdx::format_to;
4 5
6use cfg::{CfgExpr, CfgOptions, DnfExpr};
5use hir_expand::diagnostics::{Diagnostic, DiagnosticCode}; 7use hir_expand::diagnostics::{Diagnostic, DiagnosticCode};
6use syntax::{ast, AstPtr, SyntaxNodePtr};
7
8use hir_expand::{HirFileId, InFile}; 8use hir_expand::{HirFileId, InFile};
9use syntax::{ast, AstPtr, SyntaxNodePtr};
9 10
10// Diagnostic: unresolved-module 11// Diagnostic: unresolved-module
11// 12//
@@ -94,6 +95,8 @@ impl Diagnostic for UnresolvedImport {
94pub struct InactiveCode { 95pub struct InactiveCode {
95 pub file: HirFileId, 96 pub file: HirFileId,
96 pub node: SyntaxNodePtr, 97 pub node: SyntaxNodePtr,
98 pub cfg: CfgExpr,
99 pub opts: CfgOptions,
97} 100}
98 101
99impl Diagnostic for InactiveCode { 102impl Diagnostic for InactiveCode {
@@ -101,8 +104,14 @@ impl Diagnostic for InactiveCode {
101 DiagnosticCode("inactive-code") 104 DiagnosticCode("inactive-code")
102 } 105 }
103 fn message(&self) -> String { 106 fn message(&self) -> String {
104 // FIXME: say *why* it is configured out 107 let inactive = DnfExpr::new(self.cfg.clone()).why_inactive(&self.opts);
105 "code is inactive due to #[cfg] directives".to_string() 108 let mut buf = "code is inactive due to #[cfg] directives".to_string();
109
110 if let Some(inactive) = inactive {
111 format_to!(buf, ": {}", inactive);
112 }
113
114 buf
106 } 115 }
107 fn display_source(&self) -> InFile<SyntaxNodePtr> { 116 fn display_source(&self) -> InFile<SyntaxNodePtr> {
108 InFile::new(self.file, self.node.clone()) 117 InFile::new(self.file, self.node.clone())