]> git.proxmox.com Git - rustc.git/blob - src/test/ui/nll/closure-requirements/escape-upvar-ref.rs
49d31bbc139d73f0b88aca1551900018681a7e6c
[rustc.git] / src / test / ui / nll / closure-requirements / escape-upvar-ref.rs
1 // Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 // Test closure that:
12 //
13 // - captures a variable `y` by reference
14 // - stores that reference to `y` into another, longer-lived place (`p`)
15 //
16 // Both of these are upvars of reference type (the capture of `y` is
17 // of type `&'a i32`, the capture of `p` is of type `&mut &'b
18 // i32`). The closure thus computes a relationship between `'a` and
19 // `'b`. This relationship is propagated to the closure creator,
20 // which reports an error.
21
22 // compile-flags:-Zborrowck=mir -Zverbose
23
24 #![feature(rustc_attrs)]
25
26 #[rustc_regions]
27 fn test() {
28 let x = 44;
29 let mut p = &x;
30
31 {
32 let y = 22;
33 let mut closure = || p = &y;
34 //~^ ERROR `y` does not live long enough [E0597]
35 closure();
36 }
37
38 deref(p);
39 }
40
41 fn deref(_p: &i32) { }
42
43 fn main() { }