Skip to content

Commit c4809d0

Browse files
committed
Fix unconfigured diagnostic being attached to the wrong file for modules
1 parent f1f048c commit c4809d0

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

src/tools/rust-analyzer/crates/hir-def/src/nameres/collector.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2003,7 +2003,7 @@ impl ModCollector<'_, '_> {
20032003
Err(cfg) => {
20042004
self.emit_unconfigured_diagnostic(
20052005
self.tree_id,
2006-
AttrOwner::TopLevel,
2006+
AttrOwner::ModItem(module_id.into()),
20072007
&cfg,
20082008
);
20092009
}

src/tools/rust-analyzer/crates/ide-diagnostics/src/handlers/inactive_code.rs

+25-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,10 @@ mod tests {
4242
use crate::{tests::check_diagnostics_with_config, DiagnosticsConfig};
4343

4444
pub(crate) fn check(ra_fixture: &str) {
45-
let config = DiagnosticsConfig::test_sample();
45+
let config = DiagnosticsConfig {
46+
disabled: std::iter::once("unlinked-file".to_owned()).collect(),
47+
..DiagnosticsConfig::test_sample()
48+
};
4649
check_diagnostics_with_config(config, ra_fixture)
4750
}
4851

@@ -168,6 +171,27 @@ union FooBar {
168171
#[cfg(a)] baz: u32,
169172
//^^^^^^^^^^^^^^^^^^ weak: code is inactive due to #[cfg] directives: a is disabled
170173
}
174+
"#,
175+
);
176+
}
177+
178+
#[test]
179+
fn modules() {
180+
check(
181+
r#"
182+
//- /main.rs
183+
#[cfg(outline)] mod outline;
184+
//^^^^^^^^^^^^^^^^^^^^^^^^^^^^ weak: code is inactive due to #[cfg] directives: outline is disabled
185+
186+
mod outline_inner;
187+
//^^^^^^^^^^^^^^^^^^ weak: code is inactive due to #[cfg] directives: outline_inner is disabled
188+
189+
#[cfg(inline)] mod inline {}
190+
//^^^^^^^^^^^^^^^^^^^^^^^^^^^^ weak: code is inactive due to #[cfg] directives: inline is disabled
191+
192+
//- /outline_inner.rs
193+
#![cfg(outline_inner)]
194+
//- /outline.rs
171195
"#,
172196
);
173197
}

0 commit comments

Comments
 (0)