@@ -500,9 +500,9 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
500500            hir:: OpaqueTyOrigin :: AsyncFn  => return  false , 
501501
502502            // Otherwise, generate the label we'll use in the error message. 
503-             hir:: OpaqueTyOrigin :: TypeAlias  =>  "impl Trait" , 
504-             hir:: OpaqueTyOrigin :: FnReturn  =>  "impl Trait" , 
505-             hir:: OpaqueTyOrigin :: Misc  => "impl Trait" , 
503+             hir:: OpaqueTyOrigin :: TypeAlias 
504+             |  hir:: OpaqueTyOrigin :: FnReturn 
505+             |  hir:: OpaqueTyOrigin :: Misc  => "impl Trait" , 
506506        } ; 
507507        let  msg = format ! ( "ambiguous lifetime bound in `{}`" ,  context_name) ; 
508508        let  mut  err = self . tcx . sess . struct_span_err ( span,  & msg) ; 
@@ -814,26 +814,37 @@ impl TypeFolder<'tcx> for ReverseMapper<'tcx> {
814814
815815    fn  fold_region ( & mut  self ,  r :  ty:: Region < ' tcx > )  -> ty:: Region < ' tcx >  { 
816816        match  r { 
817-             // Ignore bound regions that appear in the type, they don't need to 
818-             // be remapped (e.g., this would ignore `'r` in a type like 
819-             // `for<'r> fn(&'r u32)`. 
820-             ty:: ReLateBound ( ..) 
821- 
822-             // If regions have been erased, don't try to unerase them. 
823-             | ty:: ReErased 
824- 
825-             // ignore `'static`, as that can appear anywhere 
826-             | ty:: ReStatic  => return  r, 
827- 
828-             _ => { } 
817+             // Ignore bound regions and `'static` regions that appear in the 
818+             // type, we only need to remap regions that reference lifetimes 
819+             // from the function declaraion. 
820+             // This would ignore `'r` in a type like `for<'r> fn(&'r u32)`. 
821+             ty:: ReLateBound ( ..)  | ty:: ReStatic  => return  r, 
822+ 
823+             // If regions have been erased (by writeback), don't try to unerase 
824+             // them. 
825+             ty:: ReErased  => return  r, 
826+ 
827+             // The regions that we expect from borrow checking. 
828+             ty:: ReEarlyBound ( _)  | ty:: ReFree ( _)  | ty:: ReEmpty ( ty:: UniverseIndex :: ROOT )  => { } 
829+ 
830+             ty:: ReEmpty ( _) 
831+             | ty:: RePlaceholder ( _) 
832+             | ty:: ReVar ( _) 
833+             | ty:: ReScope ( _) 
834+             | ty:: ReClosureBound ( _)  => { 
835+                 // All of the regions in the type should either have been 
836+                 // erased by writeback, or mapped back to named regions by 
837+                 // borrow checking. 
838+                 bug ! ( "unexpected region kind in opaque type: {:?}" ,  r) ; 
839+             } 
829840        } 
830841
831842        let  generics = self . tcx ( ) . generics_of ( self . opaque_type_def_id ) ; 
832843        match  self . map . get ( & r. into ( ) ) . map ( |k| k. unpack ( ) )  { 
833844            Some ( GenericArgKind :: Lifetime ( r1) )  => r1, 
834845            Some ( u)  => panic ! ( "region mapped to unexpected kind: {:?}" ,  u) , 
835846            None  if  self . map_missing_regions_to_empty  || self . tainted_by_errors  => { 
836-                 self . tcx . lifetimes . re_empty 
847+                 self . tcx . lifetimes . re_root_empty 
837848            } 
838849            None  if  generics. parent . is_some ( )  => { 
839850                if  let  Some ( hidden_ty)  = self . hidden_ty . take ( )  { 
@@ -862,7 +873,7 @@ impl TypeFolder<'tcx> for ReverseMapper<'tcx> {
862873                    ) 
863874                    . emit ( ) ; 
864875
865-                 self . tcx ( ) . mk_region ( ty :: ReStatic ) 
876+                 self . tcx ( ) . lifetimes . re_static 
866877            } 
867878        } 
868879    } 
0 commit comments