@@ -1097,6 +1097,36 @@ impl<'tcx> RegionInferenceContext<'tcx> {
1097
1097
) -> Option < ClosureOutlivesSubject < ' tcx > > {
1098
1098
let tcx = infcx. tcx ;
1099
1099
1100
+ // Opaque types' substs may include useless lifetimes.
1101
+ // We will replace them with ReStatic.
1102
+ struct OpaqueFolder < ' tcx > {
1103
+ tcx : TyCtxt < ' tcx > ,
1104
+ }
1105
+ impl < ' tcx > ty:: TypeFolder < TyCtxt < ' tcx > > for OpaqueFolder < ' tcx > {
1106
+ fn interner ( & self ) -> TyCtxt < ' tcx > {
1107
+ self . tcx
1108
+ }
1109
+ fn fold_ty ( & mut self , t : Ty < ' tcx > ) -> Ty < ' tcx > {
1110
+ use ty:: TypeSuperFoldable as _;
1111
+ let tcx = self . tcx ;
1112
+ let & ty:: Alias ( ty:: Opaque , ty:: AliasTy { substs, def_id, .. } ) = t. kind ( ) else {
1113
+ return t. super_fold_with ( self ) ;
1114
+ } ;
1115
+ let substs =
1116
+ std:: iter:: zip ( substs, tcx. variances_of ( def_id) ) . map ( |( arg, v) | {
1117
+ match ( arg. unpack ( ) , v) {
1118
+ ( ty:: GenericArgKind :: Lifetime ( _) , ty:: Bivariant ) => {
1119
+ tcx. lifetimes . re_static . into ( )
1120
+ }
1121
+ _ => arg. fold_with ( self ) ,
1122
+ }
1123
+ } ) ;
1124
+ tcx. mk_opaque ( def_id, tcx. mk_substs_from_iter ( substs) )
1125
+ }
1126
+ }
1127
+
1128
+ let ty = ty. fold_with ( & mut OpaqueFolder { tcx } ) ;
1129
+
1100
1130
let ty = tcx. fold_regions ( ty, |r, _depth| {
1101
1131
let r_vid = self . to_region_vid ( r) ;
1102
1132
let r_scc = self . constraint_sccs . scc ( r_vid) ;
0 commit comments