From cf2dff2b1e3fa55fa5415d524200070d0d7aacfe Mon Sep 17 00:00:00 2001 From: Albert Larsan <74931857+albertlarsan68@users.noreply.github.com> Date: Thu, 5 Jan 2023 09:13:28 +0100 Subject: Move /src/test to /tests --- tests/ui/borrowck/borrowck-anon-fields-struct.rs | 37 ++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 tests/ui/borrowck/borrowck-anon-fields-struct.rs (limited to 'tests/ui/borrowck/borrowck-anon-fields-struct.rs') diff --git a/tests/ui/borrowck/borrowck-anon-fields-struct.rs b/tests/ui/borrowck/borrowck-anon-fields-struct.rs new file mode 100644 index 00000000000..a05dfe62b28 --- /dev/null +++ b/tests/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 1.4.1-3-g733a5