summaryrefslogtreecommitdiffstats
path: root/src/test/ui/borrowck/borrowck-move-out-from-array-use-no-overlap-match.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:02:58 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:02:58 +0000
commit698f8c2f01ea549d77d7dc3338a12e04c11057b9 (patch)
tree173a775858bd501c378080a10dca74132f05bc50 /src/test/ui/borrowck/borrowck-move-out-from-array-use-no-overlap-match.rs
parentInitial commit. (diff)
downloadrustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.tar.xz
rustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.zip
Adding upstream version 1.64.0+dfsg1.upstream/1.64.0+dfsg1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/test/ui/borrowck/borrowck-move-out-from-array-use-no-overlap-match.rs')
-rw-r--r--src/test/ui/borrowck/borrowck-move-out-from-array-use-no-overlap-match.rs115
1 files changed, 115 insertions, 0 deletions
diff --git a/src/test/ui/borrowck/borrowck-move-out-from-array-use-no-overlap-match.rs b/src/test/ui/borrowck/borrowck-move-out-from-array-use-no-overlap-match.rs
new file mode 100644
index 000000000..017ca90b8
--- /dev/null
+++ b/src/test/ui/borrowck/borrowck-move-out-from-array-use-no-overlap-match.rs
@@ -0,0 +1,115 @@
+// Due to #53114, which causes a "read" of the `_` patterns,
+// the borrow-checker refuses this code, while it should probably be allowed.
+// Once the bug is fixed, the test, which is derived from a
+// passing test for `let` statements, should become check-pass.
+
+fn array() -> [(String, String); 3] {
+ Default::default()
+}
+
+// Const Index + Const Index
+
+fn move_out_from_begin_and_one_from_end() {
+ let a = array();
+ match a {
+ [_, _, _x] => {}
+ }
+ match a {
+ //~^ ERROR use of partially moved value
+ [.., ref _y, _] => {}
+ }
+}
+
+fn move_out_from_begin_field_and_end_field() {
+ let a = array();
+ match a {
+ [_, _, (_x, _)] => {}
+ }
+ match a {
+ //~^ ERROR use of partially moved value
+ [.., (_, ref _y)] => {}
+ }
+}
+
+// Const Index + Slice
+
+fn move_out_by_const_index_and_subslice() {
+ let a = array();
+ match a {
+ [_x, _, _] => {}
+ }
+ match a {
+ //~^ ERROR use of partially moved value
+ [_, ref _y @ ..] => {}
+ }
+}
+
+fn move_out_by_const_index_end_and_subslice() {
+ let a = array();
+ match a {
+ [.., _x] => {}
+ }
+ match a {
+ //~^ ERROR use of partially moved value
+ [ref _y @ .., _] => {}
+ }
+}
+
+fn move_out_by_const_index_field_and_subslice() {
+ let a = array();
+ match a {
+ [(_x, _), _, _] => {}
+ }
+ match a {
+ //~^ ERROR use of partially moved value
+ [_, ref _y @ ..] => {}
+ }
+}
+
+fn move_out_by_const_index_end_field_and_subslice() {
+ let a = array();
+ match a {
+ [.., (_x, _)] => {}
+ }
+ match a {
+ //~^ ERROR use of partially moved value
+ [ref _y @ .., _] => {}
+ }
+}
+
+fn move_out_by_const_subslice_and_index_field() {
+ let a = array();
+ match a {
+ [_, _y @ ..] => {}
+ }
+ match a {
+ //~^ ERROR use of partially moved value
+ [(ref _x, _), _, _] => {}
+ }
+}
+
+fn move_out_by_const_subslice_and_end_index_field() {
+ let a = array();
+ match a {
+ [_y @ .., _] => {}
+ }
+ match a {
+ //~^ ERROR use of partially moved value
+ [.., (ref _x, _)] => {}
+ }
+}
+
+// Slice + Slice
+
+fn move_out_by_subslice_and_subslice() {
+ let a = array();
+ match a {
+ [x @ .., _, _] => {}
+ }
+ match a {
+ //~^ ERROR use of partially moved value
+ [_, ref _y @ ..] => {}
+ }
+}
+
+fn main() {}