about summary refs log tree commit diff
path: root/tests/ui/pattern
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2024-03-02 22:59:19 +0000
committerbors <bors@rust-lang.org>2024-03-02 22:59:19 +0000
commit0decdac390cfeedcd7f2f44c45f72c59c70d8143 (patch)
tree373fbe344b85306b4bb3d048b0b9ab1952a25c06 /tests/ui/pattern
parent5119208fd78a77547c705d1695428c88d6791263 (diff)
parent4c65eef26937b4ea9572eb953ebc523a6cab167b (diff)
downloadrust-0decdac390cfeedcd7f2f44c45f72c59c70d8143.tar.gz
rust-0decdac390cfeedcd7f2f44c45f72c59c70d8143.zip
Auto merge of #121914 - Nadrieril:rollup-ol98ncg, r=Nadrieril
Rollup of 5 pull requests

Successful merges:

 - #120761 (Add initial support for DataFlowSanitizer)
 - #121622 (Preserve same vtable pointer when cloning raw waker, to fix Waker::will_wake)
 - #121716 (match lowering: Lower bindings in a predictable order)
 - #121731 (Now that inlining, mir validation and const eval all use reveal-all, we won't be constraining hidden types here anymore)
 - #121841 (`f16` and `f128` step 2: intrinsics)

r? `@ghost`
`@rustbot` modify labels: rollup
Diffstat (limited to 'tests/ui/pattern')
-rw-r--r--tests/ui/pattern/bindings-after-at/bind-by-copy-or-pat.rs17
-rw-r--r--tests/ui/pattern/bindings-after-at/bind-by-copy-or-pat.stderr31
2 files changed, 48 insertions, 0 deletions
diff --git a/tests/ui/pattern/bindings-after-at/bind-by-copy-or-pat.rs b/tests/ui/pattern/bindings-after-at/bind-by-copy-or-pat.rs
new file mode 100644
index 00000000000..1555da2fd1f
--- /dev/null
+++ b/tests/ui/pattern/bindings-after-at/bind-by-copy-or-pat.rs
@@ -0,0 +1,17 @@
+//@ known-bug: unknown
+#![allow(unused)]
+
+struct A(u32);
+
+pub fn main() {
+    // The or-pattern bindings are lowered after `x`, which triggers the error.
+    let x @ (A(a) | A(a)) = A(10);
+    // ERROR: use of moved value
+    assert!(x.0 == 10);
+    assert!(a == 10);
+
+    // This works.
+    let (x @ A(a) | x @ A(a)) = A(10);
+    assert!(x.0 == 10);
+    assert!(a == 10);
+}
diff --git a/tests/ui/pattern/bindings-after-at/bind-by-copy-or-pat.stderr b/tests/ui/pattern/bindings-after-at/bind-by-copy-or-pat.stderr
new file mode 100644
index 00000000000..79808186358
--- /dev/null
+++ b/tests/ui/pattern/bindings-after-at/bind-by-copy-or-pat.stderr
@@ -0,0 +1,31 @@
+error[E0382]: use of moved value
+  --> $DIR/bind-by-copy-or-pat.rs:8:16
+   |
+LL |     let x @ (A(a) | A(a)) = A(10);
+   |         -      ^            ----- move occurs because value has type `A`, which does not implement the `Copy` trait
+   |         |      |
+   |         |      value used here after move
+   |         value moved here
+   |
+help: borrow this binding in the pattern to avoid moving the value
+   |
+LL |     let ref x @ (A(a) | A(a)) = A(10);
+   |         +++
+
+error[E0382]: use of moved value
+  --> $DIR/bind-by-copy-or-pat.rs:8:23
+   |
+LL |     let x @ (A(a) | A(a)) = A(10);
+   |         -             ^     ----- move occurs because value has type `A`, which does not implement the `Copy` trait
+   |         |             |
+   |         |             value used here after move
+   |         value moved here
+   |
+help: borrow this binding in the pattern to avoid moving the value
+   |
+LL |     let ref x @ (A(a) | A(a)) = A(10);
+   |         +++
+
+error: aborting due to 2 previous errors
+
+For more information about this error, try `rustc --explain E0382`.