Skip to content

Commit b24981a

Browse files
authored
Rollup merge of #60799 - matthewjasper:allow-bound-regions-in-existential-types, r=oli-obk
Allow late-bound regions in existential types closes #60655 r? @oli-obk
2 parents 29f93ad + 36fd00e commit b24981a

File tree

2 files changed

+35
-2
lines changed

2 files changed

+35
-2
lines changed

src/librustc_typeck/check/writeback.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,8 @@ impl<'cx, 'gcx, 'tcx> WritebackCx<'cx, 'gcx, 'tcx> {
466466
let hir_id = self.tcx().hir().as_local_hir_id(def_id).unwrap();
467467
let instantiated_ty = self.resolve(&opaque_defn.concrete_ty, &hir_id);
468468

469+
debug_assert!(!instantiated_ty.has_escaping_bound_vars());
470+
469471
let generics = self.tcx().generics_of(def_id);
470472

471473
let definition_ty = if generics.parent.is_some() {
@@ -524,8 +526,9 @@ impl<'cx, 'gcx, 'tcx> WritebackCx<'cx, 'gcx, 'tcx> {
524526
},
525527
lt_op: |region| {
526528
match region {
527-
// ignore static regions
528-
ty::ReStatic => region,
529+
// Skip static and bound regions: they don't
530+
// require substitution.
531+
ty::ReStatic | ty::ReLateBound(..) => region,
529532
_ => {
530533
trace!("checking {:?}", region);
531534
for (subst, p) in opaque_defn.substs.iter().zip(&generics.params) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Test that existential types are allowed to contain late-bound regions.
2+
3+
// compile-pass
4+
// edition:2018
5+
6+
#![feature(async_await, existential_type)]
7+
8+
use std::future::Future;
9+
10+
pub existential type Func: Sized;
11+
12+
// Late bound region should be allowed to escape the function, since it's bound
13+
// in the type.
14+
fn null_function_ptr() -> Func {
15+
None::<for<'a> fn(&'a ())>
16+
}
17+
18+
async fn async_nop(_: &u8) {}
19+
20+
pub existential type ServeFut: Future<Output=()>;
21+
22+
// Late bound regions occur in the generator witness type here.
23+
fn serve() -> ServeFut {
24+
async move {
25+
let x = 5;
26+
async_nop(&x).await
27+
}
28+
}
29+
30+
fn main() {}

0 commit comments

Comments
 (0)