Auto merge of #17823 - Veykril:mod-unconfigured-diag, r=Veykril

fix: Fix unconfigured diagnostic being attached to the wrong file for modules

Fixes https://github.com/rust-lang/rust-analyzer/issues/17817
This commit is contained in:
bors 2024-08-07 13:08:35 +00:00
commit 0e282fcd04
2 changed files with 26 additions and 2 deletions

View file

@ -2003,7 +2003,7 @@ impl ModCollector<'_, '_> {
Err(cfg) => {
self.emit_unconfigured_diagnostic(
self.tree_id,
AttrOwner::TopLevel,
AttrOwner::ModItem(module_id.into()),
&cfg,
);
}

View file

@ -42,7 +42,10 @@ mod tests {
use crate::{tests::check_diagnostics_with_config, DiagnosticsConfig};
pub(crate) fn check(ra_fixture: &str) {
let config = DiagnosticsConfig::test_sample();
let config = DiagnosticsConfig {
disabled: std::iter::once("unlinked-file".to_owned()).collect(),
..DiagnosticsConfig::test_sample()
};
check_diagnostics_with_config(config, ra_fixture)
}
@ -168,6 +171,27 @@ union FooBar {
#[cfg(a)] baz: u32,
//^^^^^^^^^^^^^^^^^^ weak: code is inactive due to #[cfg] directives: a is disabled
}
"#,
);
}
#[test]
fn modules() {
check(
r#"
//- /main.rs
#[cfg(outline)] mod outline;
//^^^^^^^^^^^^^^^^^^^^^^^^^^^^ weak: code is inactive due to #[cfg] directives: outline is disabled
mod outline_inner;
//^^^^^^^^^^^^^^^^^^ weak: code is inactive due to #[cfg] directives: outline_inner is disabled
#[cfg(inline)] mod inline {}
//^^^^^^^^^^^^^^^^^^^^^^^^^^^^ weak: code is inactive due to #[cfg] directives: inline is disabled
//- /outline_inner.rs
#![cfg(outline_inner)]
//- /outline.rs
"#,
);
}