@@ -702,8 +702,8 @@ pub(super) fn collect_return_position_impl_trait_in_trait_tys<'tcx>(
702702
703703 let mut remapped_types = DefIdMap :: default ( ) ;
704704 for ( def_id, ( ty, args) ) in collected_types {
705- match infcx. fully_resolve ( ( ty , args ) ) {
706- Ok ( ( ty , args ) ) => {
705+ match infcx. fully_resolve ( ty ) {
706+ Ok ( ty ) => {
707707 // `ty` contains free regions that we created earlier while liberating the
708708 // trait fn signature. However, projection normalization expects `ty` to
709709 // contains `def_id`'s early-bound regions.
@@ -883,33 +883,27 @@ impl<'tcx> ty::FallibleTypeFolder<TyCtxt<'tcx>> for RemapHiddenTyRegions<'tcx> {
883883 self . tcx
884884 }
885885
886- fn try_fold_ty ( & mut self , t : Ty < ' tcx > ) -> Result < Ty < ' tcx > , Self :: Error > {
887- if let ty:: Alias ( ty:: Opaque , ty:: AliasTy { args, def_id, .. } ) = * t. kind ( ) {
888- let mut mapped_args = Vec :: with_capacity ( args. len ( ) ) ;
889- for ( arg, v) in std:: iter:: zip ( args, self . tcx . variances_of ( def_id) ) {
890- mapped_args. push ( match ( arg. unpack ( ) , v) {
891- // Skip uncaptured opaque args
892- ( ty:: GenericArgKind :: Lifetime ( _) , ty:: Bivariant ) => arg,
893- _ => arg. try_fold_with ( self ) ?,
894- } ) ;
895- }
896- Ok ( Ty :: new_opaque ( self . tcx , def_id, self . tcx . mk_args ( & mapped_args) ) )
897- } else {
898- t. try_super_fold_with ( self )
899- }
900- }
901-
902886 fn try_fold_region (
903887 & mut self ,
904888 region : ty:: Region < ' tcx > ,
905889 ) -> Result < ty:: Region < ' tcx > , Self :: Error > {
906890 match region. kind ( ) {
907- // Remap late-bound regions from the function.
891+ // Never remap bound regions or `'static`
892+ ty:: ReBound ( ..) | ty:: ReStatic | ty:: ReError ( _) => return Ok ( region) ,
893+ // We always remap liberated late-bound regions from the function.
908894 ty:: ReLateParam ( _) => { }
909895 // Remap early-bound regions as long as they don't come from the `impl` itself,
910896 // in which case we don't really need to renumber them.
911- ty:: ReEarlyParam ( ebr) if ebr. index as usize >= self . num_impl_args => { }
912- _ => return Ok ( region) ,
897+ ty:: ReEarlyParam ( ebr) => {
898+ if ebr. index as usize >= self . num_impl_args {
899+ // Remap
900+ } else {
901+ return Ok ( region) ;
902+ }
903+ }
904+ ty:: ReVar ( _) | ty:: RePlaceholder ( _) | ty:: ReErased => unreachable ! (
905+ "should not have leaked vars or placeholders into hidden type of RPITIT"
906+ ) ,
913907 }
914908
915909 let e = if let Some ( id_region) = self . map . get ( & region) {
0 commit comments