@@ -291,8 +291,6 @@ impl DefCollector<'_> {
291291
292292 let attrs = item_tree. top_level_attrs ( self . db , self . def_map . krate ) ;
293293
294- self . inject_prelude ( & attrs) ;
295-
296294 // Process other crate-level attributes.
297295 for attr in & * attrs {
298296 if let Some ( cfg) = attr. cfg ( ) {
@@ -321,6 +319,16 @@ impl DefCollector<'_> {
321319 continue ;
322320 }
323321
322+ if * attr_name == hir_expand:: name![ no_core] {
323+ self . def_map . no_core = true ;
324+ continue ;
325+ }
326+
327+ if * attr_name == hir_expand:: name![ no_std] {
328+ self . def_map . no_std = true ;
329+ continue ;
330+ }
331+
324332 if attr_name. as_text ( ) . as_deref ( ) == Some ( "rustc_coherence_is_core" ) {
325333 self . def_map . rustc_coherence_is_core = true ;
326334 continue ;
@@ -359,6 +367,8 @@ impl DefCollector<'_> {
359367 }
360368 }
361369
370+ self . inject_prelude ( ) ;
371+
362372 ModCollector {
363373 def_collector : self ,
364374 macro_depth : 0 ,
@@ -517,15 +527,15 @@ impl DefCollector<'_> {
517527 }
518528 }
519529
520- fn inject_prelude ( & mut self , crate_attrs : & Attrs ) {
530+ fn inject_prelude ( & mut self ) {
521531 // See compiler/rustc_builtin_macros/src/standard_library_imports.rs
522532
523- if crate_attrs . by_key ( "no_core" ) . exists ( ) {
533+ if self . def_map . no_core {
524534 // libcore does not get a prelude.
525535 return ;
526536 }
527537
528- let krate = if crate_attrs . by_key ( "no_std" ) . exists ( ) {
538+ let krate = if self . def_map . no_std {
529539 name ! [ core]
530540 } else {
531541 let std = name ! [ std] ;
0 commit comments