summaryrefslogtreecommitdiffstats
path: root/tests/ui/pattern/pat-tuple-underfield.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:19:03 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:19:03 +0000
commit64d98f8ee037282c35007b64c2649055c56af1db (patch)
tree5492bcf97fce41ee1c0b1cc2add283f3e66cdab0 /tests/ui/pattern/pat-tuple-underfield.rs
parentAdding debian version 1.67.1+dfsg1-1. (diff)
downloadrustc-64d98f8ee037282c35007b64c2649055c56af1db.tar.xz
rustc-64d98f8ee037282c35007b64c2649055c56af1db.zip
Merging upstream version 1.68.2+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/ui/pattern/pat-tuple-underfield.rs')
-rw-r--r--tests/ui/pattern/pat-tuple-underfield.rs67
1 files changed, 67 insertions, 0 deletions
diff --git a/tests/ui/pattern/pat-tuple-underfield.rs b/tests/ui/pattern/pat-tuple-underfield.rs
new file mode 100644
index 000000000..dac60e3fa
--- /dev/null
+++ b/tests/ui/pattern/pat-tuple-underfield.rs
@@ -0,0 +1,67 @@
+struct S(i32, f32);
+enum E {
+ S(i32, f32),
+}
+struct Point4(i32, i32, i32, i32);
+
+fn main() {
+ match S(0, 1.0) {
+ S(x) => {}
+ //~^ ERROR this pattern has 1 field, but the corresponding tuple struct has 2 fields
+ //~| HELP use `_` to explicitly ignore each field
+ }
+ match S(0, 1.0) {
+ S(_) => {}
+ //~^ ERROR this pattern has 1 field, but the corresponding tuple struct has 2 fields
+ //~| HELP use `_` to explicitly ignore each field
+ //~| HELP use `..` to ignore all fields
+ }
+ match S(0, 1.0) {
+ S() => {}
+ //~^ ERROR this pattern has 0 fields, but the corresponding tuple struct has 2 fields
+ //~| HELP use `_` to explicitly ignore each field
+ //~| HELP use `..` to ignore all fields
+
+ // Test non-standard formatting
+ S () => {}
+ //~^ ERROR this pattern has 0 fields, but the corresponding tuple struct has 2 fields
+ //~| HELP use `_` to explicitly ignore each field
+ //~| HELP use `..` to ignore all fields
+ }
+
+ match E::S(0, 1.0) {
+ E::S(x) => {}
+ //~^ ERROR this pattern has 1 field, but the corresponding tuple variant has 2 fields
+ //~| HELP use `_` to explicitly ignore each field
+ }
+ match E::S(0, 1.0) {
+ E::S(_) => {}
+ //~^ ERROR this pattern has 1 field, but the corresponding tuple variant has 2 fields
+ //~| HELP use `_` to explicitly ignore each field
+ //~| HELP use `..` to ignore all fields
+ }
+ match E::S(0, 1.0) {
+ E::S() => {}
+ //~^ ERROR this pattern has 0 fields, but the corresponding tuple variant has 2 fields
+ //~| HELP use `_` to explicitly ignore each field
+ //~| HELP use `..` to ignore all fields
+
+ // Test non-standard formatting
+ E::S () => {}
+ //~^ ERROR this pattern has 0 fields, but the corresponding tuple variant has 2 fields
+ //~| HELP use `_` to explicitly ignore each field
+ //~| HELP use `..` to ignore all fields
+ }
+ match E::S(0, 1.0) {
+ E::S => {}
+ //~^ ERROR expected unit struct, unit variant or constant, found tuple variant `E::S`
+ //~| HELP use the tuple variant pattern syntax instead
+ }
+
+ match Point4(0, 1, 2, 3) {
+ Point4( a , _ ) => {}
+ //~^ ERROR this pattern has 2 fields, but the corresponding tuple struct has 4 fields
+ //~| HELP use `_` to explicitly ignore each field
+ //~| HELP use `..` to ignore the rest of the fields
+ }
+}