diff options
| author | Nadrieril <nadrieril+git@gmail.com> | 2024-02-28 00:55:01 +0100 |
|---|---|---|
| committer | Nadrieril <nadrieril+git@gmail.com> | 2024-02-28 01:41:25 +0100 |
| commit | 97bfa106c7a5f916bed7b0a329276cabb20f58ea (patch) | |
| tree | 3c8de318108af73189bd51fa4bd006c07bcf9411 | |
| parent | 5d31e29b56c9e7c8fad184eae8f5eae351f267d8 (diff) | |
| download | rust-97bfa106c7a5f916bed7b0a329276cabb20f58ea.tar.gz rust-97bfa106c7a5f916bed7b0a329276cabb20f58ea.zip | |
Add test for the known case that doesn't work
| -rw-r--r-- | tests/ui/pattern/bindings-after-at/bind-by-copy-or-pat.rs | 17 | ||||
| -rw-r--r-- | tests/ui/pattern/bindings-after-at/bind-by-copy-or-pat.stderr | 31 |
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`. |
