2017-11-22 16:39:46 -06:00
|
|
|
// Test closure that:
|
|
|
|
//
|
2017-12-06 15:18:28 -06:00
|
|
|
// - takes an argument `y` with lifetime `'a` (in the code, it's anonymous)
|
|
|
|
// - stores `y` into another, longer-lived spot with lifetime `'b`
|
2017-11-22 16:39:46 -06:00
|
|
|
//
|
2017-12-06 15:18:28 -06:00
|
|
|
// Because `'a` and `'b` are two different, unrelated higher-ranked
|
|
|
|
// regions with no relationship to one another, this is an error. This
|
|
|
|
// error is reported by the closure itself and is not propagated to
|
|
|
|
// its creator: this is because `'a` and `'b` are higher-ranked
|
|
|
|
// (late-bound) regions and the closure is not allowed to propagate
|
|
|
|
// additional where clauses between higher-ranked regions, only those
|
|
|
|
// that appear free in its type (hence, we see it before the closure's
|
|
|
|
// "external requirements" report).
|
2017-11-22 16:39:46 -06:00
|
|
|
|
2018-04-09 04:28:00 -05:00
|
|
|
// compile-flags:-Zborrowck=mir -Zverbose
|
2017-11-22 16:39:46 -06:00
|
|
|
|
|
|
|
#![feature(rustc_attrs)]
|
|
|
|
|
|
|
|
#[rustc_regions]
|
|
|
|
fn test() {
|
|
|
|
let x = 44;
|
|
|
|
let mut p = &x;
|
|
|
|
|
|
|
|
{
|
|
|
|
let y = 22;
|
|
|
|
let mut closure = expect_sig(|p, y| *p = y);
|
2018-07-03 10:38:09 -05:00
|
|
|
//~^ ERROR
|
2017-11-22 16:39:46 -06:00
|
|
|
closure(&mut p, &y);
|
|
|
|
}
|
|
|
|
|
|
|
|
deref(p);
|
|
|
|
}
|
|
|
|
|
|
|
|
fn expect_sig<F>(f: F) -> F
|
|
|
|
where F: FnMut(&mut &i32, &i32)
|
|
|
|
{
|
|
|
|
f
|
|
|
|
}
|
|
|
|
|
|
|
|
fn deref(_p: &i32) { }
|
|
|
|
|
|
|
|
fn main() { }
|