@@ -53,7 +53,7 @@ enum SideEffectBindings<'ra> {
53
53
import_bindings : PerNS < Option < Option < NameBinding < ' ra > > > > ,
54
54
} ,
55
55
Glob {
56
- import_bindings : Vec < ( NameBinding < ' ra > , BindingKey , bool /* warn_ambiguity */ ) > ,
56
+ import_bindings : Vec < ( NameBinding < ' ra > , BindingKey ) > ,
57
57
} ,
58
58
}
59
59
@@ -607,17 +607,18 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
607
607
!self . assert_speculative,
608
608
"`commit_import_resolutions` should not be called during speculative resolution"
609
609
) ;
610
- self . determined_imports . reserve ( self . determined_imports . len ( ) ) ;
611
610
for ( import, side_effect) in import_resolutions. iter ( ) {
612
- self . determined_imports . push ( * import) ;
613
611
let SideEffect { imported_module, .. } = side_effect;
614
612
import. imported_module . set_unchecked ( Some ( * imported_module) ) ;
615
613
616
- if import. is_glob ( )
617
- && let ModuleOrUniformRoot :: Module ( module) = imported_module
618
- && import. parent_scope . module != * module
619
- {
620
- module. glob_importers . borrow_mut ( self ) . push ( * import) ;
614
+ if import. is_glob ( ) {
615
+ let ModuleOrUniformRoot :: Module ( module) = imported_module else {
616
+ self . dcx ( ) . emit_err ( CannotGlobImportAllCrates { span : import. span } ) ;
617
+ continue ;
618
+ } ;
619
+ if import. parent_scope . module != * module {
620
+ module. glob_importers . borrow_mut_unchecked ( ) . push ( * import) ;
621
+ }
621
622
}
622
623
}
623
624
@@ -668,7 +669,6 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
668
669
}
669
670
( ImportKind :: Glob { id, .. } , SideEffectBindings :: Glob { import_bindings } ) => {
670
671
let ModuleOrUniformRoot :: Module ( module) = imported_module else {
671
- self . dcx ( ) . emit_err ( CannotGlobImportAllCrates { span : import. span } ) ;
672
672
continue ;
673
673
} ;
674
674
@@ -683,12 +683,17 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
683
683
. emit ( ) ;
684
684
}
685
685
686
- for ( binding, key, warn_ambiguity) in import_bindings {
686
+ for ( binding, key) in import_bindings {
687
+ let imported_binding = self . import ( binding, import) ;
688
+ let warn_ambiguity = self
689
+ . resolution ( import. parent_scope . module , key)
690
+ . and_then ( |r| r. binding ( ) )
691
+ . is_some_and ( |binding| binding. warn_ambiguity_recursive ( ) ) ;
687
692
let _ = self . try_define_local (
688
693
parent,
689
694
key. ident . 0 ,
690
695
key. ns ,
691
- binding ,
696
+ imported_binding ,
692
697
warn_ambiguity,
693
698
) ;
694
699
}
@@ -970,7 +975,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
970
975
///
971
976
/// Meanwhile, if resolution is successful, the side effect of the resolution is returned.
972
977
fn resolve_import < ' r > (
973
- self : & mut CmResolver < ' r , ' ra , ' tcx > ,
978
+ mut self : CmResolver < ' r , ' ra , ' tcx > ,
974
979
import : Import < ' ra > ,
975
980
) -> ( Option < SideEffect < ' ra > > , usize ) {
976
981
debug ! (
@@ -1015,12 +1020,15 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
1015
1020
1016
1021
let mut import_bindings = PerNS :: default ( ) ;
1017
1022
let mut indeterminate_count = 0 ;
1018
- self . reborrow ( ) . per_ns_cm ( |this, ns| {
1023
+
1024
+ // HACK: Use array of namespaces in the same order as `per_ns_mut`.
1025
+ // We can't use `per_ns_cm` because of the invariance on CmResolver (RefOrMut).
1026
+ for ns in [ TypeNS , ValueNS , MacroNS ] {
1019
1027
if !type_ns_only || ns == TypeNS {
1020
1028
if bindings[ ns] . get ( ) != PendingBinding :: Pending {
1021
- return ;
1029
+ continue ;
1022
1030
} ;
1023
- let binding_result = this . reborrow ( ) . maybe_resolve_ident_in_module (
1031
+ let binding_result = self . reborrow ( ) . maybe_resolve_ident_in_module (
1024
1032
module,
1025
1033
source,
1026
1034
ns,
@@ -1030,7 +1038,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
1030
1038
let pending_binding = match binding_result {
1031
1039
Ok ( binding) => {
1032
1040
// We need the `target`, `source` can be extracted.
1033
- let imported_binding = this . import ( binding, import) ;
1041
+ let imported_binding = self . import ( binding, import) ;
1034
1042
Some ( Some ( imported_binding) )
1035
1043
}
1036
1044
Err ( Determinacy :: Determined ) => Some ( None ) ,
@@ -1042,8 +1050,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
1042
1050
// FIXME(batched): Will be fixed in batched import resolution.
1043
1051
import_bindings[ ns] = pending_binding;
1044
1052
}
1045
- } ) ;
1046
-
1053
+ }
1047
1054
(
1048
1055
Some ( SideEffect {
1049
1056
imported_module : module,
@@ -1593,47 +1600,40 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
1593
1600
false
1594
1601
}
1595
1602
1596
- fn resolve_glob_import < ' r > (
1597
- self : & mut CmResolver < ' r , ' ra , ' tcx > ,
1603
+ fn resolve_glob_import (
1604
+ & self ,
1598
1605
import : Import < ' ra > ,
1599
1606
imported_module : ModuleOrUniformRoot < ' ra > ,
1600
1607
) -> SideEffectBindings < ' ra > {
1601
- // This function is only called for glob imports.
1602
- let ImportKind :: Glob { .. } = import. kind else { unreachable ! ( ) } ;
1608
+ match imported_module {
1609
+ ModuleOrUniformRoot :: Module ( module) if module != import. parent_scope . module => {
1610
+ let import_bindings = self
1611
+ . resolutions ( module)
1612
+ . borrow ( )
1613
+ . iter ( )
1614
+ . filter_map ( |( key, resolution) | {
1615
+ let binding = resolution. borrow ( ) . binding ( ) ?;
1616
+ let mut key = * key;
1617
+ let scope = match key
1618
+ . ident
1619
+ . 0
1620
+ . span
1621
+ . reverse_glob_adjust ( module. expansion , import. span )
1622
+ {
1623
+ Some ( Some ( def) ) => self . expn_def_scope ( def) ,
1624
+ Some ( None ) => import. parent_scope . module ,
1625
+ None => return None ,
1626
+ } ;
1627
+ self . is_accessible_from ( binding. vis , scope) . then ( || ( binding, key) )
1628
+ } )
1629
+ . collect :: < Vec < _ > > ( ) ;
1603
1630
1604
- let ModuleOrUniformRoot :: Module ( module) = imported_module else {
1605
- return SideEffectBindings :: None ;
1606
- } ;
1631
+ SideEffectBindings :: Glob { import_bindings }
1632
+ }
1607
1633
1608
- if module == import . parent_scope . module {
1609
- return SideEffectBindings :: None ;
1634
+ // Errors are reported in `commit_imports_resolutions`
1635
+ _ => SideEffectBindings :: None ,
1610
1636
}
1611
-
1612
- let import_bindings = self
1613
- . resolutions ( module)
1614
- . borrow ( )
1615
- . iter ( )
1616
- . filter_map ( |( key, resolution) | {
1617
- let binding = resolution. borrow ( ) . binding ( ) ?;
1618
- let mut key = * key;
1619
- let scope =
1620
- match key. ident . 0 . span . reverse_glob_adjust ( module. expansion , import. span ) {
1621
- Some ( Some ( def) ) => self . expn_def_scope ( def) ,
1622
- Some ( None ) => import. parent_scope . module ,
1623
- None => return None ,
1624
- } ;
1625
- self . is_accessible_from ( binding. vis , scope) . then ( || {
1626
- let imported_binding = self . import ( binding, import) ;
1627
- let warn_ambiguity = self
1628
- . resolution ( import. parent_scope . module , key)
1629
- . and_then ( |r| r. binding ( ) )
1630
- . is_some_and ( |binding| binding. warn_ambiguity_recursive ( ) ) ;
1631
- ( imported_binding, key, warn_ambiguity)
1632
- } )
1633
- } )
1634
- . collect :: < Vec < _ > > ( ) ;
1635
-
1636
- SideEffectBindings :: Glob { import_bindings }
1637
1637
}
1638
1638
1639
1639
// Miscellaneous post-processing, including recording re-exports,
0 commit comments