Skip to content

Commit

Permalink
Always show suggestions in their own subwindows
Browse files Browse the repository at this point in the history
  • Loading branch information
camelid committed Jan 13, 2021
1 parent 1bce775 commit d7307a7
Show file tree
Hide file tree
Showing 8 changed files with 69 additions and 47 deletions.
6 changes: 3 additions & 3 deletions compiler/rustc_typeck/src/check/pat.rs
Expand Up @@ -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,
Expand All @@ -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(", .."),
Expand Down
Expand Up @@ -30,10 +30,12 @@ LL | struct TupleStruct<S, T>(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
Expand All @@ -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
Expand Down
10 changes: 6 additions & 4 deletions src/test/ui/error-codes/E0023.stderr
Expand Up @@ -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
Expand Down
Expand Up @@ -16,10 +16,12 @@ LL | struct P<T>(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

Expand Down
10 changes: 6 additions & 4 deletions src/test/ui/issues/issue-72574-2.stderr
Expand Up @@ -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

Expand Down
10 changes: 6 additions & 4 deletions src/test/ui/match/match-pattern-field-mismatch.stderr
Expand Up @@ -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

Expand Down
10 changes: 6 additions & 4 deletions src/test/ui/pattern/issue-74539.stderr
Expand Up @@ -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

Expand Down
40 changes: 24 additions & 16 deletions src/test/ui/pattern/pat-tuple-underfield.stderr
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down

0 comments on commit d7307a7

Please sign in to comment.