From 16692ab66a6e2c62b416f606f144d60711c14414 Mon Sep 17 00:00:00 2001 From: Camelid Date: Sun, 13 Dec 2020 14:13:52 -0800 Subject: Suggest `_` and `..` if a pattern has too few fields For example, this code: struct S(i32, f32); let S(x) = S(0, 1.0); will make the compiler suggest either: let S(x, _) = S(0, 1.0); or: let S(x, ..) = S(0, 1.0); --- src/test/ui/error-codes/E0023.stderr | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'src/test/ui/error-codes') diff --git a/src/test/ui/error-codes/E0023.stderr b/src/test/ui/error-codes/E0023.stderr index a3610099294..1d32eab15d3 100644 --- a/src/test/ui/error-codes/E0023.stderr +++ b/src/test/ui/error-codes/E0023.stderr @@ -6,6 +6,15 @@ LL | Apple(String, String), ... LL | Fruit::Apple(a) => {}, | ^^^^^^^^^^^^^^^ expected 2 fields, found 1 + | +help: use `_` to explicitly ignore each field + | +LL | Fruit::Apple(a, _) => {}, + | ^^^ +help: use `..` to ignore all unmentioned fields + | +LL | Fruit::Apple(a, ..) => {}, + | ^^^^ error[E0023]: this pattern has 3 fields, but the corresponding tuple variant has 2 fields --> $DIR/E0023.rs:12:9 -- cgit 1.4.1-3-g733a5 From a5e8e6ec2df58bd50963af57bbd08d0526f119db Mon Sep 17 00:00:00 2001 From: Camelid Date: Fri, 18 Dec 2020 19:56:14 -0800 Subject: Pluralize 'parenthesis' correctly It's 'parentheses', not 'parenthesis', when you have more than one. --- compiler/rustc_typeck/src/check/pat.rs | 10 +++++----- src/test/ui/error-codes/E0023.stderr | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) (limited to 'src/test/ui/error-codes') diff --git a/compiler/rustc_typeck/src/check/pat.rs b/compiler/rustc_typeck/src/check/pat.rs index 474aed39eb2..a7670624f30 100644 --- a/compiler/rustc_typeck/src/check/pat.rs +++ b/compiler/rustc_typeck/src/check/pat.rs @@ -1002,7 +1002,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { // More generally, the expected type wants a tuple variant with one field of an // N-arity-tuple, e.g., `V_i((p_0, .., p_N))`. Meanwhile, the user supplied a pattern // with the subpatterns directly in the tuple variant pattern, e.g., `V_i(p_0, .., p_N)`. - let missing_parenthesis = match (&expected.kind(), fields, had_err) { + let missing_parentheses = match (&expected.kind(), fields, had_err) { // #67037: only do this if we could successfully type-check the expected type against // the tuple struct pattern. Otherwise the substs could get out of range on e.g., // `let P() = U;` where `P != U` with `struct P(T);`. @@ -1015,13 +1015,13 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { } _ => false, }; - if missing_parenthesis { + if missing_parentheses { let (left, right) = match subpats { // This is the zero case; we aim to get the "hi" part of the `QPath`'s // span as the "lo" and then the "hi" part of the pattern's span as the "hi". // This looks like: // - // help: missing parenthesis + // help: missing parentheses // | // L | let A(()) = A(()); // | ^ ^ @@ -1030,14 +1030,14 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { // last sub-pattern. In the case of `A(x)` the first and last may coincide. // This looks like: // - // help: missing parenthesis + // help: missing parentheses // | // L | let A((x, y)) = A((1, 2)); // | ^ ^ [first, ..] => (first.span.shrink_to_lo(), subpats.last().unwrap().span), }; err.multipart_suggestion( - "missing parenthesis", + "missing parentheses", vec![(left, "(".to_string()), (right.shrink_to_hi(), ")".to_string())], Applicability::MachineApplicable, ); diff --git a/src/test/ui/error-codes/E0023.stderr b/src/test/ui/error-codes/E0023.stderr index 1d32eab15d3..965cf28c79f 100644 --- a/src/test/ui/error-codes/E0023.stderr +++ b/src/test/ui/error-codes/E0023.stderr @@ -43,7 +43,7 @@ LL | Orange((String, String)), LL | Fruit::Orange(a, b) => {}, | ^^^^^^^^^^^^^^^^^^^ expected 1 field, found 2 | -help: missing parenthesis +help: missing parentheses | LL | Fruit::Orange((a, b)) => {}, | ^ ^ @@ -57,7 +57,7 @@ LL | Banana(()), LL | Fruit::Banana() => {}, | ^^^^^^^^^^^^^^^ expected 1 field, found 0 | -help: missing parenthesis +help: missing parentheses | LL | Fruit::Banana(()) => {}, | ^ ^ -- cgit 1.4.1-3-g733a5 From fe82cc38a0b3e39b9425090e2107c0ba15760491 Mon Sep 17 00:00:00 2001 From: Camelid Date: Fri, 18 Dec 2020 20:17:09 -0800 Subject: Specialize `..` help message for all fields vs. the rest --- compiler/rustc_typeck/src/check/pat.rs | 4 ++-- .../tuple_struct_destructure_fail.stderr | 4 ++-- src/test/ui/error-codes/E0023.stderr | 2 +- .../issue-67037-pat-tup-scrut-ty-diff-less-fields.stderr | 2 +- src/test/ui/issues/issue-72574-2.stderr | 2 +- src/test/ui/match/match-pattern-field-mismatch.stderr | 2 +- src/test/ui/pattern/issue-74539.stderr | 2 +- src/test/ui/pattern/pat-tuple-underfield.rs | 12 ++++++------ src/test/ui/pattern/pat-tuple-underfield.stderr | 12 ++++++------ 9 files changed, 21 insertions(+), 21 deletions(-) (limited to 'src/test/ui/error-codes') diff --git a/compiler/rustc_typeck/src/check/pat.rs b/compiler/rustc_typeck/src/check/pat.rs index a7670624f30..43a69fe1874 100644 --- a/compiler/rustc_typeck/src/check/pat.rs +++ b/compiler/rustc_typeck/src/check/pat.rs @@ -1071,14 +1071,14 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { if subpats.is_empty() || all_wildcards { err.span_suggestion( all_fields_span, - "use `..` to ignore all unmentioned fields", + "use `..` to ignore all fields", String::from(".."), Applicability::MaybeIncorrect, ); } else { err.span_suggestion( after_fields_span, - "use `..` to ignore all unmentioned fields", + "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 dd1fbbbd3bb..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,7 +36,7 @@ help: use `_` to explicitly ignore each field | LL | TupleStruct(_, _) = TupleStruct(1, 2); | ^^^ -help: use `..` to ignore all unmentioned fields +help: use `..` to ignore all fields | LL | TupleStruct(..) = TupleStruct(1, 2); | ^^ @@ -63,7 +63,7 @@ help: use `_` to explicitly ignore each field | LL | Enum::SingleVariant(_, _) = Enum::SingleVariant(1, 2); | ^^^ -help: use `..` to ignore all unmentioned fields +help: use `..` to ignore all fields | LL | Enum::SingleVariant(..) = Enum::SingleVariant(1, 2); | ^^ diff --git a/src/test/ui/error-codes/E0023.stderr b/src/test/ui/error-codes/E0023.stderr index 965cf28c79f..aaaada518d3 100644 --- a/src/test/ui/error-codes/E0023.stderr +++ b/src/test/ui/error-codes/E0023.stderr @@ -11,7 +11,7 @@ help: use `_` to explicitly ignore each field | LL | Fruit::Apple(a, _) => {}, | ^^^ -help: use `..` to ignore all unmentioned fields +help: use `..` to ignore the rest of the fields | LL | Fruit::Apple(a, ..) => {}, | ^^^^ 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 38177d15158..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,7 +22,7 @@ help: use `_` to explicitly ignore each field | LL | let P(_) = U {}; | ^ -help: use `..` to ignore all unmentioned fields +help: use `..` to ignore all fields | LL | let P(..) = U {}; | ^^ diff --git a/src/test/ui/issues/issue-72574-2.stderr b/src/test/ui/issues/issue-72574-2.stderr index 8edc6ca8f0e..02497029960 100644 --- a/src/test/ui/issues/issue-72574-2.stderr +++ b/src/test/ui/issues/issue-72574-2.stderr @@ -31,7 +31,7 @@ help: use `_` to explicitly ignore each field | LL | Binder(_a, _x @ .., _) => {} | ^^^ -help: use `..` to ignore all unmentioned fields +help: use `..` to ignore the rest of the fields | LL | Binder(_a, _x @ .., ..) => {} | ^^^^ diff --git a/src/test/ui/match/match-pattern-field-mismatch.stderr b/src/test/ui/match/match-pattern-field-mismatch.stderr index 1ee45ca1b1e..37839482b31 100644 --- a/src/test/ui/match/match-pattern-field-mismatch.stderr +++ b/src/test/ui/match/match-pattern-field-mismatch.stderr @@ -11,7 +11,7 @@ help: use `_` to explicitly ignore each field | LL | Color::Rgb(_, _, _) => { } | ^^^ -help: use `..` to ignore all unmentioned fields +help: use `..` to ignore all fields | LL | Color::Rgb(..) => { } | ^^ diff --git a/src/test/ui/pattern/issue-74539.stderr b/src/test/ui/pattern/issue-74539.stderr index 7a73d39dbc0..78249ed057f 100644 --- a/src/test/ui/pattern/issue-74539.stderr +++ b/src/test/ui/pattern/issue-74539.stderr @@ -31,7 +31,7 @@ help: use `_` to explicitly ignore each field | LL | E::A(x @ .., _) => { | ^^^ -help: use `..` to ignore all unmentioned fields +help: use `..` to ignore the rest of the fields | LL | E::A(x @ .., ..) => { | ^^^^ diff --git a/src/test/ui/pattern/pat-tuple-underfield.rs b/src/test/ui/pattern/pat-tuple-underfield.rs index 246dd0b37b6..f306377e6e5 100644 --- a/src/test/ui/pattern/pat-tuple-underfield.rs +++ b/src/test/ui/pattern/pat-tuple-underfield.rs @@ -8,38 +8,38 @@ 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 all unmentioned fields + //~| 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 unmentioned fields + //~| 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 unmentioned fields + //~| 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 - //~| HELP use `..` to ignore all unmentioned fields + //~| 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 unmentioned fields + //~| 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 unmentioned fields + //~| 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 b7a54026639..d1aaeaeafa4 100644 --- a/src/test/ui/pattern/pat-tuple-underfield.stderr +++ b/src/test/ui/pattern/pat-tuple-underfield.stderr @@ -20,7 +20,7 @@ help: use `_` to explicitly ignore each field | LL | S(x, _) => {} | ^^^ -help: use `..` to ignore all unmentioned fields +help: use `..` to ignore the rest of the fields | LL | S(x, ..) => {} | ^^^^ @@ -38,7 +38,7 @@ help: use `_` to explicitly ignore each field | LL | S(_, _) => {} | ^^^ -help: use `..` to ignore all unmentioned fields +help: use `..` to ignore all fields | LL | S(..) => {} | ^^ @@ -56,7 +56,7 @@ help: use `_` to explicitly ignore each field | LL | S(_, _) => {} | ^^^^ -help: use `..` to ignore all unmentioned fields +help: use `..` to ignore all fields | LL | S(..) => {} | ^^ @@ -74,7 +74,7 @@ help: use `_` to explicitly ignore each field | LL | E::S(x, _) => {} | ^^^ -help: use `..` to ignore all unmentioned fields +help: use `..` to ignore the rest of the fields | LL | E::S(x, ..) => {} | ^^^^ @@ -92,7 +92,7 @@ help: use `_` to explicitly ignore each field | LL | E::S(_, _) => {} | ^^^ -help: use `..` to ignore all unmentioned fields +help: use `..` to ignore all fields | LL | E::S(..) => {} | ^^ @@ -110,7 +110,7 @@ help: use `_` to explicitly ignore each field | LL | E::S(_, _) => {} | ^^^^ -help: use `..` to ignore all unmentioned fields +help: use `..` to ignore all fields | LL | E::S(..) => {} | ^^ -- cgit 1.4.1-3-g733a5 From 9959d6deedbf39d58fac06949596073d9c0dbb23 Mon Sep 17 00:00:00 2001 From: Camelid Date: Sun, 20 Dec 2020 14:43:07 -0800 Subject: Only suggest `..` if more than one field is missing --- compiler/rustc_typeck/src/check/pat.rs | 33 ++++++----- .../tuple_struct_destructure_fail.stderr | 28 +++------ src/test/ui/error-codes/E0023.stderr | 14 ++--- ...-67037-pat-tup-scrut-ty-diff-less-fields.stderr | 14 ++--- src/test/ui/issues/issue-72574-2.stderr | 14 ++--- .../ui/match/match-pattern-field-mismatch.stderr | 14 ++--- src/test/ui/pattern/issue-74539.stderr | 14 ++--- src/test/ui/pattern/pat-tuple-underfield.rs | 4 -- src/test/ui/pattern/pat-tuple-underfield.stderr | 68 +++++++--------------- 9 files changed, 68 insertions(+), 135 deletions(-) (limited to 'src/test/ui/error-codes') 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); | ------------------------------- 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); // 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 -- cgit 1.4.1-3-g733a5 From d7307a71f5e1893f7bd69ff160ce38dc97b5d195 Mon Sep 17 00:00:00 2001 From: Camelid Date: Tue, 12 Jan 2021 19:06:20 -0800 Subject: Always show suggestions in their own subwindows --- compiler/rustc_typeck/src/check/pat.rs | 6 ++-- .../tuple_struct_destructure_fail.stderr | 20 ++++++----- src/test/ui/error-codes/E0023.stderr | 10 +++--- ...-67037-pat-tup-scrut-ty-diff-less-fields.stderr | 10 +++--- src/test/ui/issues/issue-72574-2.stderr | 10 +++--- .../ui/match/match-pattern-field-mismatch.stderr | 10 +++--- src/test/ui/pattern/issue-74539.stderr | 10 +++--- src/test/ui/pattern/pat-tuple-underfield.stderr | 40 +++++++++++++--------- 8 files changed, 69 insertions(+), 47 deletions(-) (limited to 'src/test/ui/error-codes') diff --git a/compiler/rustc_typeck/src/check/pat.rs b/compiler/rustc_typeck/src/check/pat.rs index a863fc95e0e..e176389f0e2 100644 --- a/compiler/rustc_typeck/src/check/pat.rs +++ b/compiler/rustc_typeck/src/check/pat.rs @@ -1061,7 +1061,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { wildcard_sugg = String::from(", ") + &wildcard_sugg; } - err.span_suggestion_short( + err.span_suggestion_verbose( after_fields_span, "use `_` to explicitly ignore each field", wildcard_sugg, @@ -1071,14 +1071,14 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { // 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( + err.span_suggestion_verbose( all_fields_span, "use `..` to ignore all fields", String::from(".."), Applicability::MaybeIncorrect, ); } else { - err.span_suggestion_short( + err.span_suggestion_verbose( after_fields_span, "use `..` to ignore the rest of the fields", String::from(", .."), 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 42859406e17..8c20bb4fb83 100644 --- a/src/test/ui/destructuring-assignment/tuple_struct_destructure_fail.stderr +++ b/src/test/ui/destructuring-assignment/tuple_struct_destructure_fail.stderr @@ -30,10 +30,12 @@ LL | struct TupleStruct(S, T); | ------------------------------- tuple struct defined here ... LL | TupleStruct(_) = TupleStruct(1, 2); - | ^^^^^^^^^^^^^- - | | | - | | help: use `_` to explicitly ignore each field - | expected 2 fields, found 1 + | ^^^^^^^^^^^^^^ expected 2 fields, found 1 + | +help: use `_` to explicitly ignore each field + | +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 @@ -51,10 +53,12 @@ LL | SingleVariant(S, T) | ------------------- tuple variant defined here ... LL | Enum::SingleVariant(_) = Enum::SingleVariant(1, 2); - | ^^^^^^^^^^^^^^^^^^^^^- - | | | - | | help: use `_` to explicitly ignore each field - | expected 2 fields, found 1 + | ^^^^^^^^^^^^^^^^^^^^^^ expected 2 fields, found 1 + | +help: use `_` to explicitly ignore each field + | +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/error-codes/E0023.stderr b/src/test/ui/error-codes/E0023.stderr index 0c6f496cf43..832eba69722 100644 --- a/src/test/ui/error-codes/E0023.stderr +++ b/src/test/ui/error-codes/E0023.stderr @@ -5,10 +5,12 @@ LL | Apple(String, String), | --------------------- tuple variant defined here ... LL | Fruit::Apple(a) => {}, - | ^^^^^^^^^^^^^^- - | | | - | | help: use `_` to explicitly ignore each field - | expected 2 fields, found 1 + | ^^^^^^^^^^^^^^^ expected 2 fields, found 1 + | +help: use `_` to explicitly ignore each field + | +LL | Fruit::Apple(a, _) => {}, + | ^^^ 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 86be8e7db4e..46ffac48c1b 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,10 +16,12 @@ LL | struct P(T); // 1 type parameter wanted | --------------- tuple struct defined here ... LL | let P() = U {}; - | ^^- - | | | - | | help: use `_` to explicitly ignore each field - | expected 1 field, found 0 + | ^^^ expected 1 field, found 0 + | +help: use `_` to explicitly ignore each field + | +LL | let P(_) = U {}; + | ^ 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 9479e365aee..a1e8ec1677d 100644 --- a/src/test/ui/issues/issue-72574-2.stderr +++ b/src/test/ui/issues/issue-72574-2.stderr @@ -25,10 +25,12 @@ LL | struct Binder(i32, i32, i32); | ----------------------------- tuple struct defined here ... LL | Binder(_a, _x @ ..) => {} - | ^^^^^^^^^^^^^^^^^^- - | | | - | | help: use `_` to explicitly ignore each field - | expected 3 fields, found 2 + | ^^^^^^^^^^^^^^^^^^^ expected 3 fields, found 2 + | +help: use `_` to explicitly ignore each field + | +LL | Binder(_a, _x @ .., _) => {} + | ^^^ 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 0bb5e726ccb..04f8cab900e 100644 --- a/src/test/ui/match/match-pattern-field-mismatch.stderr +++ b/src/test/ui/match/match-pattern-field-mismatch.stderr @@ -5,10 +5,12 @@ LL | Rgb(usize, usize, usize), | ------------------------ tuple variant defined here ... LL | Color::Rgb(_, _) => { } - | ^^^^^^^^^^^^^^^- - | | | - | | help: use `_` to explicitly ignore each field - | expected 3 fields, found 2 + | ^^^^^^^^^^^^^^^^ expected 3 fields, found 2 + | +help: use `_` to explicitly ignore each field + | +LL | Color::Rgb(_, _, _) => { } + | ^^^ 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 49011d83e50..f7644c19ea0 100644 --- a/src/test/ui/pattern/issue-74539.stderr +++ b/src/test/ui/pattern/issue-74539.stderr @@ -25,10 +25,12 @@ LL | A(u8, u8), | --------- tuple variant defined here ... LL | E::A(x @ ..) => { - | ^^^^^^^^^^^- - | | | - | | help: use `_` to explicitly ignore each field - | expected 2 fields, found 1 + | ^^^^^^^^^^^^ expected 2 fields, found 1 + | +help: use `_` to explicitly ignore each field + | +LL | E::A(x @ .., _) => { + | ^^^ error: aborting due to 3 previous errors diff --git a/src/test/ui/pattern/pat-tuple-underfield.stderr b/src/test/ui/pattern/pat-tuple-underfield.stderr index df6b216272e..cdf7cfe3005 100644 --- a/src/test/ui/pattern/pat-tuple-underfield.stderr +++ b/src/test/ui/pattern/pat-tuple-underfield.stderr @@ -14,10 +14,12 @@ LL | struct S(i32, f32); | ------------------- tuple struct defined here ... LL | S(x) => {} - | ^^^- - | | | - | | help: use `_` to explicitly ignore each field - | expected 2 fields, found 1 + | ^^^^ expected 2 fields, found 1 + | +help: use `_` to explicitly ignore each field + | +LL | S(x, _) => {} + | ^^^ error[E0023]: this pattern has 1 field, but the corresponding tuple struct has 2 fields --> $DIR/pat-tuple-underfield.rs:14:9 @@ -26,10 +28,12 @@ LL | struct S(i32, f32); | ------------------- tuple struct defined here ... LL | S(_) => {} - | ^^^- - | | | - | | help: use `_` to explicitly ignore each field - | expected 2 fields, found 1 + | ^^^^ expected 2 fields, found 1 + | +help: use `_` to explicitly ignore each field + | +LL | S(_, _) => {} + | ^^^ error[E0023]: this pattern has 0 fields, but the corresponding tuple struct has 2 fields --> $DIR/pat-tuple-underfield.rs:19:9 @@ -56,10 +60,12 @@ LL | S(i32, f32), | ----------- tuple variant defined here ... LL | E::S(x) => {} - | ^^^^^^- - | | | - | | help: use `_` to explicitly ignore each field - | expected 2 fields, found 1 + | ^^^^^^^ expected 2 fields, found 1 + | +help: use `_` to explicitly ignore each field + | +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 @@ -68,10 +74,12 @@ LL | S(i32, f32), | ----------- tuple variant defined here ... LL | E::S(_) => {} - | ^^^^^^- - | | | - | | help: use `_` to explicitly ignore each field - | expected 2 fields, found 1 + | ^^^^^^^ expected 2 fields, found 1 + | +help: use `_` to explicitly ignore each field + | +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 -- cgit 1.4.1-3-g733a5