mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-22 14:55:26 +00:00
ignore bivariant regions in opaque types
This commit is contained in:
parent
9d74bff829
commit
10da7710cd
@ -1097,6 +1097,36 @@ impl<'tcx> RegionInferenceContext<'tcx> {
|
||||
) -> Option<ClosureOutlivesSubject<'tcx>> {
|
||||
let tcx = infcx.tcx;
|
||||
|
||||
// Opaque types' substs 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 interner(&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 { substs, def_id, .. }) = t.kind() else {
|
||||
return t.super_fold_with(self);
|
||||
};
|
||||
let substs =
|
||||
std::iter::zip(substs, 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),
|
||||
}
|
||||
});
|
||||
tcx.mk_opaque(def_id, tcx.mk_substs_from_iter(substs))
|
||||
}
|
||||
}
|
||||
|
||||
let ty = ty.fold_with(&mut OpaqueFolder { tcx });
|
||||
|
||||
let ty = tcx.fold_regions(ty, |r, _depth| {
|
||||
let r_vid = self.to_region_vid(r);
|
||||
let r_scc = self.constraint_sccs.scc(r_vid);
|
||||
|
@ -1,5 +1,5 @@
|
||||
// check-fail
|
||||
// known-bug: #107516
|
||||
// Resgression test for #107516.
|
||||
// check-pass
|
||||
|
||||
fn iter1<'a: 'a>() -> impl Iterator<Item = &'static str> {
|
||||
None.into_iter()
|
||||
|
@ -1,18 +0,0 @@
|
||||
error[E0310]: the opaque type `iter1<'_>::{opaque#0}` may not live long enough
|
||||
--> $DIR/type-test-subject-opaque-2.rs:15:16
|
||||
|
|
||||
LL | let _ = || Bivar(iter1());
|
||||
| ^^^^^^^^^^^^^^
|
||||
|
|
||||
= help: consider adding an explicit lifetime bound `iter1<'_>::{opaque#0}: 'static`...
|
||||
= note: ...so that the type `impl Iterator<Item = &'static str>` will meet its required lifetime bounds
|
||||
|
||||
error: `iter2<'_>::{opaque#0}<'_>` does not live long enough
|
||||
--> $DIR/type-test-subject-opaque-2.rs:16:16
|
||||
|
|
||||
LL | let _ = || Bivar(iter2());
|
||||
| ^^^^^^^^^^^^^^
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0310`.
|
Loading…
Reference in New Issue
Block a user