about summary refs log tree commit diff
diff options
context:
space:
mode:
authorlcnr <rust@lcnr.de>2024-12-03 13:49:12 +0100
committerlcnr <rust@lcnr.de>2024-12-03 14:07:04 +0100
commit8a47b442c431efcaba7e257c509b9b8d2337e37a (patch)
treebde4eba127a9fa7c253d8c8c7a645c4edd62ff10
parent67defd72e6a39a3a339ebe925ffb6f5a35f5a04e (diff)
closure requirements: don't replace bivariant opaque args
It is unnecessary, these get constrained when checking that the
opaque type is well-formed.

It also results in the opaque type no longer being well formed.
If you've got `fn foo<'a>() -> impl Sized + 'a` the opaque is
`type Opaque<'a, 'aDummy> where 'a: 'aDummy, 'aDummy: 'a` where
`'aDummy`  is bivariant. If we call `foo::<'b>()`  inside of a closure
and its return type ends up in a type test, we start out with the WF
`Opaque<'b, 'b>`, and then replace the bivariant `'b` with `'static`.
`Opaque<'b, 'static>`  is no longer well-formed. Given how these type
tests are used, I don't think this caused any practical issues.
-rw-r--r--compiler/rustc_borrowck/src/region_infer/mod.rs30
1 files changed, 0 insertions, 30 deletions
diff --git a/compiler/rustc_borrowck/src/region_infer/mod.rs b/compiler/rustc_borrowck/src/region_infer/mod.rs
index f4f87fa9f65..691709e53ee 100644
--- a/compiler/rustc_borrowck/src/region_infer/mod.rs
+++ b/compiler/rustc_borrowck/src/region_infer/mod.rs
@@ -1068,37 +1068,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
         ty: Ty<'tcx>,
     ) -> Option<ClosureOutlivesSubject<'tcx>> {
         let tcx = infcx.tcx;
-
-        // Opaque types' args may include useless lifetimes.
-        // We will replace them with ReStatic.
-        struct OpaqueFolder<'tcx> {
-            tcx: TyCtxt<'tcx>,
-        }
-        impl<'tcx> ty::TypeFolder<TyCtxt<'tcx>> for OpaqueFolder<'tcx> {
-            fn cx(&self) -> TyCtxt<'tcx> {
-                self.tcx
-            }
-            fn fold_ty(&mut self, t: Ty<'tcx>) -> Ty<'tcx> {
-                use ty::TypeSuperFoldable as _;
-                let tcx = self.tcx;
-                let &ty::Alias(ty::Opaque, ty::AliasTy { args, def_id, .. }) = t.kind() else {
-                    return t.super_fold_with(self);
-                };
-                let args = std::iter::zip(args, tcx.variances_of(def_id)).map(|(arg, v)| {
-                    match (arg.unpack(), v) {
-                        (ty::GenericArgKind::Lifetime(_), ty::Bivariant) => {
-                            tcx.lifetimes.re_static.into()
-                        }
-                        _ => arg.fold_with(self),
-                    }
-                });
-                Ty::new_opaque(tcx, def_id, tcx.mk_args_from_iter(args))
-            }
-        }
-
-        let ty = ty.fold_with(&mut OpaqueFolder { tcx });
         let mut failed = false;
-
         let ty = fold_regions(tcx, ty, |r, _depth| {
             let r_vid = self.to_region_vid(r);
             let r_scc = self.constraint_sccs.scc(r_vid);