]> git.lizzy.rs Git - rust.git/blob - src/test/ui/nll/capture-ref-in-struct.rs
Rollup merge of #60685 - dtolnay:spdx, r=nikomatsakis
[rust.git] / src / test / ui / nll / capture-ref-in-struct.rs
1 // Test that a structure which tries to store a pointer to `y` into
2 // `p` (indirectly) fails to compile.
3
4 #![feature(rustc_attrs)]
5 #![feature(nll)]
6
7 struct SomeStruct<'a, 'b: 'a> {
8     p: &'a mut &'b i32,
9     y: &'b i32,
10 }
11
12 fn test() {
13     let x = 44;
14     let mut p = &x;
15
16     {
17         let y = 22;
18
19         let closure = SomeStruct {
20             p: &mut p,
21             y: &y,
22             //~^ ERROR `y` does not live long enough [E0597]
23         };
24
25         closure.invoke();
26     }
27
28     deref(p);
29 }
30
31 impl<'a, 'b> SomeStruct<'a, 'b> {
32     fn invoke(self) {
33         *self.p = self.y;
34     }
35 }
36
37 fn deref(_: &i32) { }
38
39 fn main() { }