Fix suggestion span and move suggestions into new subwindow.

This commit is contained in:
Reese Williams 2021-02-20 15:33:08 -05:00
parent 7879099ad3
commit d8540ae5a9
6 changed files with 40 additions and 22 deletions

View File

@ -1256,8 +1256,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
"tuple variant `{}` written as struct variant", "tuple variant `{}` written as struct variant",
path path
); );
err.span_suggestion( err.span_suggestion_verbose(
qpath.span().shrink_to_hi().until(pat.span), qpath.span().shrink_to_hi().to(pat.span.shrink_to_hi()),
"use the tuple variant pattern syntax instead", "use the tuple variant pattern syntax instead",
format!("({})", self.get_suggested_tuple_struct_pattern(fields, variant)), format!("({})", self.get_suggested_tuple_struct_pattern(fields, variant)),
Applicability::MaybeIncorrect, Applicability::MaybeIncorrect,
@ -1416,8 +1416,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
Applicability::MaybeIncorrect, Applicability::MaybeIncorrect,
) )
}; };
err.span_suggestion( err.span_suggestion_verbose(
qpath.span().shrink_to_hi().until(pat.span), qpath.span().shrink_to_hi().to(pat.span.shrink_to_hi()),
"use the tuple variant pattern syntax instead", "use the tuple variant pattern syntax instead",
format!("({})", sugg), format!("({})", sugg),
appl, appl,

View File

@ -2,9 +2,12 @@ error[E0769]: tuple variant `MyOption::MySome` written as struct variant
--> $DIR/issue-17800.rs:8:9 --> $DIR/issue-17800.rs:8:9
| |
LL | MyOption::MySome { x: 42 } => (), LL | MyOption::MySome { x: 42 } => (),
| ----------------^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^^^^^^^
| | |
| help: use the tuple variant pattern syntax instead: `(42)` help: use the tuple variant pattern syntax instead
|
LL | MyOption::MySome(42) => (),
| ^^^^
error: aborting due to previous error error: aborting due to previous error

View File

@ -2,9 +2,12 @@ error[E0769]: tuple variant `S` written as struct variant
--> $DIR/missing-fields-in-struct-pattern.rs:4:12 --> $DIR/missing-fields-in-struct-pattern.rs:4:12
| |
LL | if let S { a, b, c, d } = S(1, 2, 3, 4) { LL | if let S { a, b, c, d } = S(1, 2, 3, 4) {
| -^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^
| | |
| help: use the tuple variant pattern syntax instead: `(a, b, c, d)` help: use the tuple variant pattern syntax instead
|
LL | if let S(a, b, c, d) = S(1, 2, 3, 4) {
| ^^^^^^^^^^^^
error: aborting due to previous error error: aborting due to previous error

View File

@ -22,9 +22,12 @@ error[E0769]: tuple variant `Enum::Bar` written as struct variant
--> $DIR/recover-from-bad-variant.rs:12:9 --> $DIR/recover-from-bad-variant.rs:12:9
| |
LL | Enum::Bar { a, b } => {} LL | Enum::Bar { a, b } => {}
| ---------^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^
| | |
| help: use the tuple variant pattern syntax instead: `(a, b)` help: use the tuple variant pattern syntax instead
|
LL | Enum::Bar(a, b) => {}
| ^^^^^^
error: aborting due to 3 previous errors error: aborting due to 3 previous errors

View File

@ -2,17 +2,23 @@ error[E0769]: tuple variant `E::S` written as struct variant
--> $DIR/struct-tuple-field-names.rs:8:9 --> $DIR/struct-tuple-field-names.rs:8:9
| |
LL | E::S { 0, 1 } => {} LL | E::S { 0, 1 } => {}
| ----^^^^^^^^^ | ^^^^^^^^^^^^^
| | |
| help: use the tuple variant pattern syntax instead: `(_, _)` help: use the tuple variant pattern syntax instead
|
LL | E::S(_, _) => {}
| ^^^^^^
error[E0769]: tuple variant `S` written as struct variant error[E0769]: tuple variant `S` written as struct variant
--> $DIR/struct-tuple-field-names.rs:13:9 --> $DIR/struct-tuple-field-names.rs:13:9
| |
LL | S { } => {} LL | S { } => {}
| -^^^^ | ^^^^^
| | |
| help: use the tuple variant pattern syntax instead: `(_, _)` help: use the tuple variant pattern syntax instead
|
LL | S(_, _) => {}
| ^^^^^^
error: aborting due to 2 previous errors error: aborting due to 2 previous errors

View File

@ -2,9 +2,12 @@ error[E0769]: tuple variant `X::Y` written as struct variant
--> $DIR/issue-41314.rs:7:9 --> $DIR/issue-41314.rs:7:9
| |
LL | X::Y { number } => {} LL | X::Y { number } => {}
| ----^^^^^^^^^^^ | ^^^^^^^^^^^^^^^
| | |
| help: use the tuple variant pattern syntax instead: `(number)` help: use the tuple variant pattern syntax instead
|
LL | X::Y(number) => {}
| ^^^^^^^^
error: aborting due to previous error error: aborting due to previous error