From 64d98f8ee037282c35007b64c2649055c56af1db Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 17 Apr 2024 14:19:03 +0200 Subject: Merging upstream version 1.68.2+dfsg1. Signed-off-by: Daniel Baumann --- tests/ui/nll/capture-ref-in-struct.rs | 36 +++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 tests/ui/nll/capture-ref-in-struct.rs (limited to 'tests/ui/nll/capture-ref-in-struct.rs') diff --git a/tests/ui/nll/capture-ref-in-struct.rs b/tests/ui/nll/capture-ref-in-struct.rs new file mode 100644 index 000000000..db6ac7d66 --- /dev/null +++ b/tests/ui/nll/capture-ref-in-struct.rs @@ -0,0 +1,36 @@ +// Test that a structure which tries to store a pointer to `y` into +// `p` (indirectly) fails to compile. + +struct SomeStruct<'a, 'b: 'a> { + p: &'a mut &'b i32, + y: &'b i32, +} + +fn test() { + let x = 44; + let mut p = &x; + + { + let y = 22; + + let closure = SomeStruct { + p: &mut p, + y: &y, + //~^ ERROR `y` does not live long enough [E0597] + }; + + closure.invoke(); + } + + deref(p); +} + +impl<'a, 'b> SomeStruct<'a, 'b> { + fn invoke(self) { + *self.p = self.y; + } +} + +fn deref(_: &i32) { } + +fn main() { } -- cgit v1.2.3