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 23:05:25 +0100
committerGitHub <[email protected]>2020-10-23 23:05:25 +0100
commitc483212f274e9a5e348451cd4bbd0487e172458b (patch)
treedcb279acf2cd6262ede408615a4b3f9bed8098fc /crates/hir_def/src/diagnostics.rs
parentea25ae614b21237c4a536304da875bdc29f0c65a (diff)
parent5350c15e27bfb85d2e7ae3eae0e624197f2b9a70 (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.rs13
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;
4use stdx::format_to; 4use stdx::format_to;
5 5
6use cfg::{CfgExpr, CfgOptions, DnfExpr}; 6use cfg::{CfgExpr, CfgOptions, DnfExpr};
7use hir_expand::diagnostics::{Diagnostic, DiagnosticCode}; 7use hir_expand::diagnostics::{Diagnostic, DiagnosticCode, DiagnosticSink};
8use hir_expand::{HirFileId, InFile}; 8use hir_expand::{HirFileId, InFile};
9use syntax::{ast, AstPtr, SyntaxNodePtr}; 9use syntax::{ast, AstPtr, SyntaxNodePtr};
10 10
11use crate::{db::DefDatabase, DefWithBodyId};
12
13pub 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)]
95pub struct InactiveCode { 102pub struct InactiveCode {
96 pub file: HirFileId, 103 pub file: HirFileId,
97 pub node: SyntaxNodePtr, 104 pub node: SyntaxNodePtr,