Skip to content

Commit d748712

Browse files
committed
Propagate all closure requirements to the caller
1 parent 0c999ed commit d748712

File tree

3 files changed

+43
-1
lines changed

3 files changed

+43
-1
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

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)