2017-11-22 16:39:46 -06:00
|
|
|
// Test closure that:
|
2017-12-06 15:19:26 -06:00
|
|
|
//
|
|
|
|
// - captures a variable `y` by reference
|
|
|
|
// - stores that reference to `y` into another, longer-lived place (`p`)
|
|
|
|
//
|
|
|
|
// Both of these are upvars of reference type (the capture of `y` is
|
|
|
|
// of type `&'a i32`, the capture of `p` is of type `&mut &'b
|
|
|
|
// i32`). The closure thus computes a relationship between `'a` and
|
|
|
|
// `'b`. This relationship is propagated to the closure creator,
|
|
|
|
// which reports an error.
|
2017-11-22 16:39:46 -06:00
|
|
|
|
2022-04-01 12:13:25 -05:00
|
|
|
// compile-flags:-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 = || p = &y;
|
2017-12-11 11:29:31 -06:00
|
|
|
//~^ ERROR `y` does not live long enough [E0597]
|
2017-11-22 16:39:46 -06:00
|
|
|
closure();
|
2017-12-11 11:29:31 -06:00
|
|
|
}
|
2017-11-22 16:39:46 -06:00
|
|
|
|
|
|
|
deref(p);
|
|
|
|
}
|
|
|
|
|
|
|
|
fn deref(_p: &i32) { }
|
|
|
|
|
|
|
|
fn main() { }
|