aboutsummaryrefslogtreecommitdiff
path: root/crates/hir_def/src
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2020-10-26 15:05:10 +0000
committerGitHub <[email protected]>2020-10-26 15:05:10 +0000
commitd01e412eb1572676a33ad145f3370a7157dbc9df (patch)
tree90ea98894e9399cea58a4f961c08ad31a80b6119 /crates/hir_def/src
parent42df7cc0c8ce56fb8711ac8b0c11ee71a08c2ca8 (diff)
parentcd3c632cfcbb4225c0325b229517a1bf38d83000 (diff)
Merge #6367
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+ :robot: Co-authored-by: Jonas Schievink <[email protected]>
Diffstat (limited to 'crates/hir_def/src')
-rw-r--r--crates/hir_def/src/nameres/collector.rs7
-rw-r--r--crates/hir_def/src/nameres/tests.rs17
2 files changed, 22 insertions, 2 deletions
diff --git a/crates/hir_def/src/nameres/collector.rs b/crates/hir_def/src/nameres/collector.rs
index f30172d90..1ff45d244 100644
--- a/crates/hir_def/src/nameres/collector.rs
+++ b/crates/hir_def/src/nameres/collector.rs
@@ -218,15 +218,18 @@ impl DefCollector<'_> {
218 let item_tree = self.db.item_tree(file_id.into()); 218 let item_tree = self.db.item_tree(file_id.into());
219 let module_id = self.def_map.root; 219 let module_id = self.def_map.root;
220 self.def_map.modules[module_id].origin = ModuleOrigin::CrateRoot { definition: file_id }; 220 self.def_map.modules[module_id].origin = ModuleOrigin::CrateRoot { definition: file_id };
221 ModCollector { 221 let mut root_collector = ModCollector {
222 def_collector: &mut *self, 222 def_collector: &mut *self,
223 macro_depth: 0, 223 macro_depth: 0,
224 module_id, 224 module_id,
225 file_id: file_id.into(), 225 file_id: file_id.into(),
226 item_tree: &item_tree, 226 item_tree: &item_tree,
227 mod_dir: ModDir::root(), 227 mod_dir: ModDir::root(),
228 };
229 if item_tree.top_level_attrs().cfg().map_or(true, |cfg| root_collector.is_cfg_enabled(&cfg))
230 {
231 root_collector.collect(item_tree.top_level_items());
228 } 232 }
229 .collect(item_tree.top_level_items());
230 233
231 // main name resolution fixed-point loop. 234 // main name resolution fixed-point loop.
232 let mut i = 0; 235 let mut i = 0;
diff --git a/crates/hir_def/src/nameres/tests.rs b/crates/hir_def/src/nameres/tests.rs
index 11d84f808..9c19bf572 100644
--- a/crates/hir_def/src/nameres/tests.rs
+++ b/crates/hir_def/src/nameres/tests.rs
@@ -691,3 +691,20 @@ mod tr {
691 "#]], 691 "#]],
692 ); 692 );
693} 693}
694
695#[test]
696fn cfg_the_entire_crate() {
697 check(
698 r#"
699//- /main.rs
700#![cfg(never)]
701
702pub struct S;
703pub enum E {}
704pub fn f() {}
705 "#,
706 expect![[r#"
707 crate
708 "#]],
709 );
710}