Skip to content

Commit 8a47b44

Browse files
committed
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.
1 parent 67defd7 commit 8a47b44

File tree

1 file changed

+0
-30
lines changed
  • compiler/rustc_borrowck/src/region_infer

1 file changed

+0
-30
lines changed

compiler/rustc_borrowck/src/region_infer/mod.rs

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1068,37 +1068,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
10681068
ty: Ty<'tcx>,
10691069
) -> Option<ClosureOutlivesSubject<'tcx>> {
10701070
let tcx = infcx.tcx;
1071-
1072-
// Opaque types' args may include useless lifetimes.
1073-
// We will replace them with ReStatic.
1074-
struct OpaqueFolder<'tcx> {
1075-
tcx: TyCtxt<'tcx>,
1076-
}
1077-
impl<'tcx> ty::TypeFolder<TyCtxt<'tcx>> for OpaqueFolder<'tcx> {
1078-
fn cx(&self) -> TyCtxt<'tcx> {
1079-
self.tcx
1080-
}
1081-
fn fold_ty(&mut self, t: Ty<'tcx>) -> Ty<'tcx> {
1082-
use ty::TypeSuperFoldable as _;
1083-
let tcx = self.tcx;
1084-
let &ty::Alias(ty::Opaque, ty::AliasTy { args, def_id, .. }) = t.kind() else {
1085-
return t.super_fold_with(self);
1086-
};
1087-
let args = std::iter::zip(args, tcx.variances_of(def_id)).map(|(arg, v)| {
1088-
match (arg.unpack(), v) {
1089-
(ty::GenericArgKind::Lifetime(_), ty::Bivariant) => {
1090-
tcx.lifetimes.re_static.into()
1091-
}
1092-
_ => arg.fold_with(self),
1093-
}
1094-
});
1095-
Ty::new_opaque(tcx, def_id, tcx.mk_args_from_iter(args))
1096-
}
1097-
}
1098-
1099-
let ty = ty.fold_with(&mut OpaqueFolder { tcx });
11001071
let mut failed = false;
1101-
11021072
let ty = fold_regions(tcx, ty, |r, _depth| {
11031073
let r_vid = self.to_region_vid(r);
11041074
let r_scc = self.constraint_sccs.scc(r_vid);

0 commit comments

Comments
 (0)