File tree Expand file tree Collapse file tree 2 files changed +22
-2
lines changed
crates/hir_def/src/nameres Expand file tree Collapse file tree 2 files changed +22
-2
lines changed Original file line number Diff line number Diff line change @@ -218,15 +218,18 @@ impl DefCollector<'_> {
218218 let item_tree = self . db . item_tree ( file_id. into ( ) ) ;
219219 let module_id = self . def_map . root ;
220220 self . def_map . modules [ module_id] . origin = ModuleOrigin :: CrateRoot { definition : file_id } ;
221- ModCollector {
221+ let mut root_collector = ModCollector {
222222 def_collector : & mut * self ,
223223 macro_depth : 0 ,
224224 module_id,
225225 file_id : file_id. into ( ) ,
226226 item_tree : & item_tree,
227227 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 ( ) ) ;
228232 }
229- . collect ( item_tree. top_level_items ( ) ) ;
230233
231234 // main name resolution fixed-point loop.
232235 let mut i = 0 ;
Original file line number Diff line number Diff line change @@ -691,3 +691,20 @@ mod tr {
691691 "# ] ] ,
692692 ) ;
693693}
694+
695+ #[ test]
696+ fn cfg_the_entire_crate ( ) {
697+ check (
698+ r#"
699+ //- /main.rs
700+ #![cfg(never)]
701+
702+ pub struct S;
703+ pub enum E {}
704+ pub fn f() {}
705+ "# ,
706+ expect ! [ [ r#"
707+ crate
708+ "# ] ] ,
709+ ) ;
710+ }
You can’t perform that action at this time.
0 commit comments