From 698f8c2f01ea549d77d7dc3338a12e04c11057b9 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 17 Apr 2024 14:02:58 +0200 Subject: Adding upstream version 1.64.0+dfsg1. Signed-off-by: Daniel Baumann --- .../ui/borrowck/borrowck-anon-fields-struct.rs | 37 ++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 src/test/ui/borrowck/borrowck-anon-fields-struct.rs (limited to 'src/test/ui/borrowck/borrowck-anon-fields-struct.rs') diff --git a/src/test/ui/borrowck/borrowck-anon-fields-struct.rs b/src/test/ui/borrowck/borrowck-anon-fields-struct.rs new file mode 100644 index 000000000..a05dfe62b --- /dev/null +++ b/src/test/ui/borrowck/borrowck-anon-fields-struct.rs @@ -0,0 +1,37 @@ +// Tests that we are able to distinguish when loans borrow different +// anonymous fields of a tuple vs the same anonymous field. + +struct Y(usize, usize); + +fn distinct_variant() { + let mut y = Y(1, 2); + + let a = match y { + Y(ref mut a, _) => a + }; + + let b = match y { + Y(_, ref mut b) => b + }; + + *a += 1; + *b += 1; +} + +fn same_variant() { + let mut y = Y(1, 2); + + let a = match y { + Y(ref mut a, _) => a + }; + + let b = match y { + Y(ref mut b, _) => b //~ ERROR cannot borrow + }; + + *a += 1; + *b += 1; +} + +fn main() { +} -- cgit v1.2.3