diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2020-10-23 23:05:25 +0100 |
---|---|---|
committer | GitHub <[email protected]> | 2020-10-23 23:05:25 +0100 |
commit | c483212f274e9a5e348451cd4bbd0487e172458b (patch) | |
tree | dcb279acf2cd6262ede408615a4b3f9bed8098fc /crates/hir_def/src/diagnostics.rs | |
parent | ea25ae614b21237c4a536304da875bdc29f0c65a (diff) | |
parent | 5350c15e27bfb85d2e7ae3eae0e624197f2b9a70 (diff) |
Merge #6339
6339: Diagnose #[cfg]s in bodies r=matklad a=jonas-schievink
This PR threads diagnostics through body lowering using the `BodySourceMap`, and emits `InactiveCode` diagnostics for expressions, statements, and match arms that are `#[cfg]`d out.
Co-authored-by: Jonas Schievink <[email protected]>
Diffstat (limited to 'crates/hir_def/src/diagnostics.rs')
-rw-r--r-- | crates/hir_def/src/diagnostics.rs | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/crates/hir_def/src/diagnostics.rs b/crates/hir_def/src/diagnostics.rs index 532496b62..b221b290c 100644 --- a/crates/hir_def/src/diagnostics.rs +++ b/crates/hir_def/src/diagnostics.rs | |||
@@ -4,10 +4,17 @@ use std::any::Any; | |||
4 | use stdx::format_to; | 4 | use stdx::format_to; |
5 | 5 | ||
6 | use cfg::{CfgExpr, CfgOptions, DnfExpr}; | 6 | use cfg::{CfgExpr, CfgOptions, DnfExpr}; |
7 | use hir_expand::diagnostics::{Diagnostic, DiagnosticCode}; | 7 | use hir_expand::diagnostics::{Diagnostic, DiagnosticCode, DiagnosticSink}; |
8 | use hir_expand::{HirFileId, InFile}; | 8 | use hir_expand::{HirFileId, InFile}; |
9 | use syntax::{ast, AstPtr, SyntaxNodePtr}; | 9 | use syntax::{ast, AstPtr, SyntaxNodePtr}; |
10 | 10 | ||
11 | use crate::{db::DefDatabase, DefWithBodyId}; | ||
12 | |||
13 | pub fn validate_body(db: &dyn DefDatabase, owner: DefWithBodyId, sink: &mut DiagnosticSink<'_>) { | ||
14 | let source_map = db.body_with_source_map(owner).1; | ||
15 | source_map.add_diagnostics(db, sink); | ||
16 | } | ||
17 | |||
11 | // Diagnostic: unresolved-module | 18 | // Diagnostic: unresolved-module |
12 | // | 19 | // |
13 | // This diagnostic is triggered if rust-analyzer is unable to discover referred module. | 20 | // This diagnostic is triggered if rust-analyzer is unable to discover referred module. |
@@ -88,10 +95,10 @@ impl Diagnostic for UnresolvedImport { | |||
88 | } | 95 | } |
89 | } | 96 | } |
90 | 97 | ||
91 | // Diagnostic: unconfigured-code | 98 | // Diagnostic: inactive-code |
92 | // | 99 | // |
93 | // This diagnostic is shown for code with inactive `#[cfg]` attributes. | 100 | // This diagnostic is shown for code with inactive `#[cfg]` attributes. |
94 | #[derive(Debug)] | 101 | #[derive(Debug, Clone, Eq, PartialEq)] |
95 | pub struct InactiveCode { | 102 | pub struct InactiveCode { |
96 | pub file: HirFileId, | 103 | pub file: HirFileId, |
97 | pub node: SyntaxNodePtr, | 104 | pub node: SyntaxNodePtr, |