Propagate all closure requirements to the caller
This commit is contained in:
parent
0c999ed132
commit
d748712521
3 changed files with 43 additions and 1 deletions
|
@ -1208,7 +1208,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
|
|||
blame_span: blame_span_category.1,
|
||||
category: blame_span_category.0,
|
||||
});
|
||||
return;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,25 @@
|
|||
// Test that we propagate *all* requirements to the caller, not just the first
|
||||
// one.
|
||||
|
||||
#![feature(nll)]
|
||||
|
||||
fn once<S, T, U, F: FnOnce(S, T) -> U>(f: F, s: S, t: T) -> U {
|
||||
f(s, t)
|
||||
}
|
||||
|
||||
pub fn dangle() -> &'static [i32] {
|
||||
let other_local_arr = [0, 2, 4];
|
||||
let local_arr = other_local_arr;
|
||||
let mut out: &mut &'static [i32] = &mut (&[1] as _);
|
||||
once(|mut z: &[i32], mut out_val: &mut &[i32]| {
|
||||
// We unfortunately point to the first use in the closure in the error
|
||||
// message
|
||||
z = &local_arr; //~ ERROR
|
||||
*out_val = &local_arr;
|
||||
}, &[] as &[_], &mut *out);
|
||||
*out
|
||||
}
|
||||
|
||||
fn main() {
|
||||
println!("{:?}", dangle());
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
error[E0597]: `local_arr` does not live long enough
|
||||
--> $DIR/propagate-multiple-requirements.rs:17:14
|
||||
|
|
||||
LL | let mut out: &mut &'static [i32] = &mut (&[1] as _);
|
||||
| ------------------- type annotation requires that `local_arr` is borrowed for `'static`
|
||||
LL | once(|mut z: &[i32], mut out_val: &mut &[i32]| {
|
||||
| ----------------------------------------- value captured here
|
||||
...
|
||||
LL | z = &local_arr; //~ ERROR
|
||||
| ^^^^^^^^^ borrowed value does not live long enough
|
||||
...
|
||||
LL | }
|
||||
| - `local_arr` dropped here while still borrowed
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0597`.
|
Loading…
Add table
Reference in a new issue