@@ -23,9 +23,9 @@ use crate::late::{
2323use crate :: macros:: { MacroRulesScope , sub_namespace_match} ;
2424use crate :: {
2525 AmbiguityError , AmbiguityKind , AmbiguityWarning , BindingKey , CmResolver , Decl , DeclKind ,
26- Determinacy , Finalize , IdentKey , ImportKind , ImportSummary , LateDecl , LocalModule , Module ,
27- ModuleKind , ModuleOrUniformRoot , ParentScope , PathResult , PrivacyError , Res , ResolutionError ,
28- Resolver , Scope , ScopeSet , Segment , Stage , Symbol , Used , diagnostics,
26+ Determinacy , ExternModule , Finalize , IdentKey , ImportKind , ImportSummary , LateDecl ,
27+ LocalModule , Module , ModuleKind , ModuleOrUniformRoot , ParentScope , PathResult , PrivacyError ,
28+ Res , ResolutionError , Resolver , Scope , ScopeSet , Segment , Stage , Symbol , Used , diagnostics,
2929} ;
3030
3131#[ derive( Copy , Clone ) ]
@@ -608,21 +608,36 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
608608 finalize. map ( |f| Finalize { used : Used :: Scope , ..f } ) ,
609609 )
610610 } ;
611- let decl = self . reborrow ( ) . resolve_ident_in_module_non_globs_unadjusted (
612- module,
613- ident,
614- orig_ident_span,
615- ns,
616- adjusted_parent_scope,
617- if matches ! ( scope_set, ScopeSet :: Module ( ..) ) {
618- Shadowing :: Unrestricted
619- } else {
620- Shadowing :: Restricted
621- } ,
622- adjusted_finalize,
623- ignore_decl,
624- ignore_import,
625- ) ;
611+ let shadowing = if matches ! ( scope_set, ScopeSet :: Module ( ..) ) {
612+ Shadowing :: Unrestricted
613+ } else {
614+ Shadowing :: Restricted
615+ } ;
616+ let decl = if module. is_local ( ) {
617+ self . reborrow ( ) . resolve_ident_in_local_module_non_globs_unadjusted (
618+ module. expect_local ( ) ,
619+ ident,
620+ orig_ident_span,
621+ ns,
622+ adjusted_parent_scope,
623+ shadowing,
624+ adjusted_finalize,
625+ ignore_decl,
626+ ignore_import,
627+ )
628+ } else {
629+ self . reborrow ( ) . resolve_ident_in_extern_module_non_globs_unadjusted (
630+ module. expect_extern ( ) ,
631+ ident,
632+ orig_ident_span,
633+ ns,
634+ adjusted_parent_scope,
635+ shadowing,
636+ adjusted_finalize,
637+ ignore_decl,
638+ )
639+ } ;
640+
626641 match decl {
627642 Ok ( decl) => {
628643 if let Some ( lint_id) = derive_fallback_lint_id {
@@ -1078,10 +1093,49 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
10781093 }
10791094 }
10801095
1081- /// Attempts to resolve `ident` in namespace `ns` of non-glob bindings in `module`.
1082- fn resolve_ident_in_module_non_globs_unadjusted < ' r > (
1096+ /// Attempts to resolve `ident` in namespace `ns` of non-glob bindings in an external `module`.
1097+ fn resolve_ident_in_extern_module_non_globs_unadjusted < ' r > (
10831098 mut self : CmResolver < ' r , ' ra , ' tcx > ,
1084- module : Module < ' ra > ,
1099+ module : ExternModule < ' ra > ,
1100+ ident : IdentKey ,
1101+ orig_ident_span : Span ,
1102+ ns : Namespace ,
1103+ parent_scope : & ParentScope < ' ra > ,
1104+ shadowing : Shadowing ,
1105+ finalize : Option < Finalize > ,
1106+ // This binding should be ignored during in-module resolution, so that we don't get
1107+ // "self-confirming" import resolutions during import validation and checking.
1108+ ignore_decl : Option < Decl < ' ra > > ,
1109+ ) -> Result < Decl < ' ra > , ControlFlow < Determinacy , Determinacy > > {
1110+ let key = BindingKey :: new ( ident, ns) ;
1111+ let resolution =
1112+ & * self . resolution ( module. to_module ( ) , key) . ok_or ( ControlFlow :: Continue ( Determined ) ) ?;
1113+
1114+ let binding = resolution. non_glob_decl . filter ( |b| Some ( * b) != ignore_decl) ;
1115+
1116+ if let Some ( finalize) = finalize {
1117+ return self . get_mut ( ) . finalize_module_binding (
1118+ ident,
1119+ orig_ident_span,
1120+ binding,
1121+ parent_scope,
1122+ finalize,
1123+ shadowing,
1124+ ) ;
1125+ }
1126+
1127+ // Items and single imports are not shadowable, if we have one, then it's determined.
1128+ if let Some ( binding) = binding {
1129+ let accessible = self . is_accessible_from ( binding. vis ( ) , parent_scope. module ) ;
1130+ return if accessible { Ok ( binding) } else { Err ( ControlFlow :: Break ( Determined ) ) } ;
1131+ }
1132+ Err ( ControlFlow :: Continue ( Determined ) )
1133+ }
1134+
1135+ /// Attempts to resolve `ident` in namespace `ns` of non-glob bindings in a local `module`.
1136+ fn resolve_ident_in_local_module_non_globs_unadjusted < ' r > (
1137+ mut self : CmResolver < ' r , ' ra , ' tcx > ,
1138+ module : LocalModule < ' ra > ,
10851139 ident : IdentKey ,
10861140 orig_ident_span : Span ,
10871141 ns : Namespace ,
@@ -1098,7 +1152,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
10981152 // doesn't need to be mutable. It will fail when there is a cycle of imports, and without
10991153 // the exclusive access infinite recursion will crash the compiler with stack overflow.
11001154 let resolution = & * self
1101- . resolution_or_default ( module, key, orig_ident_span)
1155+ . resolution_or_default ( module. to_module ( ) , key, orig_ident_span)
11021156 . try_borrow_mut_unchecked ( )
11031157 . map_err ( |_| ControlFlow :: Continue ( Determined ) ) ?;
11041158
@@ -1121,11 +1175,6 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
11211175 return if accessible { Ok ( binding) } else { Err ( ControlFlow :: Break ( Determined ) ) } ;
11221176 }
11231177
1124- // In extern modules everything is determined from the start.
1125- if !module. is_local ( ) {
1126- return Err ( ControlFlow :: Continue ( Determined ) ) ;
1127- } ;
1128-
11291178 // Check if one of single imports can still define the name, block if it can.
11301179 if self . reborrow ( ) . single_import_can_define_name (
11311180 & resolution,
0 commit comments