aboutsummaryrefslogtreecommitdiff
path: root/crates/hir_def/src
diff options
context:
space:
mode:
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}