diff --git a/compiler/rustc_typeck/src/check/pat.rs b/compiler/rustc_typeck/src/check/pat.rs index e176389f0e279a2276b3aa5fe3df98e3e0a78b79..ecc6e8599ad01d2ccd7e8084fe69b9477f658441 100644 --- a/compiler/rustc_typeck/src/check/pat.rs +++ b/compiler/rustc_typeck/src/check/pat.rs @@ -1068,8 +1068,9 @@ fn e0023( 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 8c20bb4fb833cce4783f59b6f66a99b7a1231ad7..c270593cac741883fcc242d2961983adb4849b88 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 46ffac48c1bada9bf04152f338ed0ba96b6fd13d..9bdbf0bf9f40dfced6ed3e35aea1a6591fb913c0 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 04f8cab900e1b08d4c75c7b0a636aa9aaa7a62c7..37839482b31a2ef3aabae9fb356661db531c0241 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 50f8a855d3639321961ea86c2909396dfced3b84..ed852a47bb4ee1752ea520fe2c24be41c796b7a8 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 cdf7cfe30054ddf85c031d50534c1110668a1170..76323d9a7bf56cba5ce792cbb2929dec11830858 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