Skip to content

Commit b56e3d9

Browse files
authored
Rollup merge of #91321 - matthewjasper:constaint-placeholders, r=jackh726
Handle placeholder regions in NLL type outlive constraints Closes #76168
2 parents 444635d + 2a83c11 commit b56e3d9

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

compiler/rustc_borrowck/src/type_check/constraint_conversion.rs

+14-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use rustc_infer::infer::region_constraints::{GenericKind, VerifyBound};
66
use rustc_infer::infer::{self, InferCtxt, SubregionOrigin};
77
use rustc_middle::mir::ConstraintCategory;
88
use rustc_middle::ty::subst::GenericArgKind;
9+
use rustc_middle::ty::TypeFoldable;
910
use rustc_middle::ty::{self, TyCtxt};
1011
use rustc_span::DUMMY_SP;
1112

@@ -95,11 +96,23 @@ impl<'a, 'tcx> ConstraintConversion<'a, 'tcx> {
9596
self.add_outlives(r1_vid, r2_vid);
9697
}
9798

98-
GenericArgKind::Type(t1) => {
99+
GenericArgKind::Type(mut t1) => {
99100
// we don't actually use this for anything, but
100101
// the `TypeOutlives` code needs an origin.
101102
let origin = infer::RelateParamBound(DUMMY_SP, t1, None);
102103

104+
// Placeholder regions need to be converted now because it may
105+
// create new region variables, which can't be done later when
106+
// verifying these bounds.
107+
if t1.has_placeholders() {
108+
t1 = tcx.fold_regions(&t1, &mut false, |r, _| match *r {
109+
ty::RegionKind::RePlaceholder(placeholder) => {
110+
self.constraints.placeholder_region(self.infcx, placeholder)
111+
}
112+
_ => r,
113+
});
114+
}
115+
103116
TypeOutlives::new(
104117
&mut *self,
105118
tcx,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// edition:2018
2+
// check-pass
3+
4+
#![feature(unboxed_closures)]
5+
use std::future::Future;
6+
7+
async fn wrapper<F>(f: F)
8+
where for<'a> F: FnOnce<(&'a mut i32,)>,
9+
for<'a> <F as FnOnce<(&'a mut i32,)>>::Output: Future<Output=()> + 'a
10+
{
11+
let mut i = 41;
12+
f(&mut i).await;
13+
}
14+
15+
async fn add_one(i: &mut i32) {
16+
*i = *i + 1;
17+
}
18+
19+
fn main() {}

0 commit comments

Comments
 (0)