Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow late-bound regions in existential types #60799

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/librustc_typeck/check/writeback.rs
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,8 @@ impl<'cx, 'gcx, 'tcx> WritebackCx<'cx, 'gcx, 'tcx> {
let hir_id = self.tcx().hir().as_local_hir_id(def_id).unwrap();
let instantiated_ty = self.resolve(&opaque_defn.concrete_ty, &hir_id);

debug_assert!(!instantiated_ty.has_escaping_bound_vars());

let generics = self.tcx().generics_of(def_id);

let definition_ty = if generics.parent.is_some() {
Expand Down Expand Up @@ -524,8 +526,9 @@ impl<'cx, 'gcx, 'tcx> WritebackCx<'cx, 'gcx, 'tcx> {
},
lt_op: |region| {
match region {
// ignore static regions
ty::ReStatic => region,
// Skip static and bound regions: they don't
// require substitution.
ty::ReStatic | ty::ReLateBound(..) => region,
_ => {
trace!("checking {:?}", region);
for (subst, p) in opaque_defn.substs.iter().zip(&generics.params) {
Expand Down
30 changes: 30 additions & 0 deletions src/test/ui/existential_types/issue-60655-latebound-regions.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Test that existential types are allowed to contain late-bound regions.

// compile-pass
// edition:2018

#![feature(async_await, existential_type)]

use std::future::Future;

pub existential type Func: Sized;

// Late bound region should be allowed to escape the function, since it's bound
// in the type.
fn null_function_ptr() -> Func {
None::<for<'a> fn(&'a ())>
}

async fn async_nop(_: &u8) {}

pub existential type ServeFut: Future<Output=()>;

// Late bound regions occur in the generator witness type here.
fn serve() -> ServeFut {
async move {
let x = 5;
async_nop(&x).await
}
}

fn main() {}