aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
Diffstat (limited to 'crates')
-rw-r--r--crates/hir_def/src/nameres.rs9
-rw-r--r--crates/hir_def/src/nameres/collector.rs6
-rw-r--r--crates/hir_def/src/nameres/tests/incremental.rs6
3 files changed, 13 insertions, 8 deletions
diff --git a/crates/hir_def/src/nameres.rs b/crates/hir_def/src/nameres.rs
index eb41d324e..202a7dcb6 100644
--- a/crates/hir_def/src/nameres.rs
+++ b/crates/hir_def/src/nameres.rs
@@ -287,7 +287,7 @@ mod diagnostics {
287 use hir_expand::diagnostics::DiagnosticSink; 287 use hir_expand::diagnostics::DiagnosticSink;
288 use hir_expand::hygiene::Hygiene; 288 use hir_expand::hygiene::Hygiene;
289 use hir_expand::InFile; 289 use hir_expand::InFile;
290 use syntax::{ast, AstPtr, SyntaxNodePtr}; 290 use syntax::{ast, AstPtr};
291 291
292 use crate::path::ModPath; 292 use crate::path::ModPath;
293 use crate::{db::DefDatabase, diagnostics::*, nameres::LocalModuleId, AstId}; 293 use crate::{db::DefDatabase, diagnostics::*, nameres::LocalModuleId, AstId};
@@ -300,7 +300,7 @@ mod diagnostics {
300 300
301 UnresolvedImport { ast: AstId<ast::Use>, index: usize }, 301 UnresolvedImport { ast: AstId<ast::Use>, index: usize },
302 302
303 UnconfiguredCode { ast: InFile<SyntaxNodePtr>, cfg: CfgExpr, opts: CfgOptions }, 303 UnconfiguredCode { ast: AstId<ast::Item>, cfg: CfgExpr, opts: CfgOptions },
304 } 304 }
305 305
306 #[derive(Debug, PartialEq, Eq)] 306 #[derive(Debug, PartialEq, Eq)]
@@ -341,7 +341,7 @@ mod diagnostics {
341 341
342 pub(super) fn unconfigured_code( 342 pub(super) fn unconfigured_code(
343 container: LocalModuleId, 343 container: LocalModuleId,
344 ast: InFile<SyntaxNodePtr>, 344 ast: AstId<ast::Item>,
345 cfg: CfgExpr, 345 cfg: CfgExpr,
346 opts: CfgOptions, 346 opts: CfgOptions,
347 ) -> Self { 347 ) -> Self {
@@ -399,9 +399,10 @@ mod diagnostics {
399 } 399 }
400 400
401 DiagnosticKind::UnconfiguredCode { ast, cfg, opts } => { 401 DiagnosticKind::UnconfiguredCode { ast, cfg, opts } => {
402 let item = ast.to_node(db.upcast());
402 sink.push(InactiveCode { 403 sink.push(InactiveCode {
403 file: ast.file_id, 404 file: ast.file_id,
404 node: ast.value.clone(), 405 node: AstPtr::new(&item).into(),
405 cfg: cfg.clone(), 406 cfg: cfg.clone(),
406 opts: opts.clone(), 407 opts: opts.clone(),
407 }); 408 });
diff --git a/crates/hir_def/src/nameres/collector.rs b/crates/hir_def/src/nameres/collector.rs
index 386287518..5ed9073e0 100644
--- a/crates/hir_def/src/nameres/collector.rs
+++ b/crates/hir_def/src/nameres/collector.rs
@@ -1336,13 +1336,11 @@ impl ModCollector<'_, '_> {
1336 1336
1337 fn emit_unconfigured_diagnostic(&mut self, item: ModItem, cfg: &CfgExpr) { 1337 fn emit_unconfigured_diagnostic(&mut self, item: ModItem, cfg: &CfgExpr) {
1338 let ast_id = item.ast_id(self.item_tree); 1338 let ast_id = item.ast_id(self.item_tree);
1339 let id_map = self.def_collector.db.ast_id_map(self.file_id);
1340 let syntax_ptr = id_map.get(ast_id).syntax_node_ptr();
1341 1339
1342 let ast_node = InFile::new(self.file_id, syntax_ptr); 1340 let ast_id = InFile::new(self.file_id, ast_id);
1343 self.def_collector.def_map.diagnostics.push(DefDiagnostic::unconfigured_code( 1341 self.def_collector.def_map.diagnostics.push(DefDiagnostic::unconfigured_code(
1344 self.module_id, 1342 self.module_id,
1345 ast_node, 1343 ast_id,
1346 cfg.clone(), 1344 cfg.clone(),
1347 self.def_collector.cfg_options.clone(), 1345 self.def_collector.cfg_options.clone(),
1348 )); 1346 ));
diff --git a/crates/hir_def/src/nameres/tests/incremental.rs b/crates/hir_def/src/nameres/tests/incremental.rs
index cfbc62cc4..8981fa7c9 100644
--- a/crates/hir_def/src/nameres/tests/incremental.rs
+++ b/crates/hir_def/src/nameres/tests/incremental.rs
@@ -38,6 +38,9 @@ fn typing_inside_a_function_should_not_invalidate_def_map() {
38 fn foo() -> i32 { 38 fn foo() -> i32 {
39 1 + 1 39 1 + 1
40 } 40 }
41
42 #[cfg(never)]
43 fn no() {}
41 //- /foo/mod.rs 44 //- /foo/mod.rs
42 pub mod bar; 45 pub mod bar;
43 46
@@ -53,6 +56,9 @@ fn typing_inside_a_function_should_not_invalidate_def_map() {
53 use E::*; 56 use E::*;
54 57
55 fn foo() -> i32 { 92 } 58 fn foo() -> i32 { 92 }
59
60 #[cfg(never)]
61 fn no() {}
56 ", 62 ",
57 ); 63 );
58} 64}