diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2020-10-20 17:35:05 +0100 |
---|---|---|
committer | GitHub <[email protected]> | 2020-10-20 17:35:05 +0100 |
commit | 20d369a826e8f333cba1988325480a49a730f00e (patch) | |
tree | 266845de2212273c0967ed6455bdc0c7b485f225 /crates/hir_def/src/nameres.rs | |
parent | 5dd99aa016bd9f7b8bcbc0eb47998723b675bb26 (diff) | |
parent | 74ac83a5acc9f53db69577fc32a4a6e3985d2ef9 (diff) |
Merge #6299
6299: Diagnose items that are #[cfg]d out r=jonas-schievink a=jonas-schievink
This emits a hint-level diagnostic with `Unnecessary` tag to "gray out" any items whose `#[cfg]` attributes remove the item before name resolution.
Co-authored-by: Jonas Schievink <[email protected]>
Diffstat (limited to 'crates/hir_def/src/nameres.rs')
-rw-r--r-- | crates/hir_def/src/nameres.rs | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/crates/hir_def/src/nameres.rs b/crates/hir_def/src/nameres.rs index 3d04f81c6..01a28aeeb 100644 --- a/crates/hir_def/src/nameres.rs +++ b/crates/hir_def/src/nameres.rs | |||
@@ -286,7 +286,7 @@ mod diagnostics { | |||
286 | use hir_expand::diagnostics::DiagnosticSink; | 286 | use hir_expand::diagnostics::DiagnosticSink; |
287 | use hir_expand::hygiene::Hygiene; | 287 | use hir_expand::hygiene::Hygiene; |
288 | use hir_expand::InFile; | 288 | use hir_expand::InFile; |
289 | use syntax::{ast, AstPtr}; | 289 | use syntax::{ast, AstPtr, SyntaxNodePtr}; |
290 | 290 | ||
291 | use crate::path::ModPath; | 291 | use crate::path::ModPath; |
292 | use crate::{db::DefDatabase, diagnostics::*, nameres::LocalModuleId, AstId}; | 292 | use crate::{db::DefDatabase, diagnostics::*, nameres::LocalModuleId, AstId}; |
@@ -298,6 +298,8 @@ mod diagnostics { | |||
298 | UnresolvedExternCrate { ast: AstId<ast::ExternCrate> }, | 298 | UnresolvedExternCrate { ast: AstId<ast::ExternCrate> }, |
299 | 299 | ||
300 | UnresolvedImport { ast: AstId<ast::Use>, index: usize }, | 300 | UnresolvedImport { ast: AstId<ast::Use>, index: usize }, |
301 | |||
302 | UnconfiguredCode { ast: InFile<SyntaxNodePtr> }, | ||
301 | } | 303 | } |
302 | 304 | ||
303 | #[derive(Debug, PartialEq, Eq)] | 305 | #[derive(Debug, PartialEq, Eq)] |
@@ -336,6 +338,13 @@ mod diagnostics { | |||
336 | Self { in_module: container, kind: DiagnosticKind::UnresolvedImport { ast, index } } | 338 | Self { in_module: container, kind: DiagnosticKind::UnresolvedImport { ast, index } } |
337 | } | 339 | } |
338 | 340 | ||
341 | pub(super) fn unconfigured_code( | ||
342 | container: LocalModuleId, | ||
343 | ast: InFile<SyntaxNodePtr>, | ||
344 | ) -> Self { | ||
345 | Self { in_module: container, kind: DiagnosticKind::UnconfiguredCode { ast } } | ||
346 | } | ||
347 | |||
339 | pub(super) fn add_to( | 348 | pub(super) fn add_to( |
340 | &self, | 349 | &self, |
341 | db: &dyn DefDatabase, | 350 | db: &dyn DefDatabase, |
@@ -385,6 +394,10 @@ mod diagnostics { | |||
385 | sink.push(UnresolvedImport { file: ast.file_id, node: AstPtr::new(&tree) }); | 394 | sink.push(UnresolvedImport { file: ast.file_id, node: AstPtr::new(&tree) }); |
386 | } | 395 | } |
387 | } | 396 | } |
397 | |||
398 | DiagnosticKind::UnconfiguredCode { ast } => { | ||
399 | sink.push(InactiveCode { file: ast.file_id, node: ast.value.clone() }); | ||
400 | } | ||
388 | } | 401 | } |
389 | } | 402 | } |
390 | } | 403 | } |