Always show suggestions in their own subwindows

This commit is contained in:
Camelid 2021-01-12 19:06:20 -08:00
parent 1bce775769
commit d7307a71f5
8 changed files with 69 additions and 47 deletions

View File

@ -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(", .."),

View File

@ -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
@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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