Skip to content

Commit 3a96c29

Browse files
Merge #6641
6641: Fix def map volatility with `#[cfg]` diagnostics r=jonas-schievink a=jonas-schievink bors r+ 🤖 Co-authored-by: Jonas Schievink <[email protected]>
2 parents ad34387 + 519d870 commit 3a96c29

File tree

3 files changed

+13
-8
lines changed

3 files changed

+13
-8
lines changed

crates/hir_def/src/nameres.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ mod diagnostics {
287287
use hir_expand::diagnostics::DiagnosticSink;
288288
use hir_expand::hygiene::Hygiene;
289289
use hir_expand::InFile;
290-
use syntax::{ast, AstPtr, SyntaxNodePtr};
290+
use syntax::{ast, AstPtr};
291291

292292
use crate::path::ModPath;
293293
use crate::{db::DefDatabase, diagnostics::*, nameres::LocalModuleId, AstId};
@@ -300,7 +300,7 @@ mod diagnostics {
300300

301301
UnresolvedImport { ast: AstId<ast::Use>, index: usize },
302302

303-
UnconfiguredCode { ast: InFile<SyntaxNodePtr>, cfg: CfgExpr, opts: CfgOptions },
303+
UnconfiguredCode { ast: AstId<ast::Item>, cfg: CfgExpr, opts: CfgOptions },
304304
}
305305

306306
#[derive(Debug, PartialEq, Eq)]
@@ -341,7 +341,7 @@ mod diagnostics {
341341

342342
pub(super) fn unconfigured_code(
343343
container: LocalModuleId,
344-
ast: InFile<SyntaxNodePtr>,
344+
ast: AstId<ast::Item>,
345345
cfg: CfgExpr,
346346
opts: CfgOptions,
347347
) -> Self {
@@ -399,9 +399,10 @@ mod diagnostics {
399399
}
400400

401401
DiagnosticKind::UnconfiguredCode { ast, cfg, opts } => {
402+
let item = ast.to_node(db.upcast());
402403
sink.push(InactiveCode {
403404
file: ast.file_id,
404-
node: ast.value.clone(),
405+
node: AstPtr::new(&item).into(),
405406
cfg: cfg.clone(),
406407
opts: opts.clone(),
407408
});

crates/hir_def/src/nameres/collector.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1336,13 +1336,11 @@ impl ModCollector<'_, '_> {
13361336

13371337
fn emit_unconfigured_diagnostic(&mut self, item: ModItem, cfg: &CfgExpr) {
13381338
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();
13411339

1342-
let ast_node = InFile::new(self.file_id, syntax_ptr);
1340+
let ast_id = InFile::new(self.file_id, ast_id);
13431341
self.def_collector.def_map.diagnostics.push(DefDiagnostic::unconfigured_code(
13441342
self.module_id,
1345-
ast_node,
1343+
ast_id,
13461344
cfg.clone(),
13471345
self.def_collector.cfg_options.clone(),
13481346
));

crates/hir_def/src/nameres/tests/incremental.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ fn typing_inside_a_function_should_not_invalidate_def_map() {
3838
fn foo() -> i32 {
3939
1 + 1
4040
}
41+
42+
#[cfg(never)]
43+
fn no() {}
4144
//- /foo/mod.rs
4245
pub mod bar;
4346
@@ -53,6 +56,9 @@ fn typing_inside_a_function_should_not_invalidate_def_map() {
5356
use E::*;
5457
5558
fn foo() -> i32 { 92 }
59+
60+
#[cfg(never)]
61+
fn no() {}
5662
",
5763
);
5864
}

0 commit comments

Comments
 (0)