Handle ReErased in responses in new solver

This commit is contained in:
Michael Goulet 2023-10-04 21:58:38 +00:00
parent 1322f92634
commit fd92bc6021
2 changed files with 25 additions and 2 deletions

View File

@ -224,12 +224,20 @@ impl<'tcx> TypeFolder<TyCtxt<'tcx>> for Canonicalizer<'_, 'tcx> {
let kind = match *r { let kind = match *r {
ty::ReLateBound(..) => return r, ty::ReLateBound(..) => return r,
ty::ReStatic => match self.canonicalize_mode { // We may encounter `ReStatic` in item signatures or the hidden type
// of an opaque. `ReErased` should only be encountered in the hidden
// type of an opaque for regions that are ignored for the purposes of
// captures.
//
// FIXME: We should investigate the perf implications of not uniquifying
// `ReErased`. We may be able to short-circuit registering region
// obligations if we encounter a `ReErased` on one side, for example.
ty::ReStatic | ty::ReErased => match self.canonicalize_mode {
CanonicalizeMode::Input => CanonicalVarKind::Region(ty::UniverseIndex::ROOT), CanonicalizeMode::Input => CanonicalVarKind::Region(ty::UniverseIndex::ROOT),
CanonicalizeMode::Response { .. } => return r, CanonicalizeMode::Response { .. } => return r,
}, },
ty::ReErased | ty::ReFree(_) | ty::ReEarlyBound(_) => match self.canonicalize_mode { ty::ReFree(_) | ty::ReEarlyBound(_) => match self.canonicalize_mode {
CanonicalizeMode::Input => CanonicalVarKind::Region(ty::UniverseIndex::ROOT), CanonicalizeMode::Input => CanonicalVarKind::Region(ty::UniverseIndex::ROOT),
CanonicalizeMode::Response { .. } => bug!("unexpected region in response: {r:?}"), CanonicalizeMode::Response { .. } => bug!("unexpected region in response: {r:?}"),
}, },

View File

@ -0,0 +1,15 @@
// revisions: current next
//[next] compile-flags: -Ztrait-solver=next
// check-pass
// Make sure that the compiler can handle `ReErased` in the hidden type of an opaque.
fn foo<'a: 'a>(x: &'a Vec<i32>) -> impl Fn() + 'static {
|| ()
}
fn bar() -> impl Fn() + 'static {
foo(&vec![])
}
fn main() {}