diff options
Diffstat (limited to 'tests/ui/nll/closure-requirements/escape-upvar-nested.rs')
-rw-r--r-- | tests/ui/nll/closure-requirements/escape-upvar-nested.rs | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/tests/ui/nll/closure-requirements/escape-upvar-nested.rs b/tests/ui/nll/closure-requirements/escape-upvar-nested.rs new file mode 100644 index 000000000..765a3cf96 --- /dev/null +++ b/tests/ui/nll/closure-requirements/escape-upvar-nested.rs @@ -0,0 +1,33 @@ +// As in `escape-upvar-ref.rs`, test closure that: +// +// - captures a variable `y` +// - stores reference to `y` into another, longer-lived spot +// +// except that the closure does so via a second closure. + +// compile-flags:-Zverbose + +#![feature(rustc_attrs)] + +#[rustc_regions] +fn test() { + let x = 44; + let mut p = &x; + + { + let y = 22; + + let mut closure = || { + let mut closure1 = || p = &y; //~ ERROR `y` does not live long enough [E0597] + closure1(); + }; + + closure(); + } + + deref(p); +} + +fn deref(_p: &i32) { } + +fn main() { } |