File tree Expand file tree Collapse file tree 3 files changed +9
-3
lines changed Expand file tree Collapse file tree 3 files changed +9
-3
lines changed Original file line number Diff line number Diff line change @@ -67,7 +67,7 @@ use itertools::Itertools;
67
67
use la_arena:: Arena ;
68
68
use rustc_hash:: { FxHashMap , FxHashSet } ;
69
69
use span:: { Edition , FileAstId , ROOT_ERASED_FILE_AST_ID } ;
70
- use stdx:: format_to;
70
+ use stdx:: { format_to, IsNoneOr } ;
71
71
use syntax:: { ast, SmolStr } ;
72
72
use triomphe:: Arc ;
73
73
use tt:: TextRange ;
@@ -478,6 +478,10 @@ impl DefMap {
478
478
CrateRootModuleId { krate : self . krate }
479
479
}
480
480
481
+ pub fn is_root_block_in_module ( & self ) -> bool {
482
+ self . block . is_none_or ( |block| !block. parent . is_block_module ( ) )
483
+ }
484
+
481
485
/// This is the same as [`Self::crate_root`] for crate def maps, but for block def maps, it
482
486
/// returns the root block module.
483
487
pub fn root_module_id ( & self ) -> ModuleId {
Original file line number Diff line number Diff line change @@ -395,6 +395,8 @@ impl DefCollector<'_> {
395
395
. cfg ( )
396
396
. map_or ( true , |cfg| self . cfg_options . check ( & cfg) != Some ( false ) ) ;
397
397
if is_cfg_enabled {
398
+ self . inject_prelude ( ) ;
399
+
398
400
ModCollector {
399
401
def_collector : self ,
400
402
macro_depth : 0 ,
Original file line number Diff line number Diff line change @@ -470,7 +470,7 @@ impl DefMap {
470
470
} ;
471
471
472
472
let extern_prelude = || {
473
- if self . block . is_some ( ) {
473
+ if self . block . is_some ( ) && ! self . is_root_block_in_module ( ) {
474
474
// Don't resolve extern prelude in block `DefMap`s, defer it to the crate def map so
475
475
// that blocks can properly shadow them
476
476
return PerNs :: none ( ) ;
@@ -515,7 +515,7 @@ impl DefMap {
515
515
None => self [ Self :: ROOT ] . scope . get ( name) ,
516
516
} ;
517
517
let from_extern_prelude = || {
518
- if self . block . is_some ( ) {
518
+ if self . block . is_some ( ) && ! self . is_root_block_in_module ( ) {
519
519
// Don't resolve extern prelude in block `DefMap`s.
520
520
return PerNs :: none ( ) ;
521
521
}
You can’t perform that action at this time.
0 commit comments