@@ -19,7 +19,7 @@ use crate::{
1919    AmbiguityError ,  AmbiguityErrorMisc ,  AmbiguityKind ,  BindingKey ,  CmResolver ,  Determinacy , 
2020    Finalize ,  ImportKind ,  LexicalScopeBinding ,  Module ,  ModuleKind ,  ModuleOrUniformRoot , 
2121    NameBinding ,  NameBindingKind ,  ParentScope ,  PathResult ,  PrivacyError ,  Res ,  ResolutionError , 
22-     Resolver ,  Scope ,  ScopeSet ,  Segment ,  Used ,  Weak ,  errors, 
22+     Resolver ,  Scope ,  ScopeSet ,  Segment ,  Stage ,   Used ,  Weak ,  errors, 
2323} ; 
2424
2525#[ derive( Copy ,  Clone ) ]  
@@ -100,9 +100,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
100100
101101        let  rust_2015 = ctxt. edition ( ) . is_rust_2015 ( ) ; 
102102        let  ( ns,  macro_kind)  = match  scope_set { 
103-             ScopeSet :: All ( ns) 
104-             | ScopeSet :: ModuleAndExternPrelude ( ns,  _) 
105-             | ScopeSet :: Late ( ns,  ..)  => ( ns,  None ) , 
103+             ScopeSet :: All ( ns)  | ScopeSet :: ModuleAndExternPrelude ( ns,  _)  => ( ns,  None ) , 
106104            ScopeSet :: ExternPrelude  => ( TypeNS ,  None ) , 
107105            ScopeSet :: Macro ( macro_kind)  => ( MacroNS ,  Some ( macro_kind) ) , 
108106        } ; 
@@ -347,11 +345,12 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
347345            }  else  if  let  RibKind :: Module ( module)  = rib. kind  { 
348346                // Encountered a module item, abandon ribs and look into that module and preludes. 
349347                let  parent_scope = & ParentScope  {  module,  ..* parent_scope } ; 
348+                 let  finalize = finalize. map ( |f| Finalize  {  stage :  Stage :: Late ,  ..f } ) ; 
350349                return  self 
351350                    . cm ( ) 
352351                    . resolve_ident_in_scope_set ( 
353352                        orig_ident, 
354-                         ScopeSet :: Late ( ns) , 
353+                         ScopeSet :: All ( ns) , 
355354                        parent_scope, 
356355                        finalize, 
357356                        finalize. is_some ( ) , 
@@ -405,9 +404,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
405404        } 
406405
407406        let  ( ns,  macro_kind)  = match  scope_set { 
408-             ScopeSet :: All ( ns) 
409-             | ScopeSet :: ModuleAndExternPrelude ( ns,  _) 
410-             | ScopeSet :: Late ( ns,  ..)  => ( ns,  None ) , 
407+             ScopeSet :: All ( ns)  | ScopeSet :: ModuleAndExternPrelude ( ns,  _)  => ( ns,  None ) , 
411408            ScopeSet :: ExternPrelude  => ( TypeNS ,  None ) , 
412409            ScopeSet :: Macro ( macro_kind)  => ( MacroNS ,  Some ( macro_kind) ) , 
413410        } ; 
@@ -431,8 +428,8 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
431428        } 
432429
433430        // Go through all the scopes and try to resolve the name. 
434-         let  derive_fallback_lint_id = match  ( finalize,  scope_set )  { 
435-             ( Some ( finalize ) ,   ScopeSet :: Late ( .. ) )  => Some ( finalize . node_id ) , 
431+         let  derive_fallback_lint_id = match  finalize { 
432+             Some ( Finalize   {  node_id ,   stage :   Stage :: Late ,  ..  } )  => Some ( node_id) , 
436433            _ => None , 
437434        } ; 
438435        let  break_result = self . visit_scopes ( 
@@ -509,11 +506,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
509506                            ident, 
510507                            ns, 
511508                            adjusted_parent_scope, 
512-                             if  matches ! ( scope_set,  ScopeSet :: Late ( ..) )  { 
513-                                 Shadowing :: Unrestricted 
514-                             }  else  { 
515-                                 Shadowing :: Restricted 
516-                             } , 
509+                             Shadowing :: Restricted , 
517510                            adjusted_finalize, 
518511                            ignore_binding, 
519512                            ignore_import, 
@@ -642,7 +635,11 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
642635                            return  None ; 
643636                        } 
644637
645-                         if  finalize. is_none ( )  || matches ! ( scope_set,  ScopeSet :: Late ( ..) )  { 
638+                         // Below we report various ambiguity errors. 
639+                         // We do not need to report them if we are either in speculative resolution, 
640+                         // or in late resolution when everything is already imported and expanded 
641+                         // and no ambiguities exist. 
642+                         if  matches ! ( finalize,  None  | Some ( Finalize  {  stage:  Stage :: Late ,  .. } ) )  { 
646643                            return  Some ( Ok ( binding) ) ; 
647644                        } 
648645
@@ -1039,6 +1036,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
10391036        // Forbid expanded shadowing to avoid time travel. 
10401037        if  let  Some ( shadowed_glob)  = shadowed_glob
10411038            && shadowing == Shadowing :: Restricted 
1039+             && finalize. stage  == Stage :: Early 
10421040            && binding. expansion  != LocalExpnId :: ROOT 
10431041            && binding. res ( )  != shadowed_glob. res ( ) 
10441042        { 
0 commit comments