Skip to content

Commit b3af092

Browse files
committed
Auto merge of #56486 - matthewjasper:propagate-all-closure-bounds, r=pnkfelix
Propagate all closure requirements to the caller Closes #56477 This should be backported to 1.32 if it doesn't make the cut. r? @pnkfelix cc @nikomatsakis
2 parents 906deae + b2e6da7 commit b3af092

File tree

4 files changed

+46
-4
lines changed

4 files changed

+46
-4
lines changed

src/librustc_mir/borrow_check/nll/region_infer/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1208,7 +1208,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
12081208
blame_span: blame_span_category.1,
12091209
category: blame_span_category.0,
12101210
});
1211-
return;
1211+
continue;
12121212
}
12131213
}
12141214

src/librustc_typeck/check/wfcheck.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -355,13 +355,13 @@ fn check_item_type<'a, 'tcx>(
355355
) {
356356
debug!("check_item_type: {:?}", item_id);
357357

358-
for_id(tcx, item_id, ty_span).with_fcx(|fcx, _this| {
359-
let ty = fcx.tcx.type_of(fcx.tcx.hir.local_def_id(item_id));
358+
for_id(tcx, item_id, ty_span).with_fcx(|fcx, gcx| {
359+
let ty = gcx.type_of(gcx.hir.local_def_id(item_id));
360360
let item_ty = fcx.normalize_associated_types_in(ty_span, &ty);
361361

362362
let mut forbid_unsized = true;
363363
if allow_foreign_ty {
364-
if let TyKind::Foreign(_) = tcx.struct_tail(item_ty).sty {
364+
if let TyKind::Foreign(_) = fcx.tcx.struct_tail(item_ty).sty {
365365
forbid_unsized = false;
366366
}
367367
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Test that we propagate *all* requirements to the caller, not just the first
2+
// one.
3+
4+
#![feature(nll)]
5+
6+
fn once<S, T, U, F: FnOnce(S, T) -> U>(f: F, s: S, t: T) -> U {
7+
f(s, t)
8+
}
9+
10+
pub fn dangle() -> &'static [i32] {
11+
let other_local_arr = [0, 2, 4];
12+
let local_arr = other_local_arr;
13+
let mut out: &mut &'static [i32] = &mut (&[1] as _);
14+
once(|mut z: &[i32], mut out_val: &mut &[i32]| {
15+
// We unfortunately point to the first use in the closure in the error
16+
// message
17+
z = &local_arr; //~ ERROR
18+
*out_val = &local_arr;
19+
}, &[] as &[_], &mut *out);
20+
*out
21+
}
22+
23+
fn main() {
24+
println!("{:?}", dangle());
25+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
error[E0597]: `local_arr` does not live long enough
2+
--> $DIR/propagate-multiple-requirements.rs:17:14
3+
|
4+
LL | let mut out: &mut &'static [i32] = &mut (&[1] as _);
5+
| ------------------- type annotation requires that `local_arr` is borrowed for `'static`
6+
LL | once(|mut z: &[i32], mut out_val: &mut &[i32]| {
7+
| ----------------------------------------- value captured here
8+
...
9+
LL | z = &local_arr; //~ ERROR
10+
| ^^^^^^^^^ borrowed value does not live long enough
11+
...
12+
LL | }
13+
| - `local_arr` dropped here while still borrowed
14+
15+
error: aborting due to previous error
16+
17+
For more information about this error, try `rustc --explain E0597`.

0 commit comments

Comments
 (0)