about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--compiler/rustc_typeck/src/check/pat.rs5
-rw-r--r--src/test/ui/destructuring-assignment/tuple_struct_destructure_fail.stderr8
-rw-r--r--src/test/ui/issues/issue-67037-pat-tup-scrut-ty-diff-less-fields.stderr4
-rw-r--r--src/test/ui/match/match-pattern-field-mismatch.stderr4
-rw-r--r--src/test/ui/pattern/pat-tuple-underfield.rs2
-rw-r--r--src/test/ui/pattern/pat-tuple-underfield.stderr20
6 files changed, 35 insertions, 8 deletions
diff --git a/compiler/rustc_typeck/src/check/pat.rs b/compiler/rustc_typeck/src/check/pat.rs
index e176389f0e2..ecc6e8599ad 100644
--- a/compiler/rustc_typeck/src/check/pat.rs
+++ b/compiler/rustc_typeck/src/check/pat.rs
@@ -1068,8 +1068,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
                 Applicability::MaybeIncorrect,
             );
 
-            // Only suggest `..` if more than one field is missing.
-            if fields.len() - subpats.len() > 1 {
+            // Only suggest `..` if more than one field is missing
+            // or the pattern consists of all wildcards.
+            if fields.len() - subpats.len() > 1 || all_wildcards {
                 if subpats.is_empty() || all_wildcards {
                     err.span_suggestion_verbose(
                         all_fields_span,
diff --git a/src/test/ui/destructuring-assignment/tuple_struct_destructure_fail.stderr b/src/test/ui/destructuring-assignment/tuple_struct_destructure_fail.stderr
index 8c20bb4fb83..c270593cac7 100644
--- a/src/test/ui/destructuring-assignment/tuple_struct_destructure_fail.stderr
+++ b/src/test/ui/destructuring-assignment/tuple_struct_destructure_fail.stderr
@@ -36,6 +36,10 @@ help: use `_` to explicitly ignore each field
    |
 LL |     TupleStruct(_, _) = TupleStruct(1, 2);
    |                  ^^^
+help: use `..` to ignore all fields
+   |
+LL |     TupleStruct(..) = TupleStruct(1, 2);
+   |                 ^^
 
 error[E0023]: this pattern has 3 fields, but the corresponding tuple variant has 2 fields
   --> $DIR/tuple_struct_destructure_fail.rs:34:5
@@ -59,6 +63,10 @@ help: use `_` to explicitly ignore each field
    |
 LL |     Enum::SingleVariant(_, _) = Enum::SingleVariant(1, 2);
    |                          ^^^
+help: use `..` to ignore all fields
+   |
+LL |     Enum::SingleVariant(..) = Enum::SingleVariant(1, 2);
+   |                         ^^
 
 error[E0070]: invalid left-hand side of assignment
   --> $DIR/tuple_struct_destructure_fail.rs:40:12
diff --git a/src/test/ui/issues/issue-67037-pat-tup-scrut-ty-diff-less-fields.stderr b/src/test/ui/issues/issue-67037-pat-tup-scrut-ty-diff-less-fields.stderr
index 46ffac48c1b..9bdbf0bf9f4 100644
--- a/src/test/ui/issues/issue-67037-pat-tup-scrut-ty-diff-less-fields.stderr
+++ b/src/test/ui/issues/issue-67037-pat-tup-scrut-ty-diff-less-fields.stderr
@@ -22,6 +22,10 @@ help: use `_` to explicitly ignore each field
    |
 LL |     let P(_) = U {};
    |           ^
+help: use `..` to ignore all fields
+   |
+LL |     let P(..) = U {};
+   |           ^^
 
 error: aborting due to 2 previous errors
 
diff --git a/src/test/ui/match/match-pattern-field-mismatch.stderr b/src/test/ui/match/match-pattern-field-mismatch.stderr
index 04f8cab900e..37839482b31 100644
--- a/src/test/ui/match/match-pattern-field-mismatch.stderr
+++ b/src/test/ui/match/match-pattern-field-mismatch.stderr
@@ -11,6 +11,10 @@ help: use `_` to explicitly ignore each field
    |
 LL |           Color::Rgb(_, _, _) => { }
    |                          ^^^
+help: use `..` to ignore all fields
+   |
+LL |           Color::Rgb(..) => { }
+   |                      ^^
 
 error: aborting due to previous error
 
diff --git a/src/test/ui/pattern/pat-tuple-underfield.rs b/src/test/ui/pattern/pat-tuple-underfield.rs
index 50f8a855d36..ed852a47bb4 100644
--- a/src/test/ui/pattern/pat-tuple-underfield.rs
+++ b/src/test/ui/pattern/pat-tuple-underfield.rs
@@ -14,6 +14,7 @@ fn main() {
         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() => {}
@@ -31,6 +32,7 @@ fn main() {
         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() => {}
diff --git a/src/test/ui/pattern/pat-tuple-underfield.stderr b/src/test/ui/pattern/pat-tuple-underfield.stderr
index cdf7cfe3005..76323d9a7bf 100644
--- a/src/test/ui/pattern/pat-tuple-underfield.stderr
+++ b/src/test/ui/pattern/pat-tuple-underfield.stderr
@@ -1,5 +1,5 @@
 error[E0532]: expected unit struct, unit variant or constant, found tuple variant `E::S`
-  --> $DIR/pat-tuple-underfield.rs:42:9
+  --> $DIR/pat-tuple-underfield.rs:44:9
    |
 LL |     S(i32, f32),
    |     ----------- `E::S` defined here
@@ -34,9 +34,13 @@ help: use `_` to explicitly ignore each field
    |
 LL |         S(_, _) => {}
    |            ^^^
+help: use `..` to ignore all fields
+   |
+LL |         S(..) => {}
+   |           ^^
 
 error[E0023]: this pattern has 0 fields, but the corresponding tuple struct has 2 fields
-  --> $DIR/pat-tuple-underfield.rs:19:9
+  --> $DIR/pat-tuple-underfield.rs:20:9
    |
 LL | struct S(i32, f32);
    | ------------------- tuple struct defined here
@@ -54,7 +58,7 @@ LL |         S(..) => {}
    |           ^^
 
 error[E0023]: this pattern has 1 field, but the corresponding tuple variant has 2 fields
-  --> $DIR/pat-tuple-underfield.rs:26:9
+  --> $DIR/pat-tuple-underfield.rs:27:9
    |
 LL |     S(i32, f32),
    |     ----------- tuple variant defined here
@@ -68,7 +72,7 @@ LL |         E::S(x, _) => {}
    |               ^^^
 
 error[E0023]: this pattern has 1 field, but the corresponding tuple variant has 2 fields
-  --> $DIR/pat-tuple-underfield.rs:31:9
+  --> $DIR/pat-tuple-underfield.rs:32:9
    |
 LL |     S(i32, f32),
    |     ----------- tuple variant defined here
@@ -80,9 +84,13 @@ help: use `_` to explicitly ignore each field
    |
 LL |         E::S(_, _) => {}
    |               ^^^
+help: use `..` to ignore all fields
+   |
+LL |         E::S(..) => {}
+   |              ^^
 
 error[E0023]: this pattern has 0 fields, but the corresponding tuple variant has 2 fields
-  --> $DIR/pat-tuple-underfield.rs:36:9
+  --> $DIR/pat-tuple-underfield.rs:38:9
    |
 LL |     S(i32, f32),
    |     ----------- tuple variant defined here
@@ -100,7 +108,7 @@ LL |         E::S(..) => {}
    |              ^^
 
 error[E0023]: this pattern has 2 fields, but the corresponding tuple struct has 4 fields
-  --> $DIR/pat-tuple-underfield.rs:48:9
+  --> $DIR/pat-tuple-underfield.rs:50:9
    |
 LL | struct Point4(i32, i32, i32, i32);
    | ---------------------------------- tuple struct defined here