mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-13 21:54:42 +00:00
Handle #![cfg] in crate root
This commit is contained in:
parent
a0f1346864
commit
cd3c632cfc
2 changed files with 22 additions and 2 deletions
|
@ -218,15 +218,18 @@ impl DefCollector<'_> {
|
|||
let item_tree = self.db.item_tree(file_id.into());
|
||||
let module_id = self.def_map.root;
|
||||
self.def_map.modules[module_id].origin = ModuleOrigin::CrateRoot { definition: file_id };
|
||||
ModCollector {
|
||||
let mut root_collector = ModCollector {
|
||||
def_collector: &mut *self,
|
||||
macro_depth: 0,
|
||||
module_id,
|
||||
file_id: file_id.into(),
|
||||
item_tree: &item_tree,
|
||||
mod_dir: ModDir::root(),
|
||||
};
|
||||
if item_tree.top_level_attrs().cfg().map_or(true, |cfg| root_collector.is_cfg_enabled(&cfg))
|
||||
{
|
||||
root_collector.collect(item_tree.top_level_items());
|
||||
}
|
||||
.collect(item_tree.top_level_items());
|
||||
|
||||
// main name resolution fixed-point loop.
|
||||
let mut i = 0;
|
||||
|
|
|
@ -691,3 +691,20 @@ mod tr {
|
|||
"#]],
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn cfg_the_entire_crate() {
|
||||
check(
|
||||
r#"
|
||||
//- /main.rs
|
||||
#![cfg(never)]
|
||||
|
||||
pub struct S;
|
||||
pub enum E {}
|
||||
pub fn f() {}
|
||||
"#,
|
||||
expect![[r#"
|
||||
crate
|
||||
"#]],
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue