]> git.lizzy.rs Git - rust.git/blob - src/test/ui/nll/capture-ref-in-struct.rs
Rollup merge of #105216 - GuillaumeGomez:rm-unused-gui-test, r=notriddle
[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 struct SomeStruct<'a, 'b: 'a> {
5     p: &'a mut &'b i32,
6     y: &'b i32,
7 }
8
9 fn test() {
10     let x = 44;
11     let mut p = &x;
12
13     {
14         let y = 22;
15
16         let closure = SomeStruct {
17             p: &mut p,
18             y: &y,
19             //~^ ERROR `y` does not live long enough [E0597]
20         };
21
22         closure.invoke();
23     }
24
25     deref(p);
26 }
27
28 impl<'a, 'b> SomeStruct<'a, 'b> {
29     fn invoke(self) {
30         *self.p = self.y;
31     }
32 }
33
34 fn deref(_: &i32) { }
35
36 fn main() { }