about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--compiler/rustc_typeck/src/check/pat.rs33
-rw-r--r--src/test/ui/destructuring-assignment/tuple_struct_destructure_fail.stderr28
-rw-r--r--src/test/ui/error-codes/E0023.stderr14
-rw-r--r--src/test/ui/issues/issue-67037-pat-tup-scrut-ty-diff-less-fields.stderr14
-rw-r--r--src/test/ui/issues/issue-72574-2.stderr14
-rw-r--r--src/test/ui/match/match-pattern-field-mismatch.stderr14
-rw-r--r--src/test/ui/pattern/issue-74539.stderr14
-rw-r--r--src/test/ui/pattern/pat-tuple-underfield.rs4
-rw-r--r--src/test/ui/pattern/pat-tuple-underfield.stderr68
9 files changed, 68 insertions, 135 deletions
diff --git a/compiler/rustc_typeck/src/check/pat.rs b/compiler/rustc_typeck/src/check/pat.rs
index 43a69fe1874..a863fc95e0e 100644
--- a/compiler/rustc_typeck/src/check/pat.rs
+++ b/compiler/rustc_typeck/src/check/pat.rs
@@ -1061,27 +1061,30 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
                 wildcard_sugg = String::from(", ") + &wildcard_sugg;
             }
 
-            err.span_suggestion(
+            err.span_suggestion_short(
                 after_fields_span,
                 "use `_` to explicitly ignore each field",
                 wildcard_sugg,
                 Applicability::MaybeIncorrect,
             );
 
-            if subpats.is_empty() || all_wildcards {
-                err.span_suggestion(
-                    all_fields_span,
-                    "use `..` to ignore all fields",
-                    String::from(".."),
-                    Applicability::MaybeIncorrect,
-                );
-            } else {
-                err.span_suggestion(
-                    after_fields_span,
-                    "use `..` to ignore the rest of the fields",
-                    String::from(", .."),
-                    Applicability::MaybeIncorrect,
-                );
+            // Only suggest `..` if more than one field is missing.
+            if fields.len() - subpats.len() > 1 {
+                if subpats.is_empty() || all_wildcards {
+                    err.span_suggestion_short(
+                        all_fields_span,
+                        "use `..` to ignore all fields",
+                        String::from(".."),
+                        Applicability::MaybeIncorrect,
+                    );
+                } else {
+                    err.span_suggestion_short(
+                        after_fields_span,
+                        "use `..` to ignore the rest of the fields",
+                        String::from(", .."),
+                        Applicability::MaybeIncorrect,
+                    );
+                }
             }
         }
 
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 c270593cac7..42859406e17 100644
--- a/src/test/ui/destructuring-assignment/tuple_struct_destructure_fail.stderr
+++ b/src/test/ui/destructuring-assignment/tuple_struct_destructure_fail.stderr
@@ -30,16 +30,10 @@ LL | struct TupleStruct<S, T>(S, T);
    | ------------------------------- tuple struct defined here
 ...
 LL |     TupleStruct(_) = TupleStruct(1, 2);
-   |     ^^^^^^^^^^^^^^ expected 2 fields, found 1
-   |
-help: use `_` to explicitly ignore each field
-   |
-LL |     TupleStruct(_, _) = TupleStruct(1, 2);
-   |                  ^^^
-help: use `..` to ignore all fields
-   |
-LL |     TupleStruct(..) = TupleStruct(1, 2);
-   |                 ^^
+   |     ^^^^^^^^^^^^^-
+   |     |            |
+   |     |            help: use `_` to explicitly ignore each field
+   |     expected 2 fields, found 1
 
 error[E0023]: this pattern has 3 fields, but the corresponding tuple variant has 2 fields
   --> $DIR/tuple_struct_destructure_fail.rs:34:5
@@ -57,16 +51,10 @@ LL |     SingleVariant(S, T)
    |     ------------------- tuple variant defined here
 ...
 LL |     Enum::SingleVariant(_) = Enum::SingleVariant(1, 2);
-   |     ^^^^^^^^^^^^^^^^^^^^^^ expected 2 fields, found 1
-   |
-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);
-   |                         ^^
+   |     ^^^^^^^^^^^^^^^^^^^^^-
+   |     |                    |
+   |     |                    help: use `_` to explicitly ignore each field
+   |     expected 2 fields, found 1
 
 error[E0070]: invalid left-hand side of assignment
   --> $DIR/tuple_struct_destructure_fail.rs:40:12
diff --git a/src/test/ui/error-codes/E0023.stderr b/src/test/ui/error-codes/E0023.stderr
index aaaada518d3..0c6f496cf43 100644
--- a/src/test/ui/error-codes/E0023.stderr
+++ b/src/test/ui/error-codes/E0023.stderr
@@ -5,16 +5,10 @@ LL |     Apple(String, String),
    |     --------------------- tuple variant defined here
 ...
 LL |         Fruit::Apple(a) => {},
-   |         ^^^^^^^^^^^^^^^ expected 2 fields, found 1
-   |
-help: use `_` to explicitly ignore each field
-   |
-LL |         Fruit::Apple(a, _) => {},
-   |                       ^^^
-help: use `..` to ignore the rest of the fields
-   |
-LL |         Fruit::Apple(a, ..) => {},
-   |                       ^^^^
+   |         ^^^^^^^^^^^^^^-
+   |         |             |
+   |         |             help: use `_` to explicitly ignore each field
+   |         expected 2 fields, found 1
 
 error[E0023]: this pattern has 3 fields, but the corresponding tuple variant has 2 fields
   --> $DIR/E0023.rs:12:9
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 9bdbf0bf9f4..86be8e7db4e 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
@@ -16,16 +16,10 @@ LL | struct P<T>(T); // 1 type parameter wanted
    | --------------- tuple struct defined here
 ...
 LL |     let P() = U {};
-   |         ^^^ expected 1 field, found 0
-   |
-help: use `_` to explicitly ignore each field
-   |
-LL |     let P(_) = U {};
-   |           ^
-help: use `..` to ignore all fields
-   |
-LL |     let P(..) = U {};
-   |           ^^
+   |         ^^-
+   |         | |
+   |         | help: use `_` to explicitly ignore each field
+   |         expected 1 field, found 0
 
 error: aborting due to 2 previous errors
 
diff --git a/src/test/ui/issues/issue-72574-2.stderr b/src/test/ui/issues/issue-72574-2.stderr
index 02497029960..9479e365aee 100644
--- a/src/test/ui/issues/issue-72574-2.stderr
+++ b/src/test/ui/issues/issue-72574-2.stderr
@@ -25,16 +25,10 @@ LL | struct Binder(i32, i32, i32);
    | ----------------------------- tuple struct defined here
 ...
 LL |         Binder(_a, _x @ ..) => {}
-   |         ^^^^^^^^^^^^^^^^^^^ expected 3 fields, found 2
-   |
-help: use `_` to explicitly ignore each field
-   |
-LL |         Binder(_a, _x @ .., _) => {}
-   |                           ^^^
-help: use `..` to ignore the rest of the fields
-   |
-LL |         Binder(_a, _x @ .., ..) => {}
-   |                           ^^^^
+   |         ^^^^^^^^^^^^^^^^^^-
+   |         |                 |
+   |         |                 help: use `_` to explicitly ignore each field
+   |         expected 3 fields, found 2
 
 error: aborting due to 3 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 37839482b31..0bb5e726ccb 100644
--- a/src/test/ui/match/match-pattern-field-mismatch.stderr
+++ b/src/test/ui/match/match-pattern-field-mismatch.stderr
@@ -5,16 +5,10 @@ LL |         Rgb(usize, usize, usize),
    |         ------------------------ tuple variant defined here
 ...
 LL |           Color::Rgb(_, _) => { }
-   |           ^^^^^^^^^^^^^^^^ expected 3 fields, found 2
-   |
-help: use `_` to explicitly ignore each field
-   |
-LL |           Color::Rgb(_, _, _) => { }
-   |                          ^^^
-help: use `..` to ignore all fields
-   |
-LL |           Color::Rgb(..) => { }
-   |                      ^^
+   |           ^^^^^^^^^^^^^^^-
+   |           |              |
+   |           |              help: use `_` to explicitly ignore each field
+   |           expected 3 fields, found 2
 
 error: aborting due to previous error
 
diff --git a/src/test/ui/pattern/issue-74539.stderr b/src/test/ui/pattern/issue-74539.stderr
index 78249ed057f..49011d83e50 100644
--- a/src/test/ui/pattern/issue-74539.stderr
+++ b/src/test/ui/pattern/issue-74539.stderr
@@ -25,16 +25,10 @@ LL |     A(u8, u8),
    |     --------- tuple variant defined here
 ...
 LL |         E::A(x @ ..) => {
-   |         ^^^^^^^^^^^^ expected 2 fields, found 1
-   |
-help: use `_` to explicitly ignore each field
-   |
-LL |         E::A(x @ .., _) => {
-   |                    ^^^
-help: use `..` to ignore the rest of the fields
-   |
-LL |         E::A(x @ .., ..) => {
-   |                    ^^^^
+   |         ^^^^^^^^^^^-
+   |         |          |
+   |         |          help: use `_` to explicitly ignore each field
+   |         expected 2 fields, found 1
 
 error: aborting due to 3 previous errors
 
diff --git a/src/test/ui/pattern/pat-tuple-underfield.rs b/src/test/ui/pattern/pat-tuple-underfield.rs
index f306377e6e5..f86d6178014 100644
--- a/src/test/ui/pattern/pat-tuple-underfield.rs
+++ b/src/test/ui/pattern/pat-tuple-underfield.rs
@@ -8,13 +8,11 @@ fn main() {
         S(x) => {}
         //~^ 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 the rest of the fields
     }
     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() => {}
@@ -27,13 +25,11 @@ fn main() {
         E::S(x) => {}
         //~^ 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 the rest of the fields
     }
     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() => {}
diff --git a/src/test/ui/pattern/pat-tuple-underfield.stderr b/src/test/ui/pattern/pat-tuple-underfield.stderr
index d1aaeaeafa4..6e7afd8e57b 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:45:9
+  --> $DIR/pat-tuple-underfield.rs:41:9
    |
 LL |     S(i32, f32),
    |     ----------- `E::S` defined here
@@ -14,37 +14,25 @@ LL | struct S(i32, f32);
    | ------------------- tuple struct defined here
 ...
 LL |         S(x) => {}
-   |         ^^^^ expected 2 fields, found 1
-   |
-help: use `_` to explicitly ignore each field
-   |
-LL |         S(x, _) => {}
-   |            ^^^
-help: use `..` to ignore the rest of the fields
-   |
-LL |         S(x, ..) => {}
-   |            ^^^^
+   |         ^^^-
+   |         |  |
+   |         |  help: use `_` to explicitly ignore each field
+   |         expected 2 fields, found 1
 
 error[E0023]: this pattern has 1 field, but the corresponding tuple struct has 2 fields
-  --> $DIR/pat-tuple-underfield.rs:14:9
+  --> $DIR/pat-tuple-underfield.rs:13:9
    |
 LL | struct S(i32, f32);
    | ------------------- tuple struct defined here
 ...
 LL |         S(_) => {}
-   |         ^^^^ expected 2 fields, found 1
-   |
-help: use `_` to explicitly ignore each field
-   |
-LL |         S(_, _) => {}
-   |            ^^^
-help: use `..` to ignore all fields
-   |
-LL |         S(..) => {}
-   |           ^^
+   |         ^^^-
+   |         |  |
+   |         |  help: use `_` to explicitly ignore each field
+   |         expected 2 fields, found 1
 
 error[E0023]: this pattern has 0 fields, but the corresponding tuple struct has 2 fields
-  --> $DIR/pat-tuple-underfield.rs:20:9
+  --> $DIR/pat-tuple-underfield.rs:18:9
    |
 LL | struct S(i32, f32);
    | ------------------- tuple struct defined here
@@ -62,43 +50,31 @@ LL |         S(..) => {}
    |           ^^
 
 error[E0023]: this pattern has 1 field, but the corresponding tuple variant has 2 fields
-  --> $DIR/pat-tuple-underfield.rs:27:9
+  --> $DIR/pat-tuple-underfield.rs:25:9
    |
 LL |     S(i32, f32),
    |     ----------- tuple variant defined here
 ...
 LL |         E::S(x) => {}
-   |         ^^^^^^^ expected 2 fields, found 1
-   |
-help: use `_` to explicitly ignore each field
-   |
-LL |         E::S(x, _) => {}
-   |               ^^^
-help: use `..` to ignore the rest of the fields
-   |
-LL |         E::S(x, ..) => {}
-   |               ^^^^
+   |         ^^^^^^-
+   |         |     |
+   |         |     help: use `_` to explicitly ignore each field
+   |         expected 2 fields, found 1
 
 error[E0023]: this pattern has 1 field, but the corresponding tuple variant has 2 fields
-  --> $DIR/pat-tuple-underfield.rs:33:9
+  --> $DIR/pat-tuple-underfield.rs:30:9
    |
 LL |     S(i32, f32),
    |     ----------- tuple variant defined here
 ...
 LL |         E::S(_) => {}
-   |         ^^^^^^^ expected 2 fields, found 1
-   |
-help: use `_` to explicitly ignore each field
-   |
-LL |         E::S(_, _) => {}
-   |               ^^^
-help: use `..` to ignore all fields
-   |
-LL |         E::S(..) => {}
-   |              ^^
+   |         ^^^^^^-
+   |         |     |
+   |         |     help: use `_` to explicitly ignore each field
+   |         expected 2 fields, found 1
 
 error[E0023]: this pattern has 0 fields, but the corresponding tuple variant has 2 fields
-  --> $DIR/pat-tuple-underfield.rs:39:9
+  --> $DIR/pat-tuple-underfield.rs:35:9
    |
 LL |     S(i32, f32),
    |     ----------- tuple variant defined here