6367: Handle #![cfg] in crate root r=jonas-schievink a=jonas-schievink

Now we correctly skip analysis of winapi on non-Windows platforms.

bors r+ 🤖

Co-authored-by: Jonas Schievink <jonas.schievink@ferrous-systems.com>
This commit is contained in:
bors[bot] 2020-10-26 15:05:10 +00:00 committed by GitHub
commit d01e412eb1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 2 deletions

View File

@ -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;

View File

@ -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
"#]],
);
}