Skip to content

Commit 10da771

Browse files
committed
ignore bivariant regions in opaque types
1 parent 9d74bff commit 10da771

File tree

3 files changed

+32
-20
lines changed

3 files changed

+32
-20
lines changed

compiler/rustc_borrowck/src/region_infer/mod.rs

+30
Original file line numberDiff line numberDiff line change
@@ -1097,6 +1097,36 @@ impl<'tcx> RegionInferenceContext<'tcx> {
10971097
) -> Option<ClosureOutlivesSubject<'tcx>> {
10981098
let tcx = infcx.tcx;
10991099

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+
11001130
let ty = tcx.fold_regions(ty, |r, _depth| {
11011131
let r_vid = self.to_region_vid(r);
11021132
let r_scc = self.constraint_sccs.scc(r_vid);

tests/ui/nll/closure-requirements/type-test-subject-opaque-2.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
// check-fail
2-
// known-bug: #107516
1+
// Resgression test for #107516.
2+
// check-pass
33

44
fn iter1<'a: 'a>() -> impl Iterator<Item = &'static str> {
55
None.into_iter()

tests/ui/nll/closure-requirements/type-test-subject-opaque-2.stderr

-18
This file was deleted.

0 commit comments

Comments
 (0)