Skip to content

Commit fd92bc6

Browse files
Handle ReErased in responses in new solver
1 parent 1322f92 commit fd92bc6

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

compiler/rustc_trait_selection/src/solve/canonicalize.rs

+10-2
Original file line numberDiff line numberDiff line change
@@ -224,12 +224,20 @@ impl<'tcx> TypeFolder<TyCtxt<'tcx>> for Canonicalizer<'_, 'tcx> {
224224
let kind = match *r {
225225
ty::ReLateBound(..) => return r,
226226

227-
ty::ReStatic => match self.canonicalize_mode {
227+
// We may encounter `ReStatic` in item signatures or the hidden type
228+
// of an opaque. `ReErased` should only be encountered in the hidden
229+
// type of an opaque for regions that are ignored for the purposes of
230+
// captures.
231+
//
232+
// FIXME: We should investigate the perf implications of not uniquifying
233+
// `ReErased`. We may be able to short-circuit registering region
234+
// obligations if we encounter a `ReErased` on one side, for example.
235+
ty::ReStatic | ty::ReErased => match self.canonicalize_mode {
228236
CanonicalizeMode::Input => CanonicalVarKind::Region(ty::UniverseIndex::ROOT),
229237
CanonicalizeMode::Response { .. } => return r,
230238
},
231239

232-
ty::ReErased | ty::ReFree(_) | ty::ReEarlyBound(_) => match self.canonicalize_mode {
240+
ty::ReFree(_) | ty::ReEarlyBound(_) => match self.canonicalize_mode {
233241
CanonicalizeMode::Input => CanonicalVarKind::Region(ty::UniverseIndex::ROOT),
234242
CanonicalizeMode::Response { .. } => bug!("unexpected region in response: {r:?}"),
235243
},
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// revisions: current next
2+
//[next] compile-flags: -Ztrait-solver=next
3+
// check-pass
4+
5+
// Make sure that the compiler can handle `ReErased` in the hidden type of an opaque.
6+
7+
fn foo<'a: 'a>(x: &'a Vec<i32>) -> impl Fn() + 'static {
8+
|| ()
9+
}
10+
11+
fn bar() -> impl Fn() + 'static {
12+
foo(&vec![])
13+
}
14+
15+
fn main() {}

0 commit comments

Comments
 (0)