Skip to content

Commit d8540ae

Browse files
committed
Fix suggestion span and move suggestions into new subwindow.
1 parent 7879099 commit d8540ae

File tree

6 files changed

+40
-22
lines changed

6 files changed

+40
-22
lines changed

compiler/rustc_typeck/src/check/pat.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1256,8 +1256,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
12561256
"tuple variant `{}` written as struct variant",
12571257
path
12581258
);
1259-
err.span_suggestion(
1260-
qpath.span().shrink_to_hi().until(pat.span),
1259+
err.span_suggestion_verbose(
1260+
qpath.span().shrink_to_hi().to(pat.span.shrink_to_hi()),
12611261
"use the tuple variant pattern syntax instead",
12621262
format!("({})", self.get_suggested_tuple_struct_pattern(fields, variant)),
12631263
Applicability::MaybeIncorrect,
@@ -1416,8 +1416,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
14161416
Applicability::MaybeIncorrect,
14171417
)
14181418
};
1419-
err.span_suggestion(
1420-
qpath.span().shrink_to_hi().until(pat.span),
1419+
err.span_suggestion_verbose(
1420+
qpath.span().shrink_to_hi().to(pat.span.shrink_to_hi()),
14211421
"use the tuple variant pattern syntax instead",
14221422
format!("({})", sugg),
14231423
appl,

src/test/ui/issues/issue-17800.stderr

+6-3
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@ error[E0769]: tuple variant `MyOption::MySome` written as struct variant
22
--> $DIR/issue-17800.rs:8:9
33
|
44
LL | MyOption::MySome { x: 42 } => (),
5-
| ----------------^^^^^^^^^^
6-
| |
7-
| help: use the tuple variant pattern syntax instead: `(42)`
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
6+
|
7+
help: use the tuple variant pattern syntax instead
8+
|
9+
LL | MyOption::MySome(42) => (),
10+
| ^^^^
811

912
error: aborting due to previous error
1013

src/test/ui/missing/missing-fields-in-struct-pattern.stderr

+6-3
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@ error[E0769]: tuple variant `S` written as struct variant
22
--> $DIR/missing-fields-in-struct-pattern.rs:4:12
33
|
44
LL | if let S { a, b, c, d } = S(1, 2, 3, 4) {
5-
| -^^^^^^^^^^^^^^^
6-
| |
7-
| help: use the tuple variant pattern syntax instead: `(a, b, c, d)`
5+
| ^^^^^^^^^^^^^^^^
6+
|
7+
help: use the tuple variant pattern syntax instead
8+
|
9+
LL | if let S(a, b, c, d) = S(1, 2, 3, 4) {
10+
| ^^^^^^^^^^^^
811

912
error: aborting due to previous error
1013

src/test/ui/parser/recover-from-bad-variant.stderr

+6-3
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,12 @@ error[E0769]: tuple variant `Enum::Bar` written as struct variant
2222
--> $DIR/recover-from-bad-variant.rs:12:9
2323
|
2424
LL | Enum::Bar { a, b } => {}
25-
| ---------^^^^^^^^^
26-
| |
27-
| help: use the tuple variant pattern syntax instead: `(a, b)`
25+
| ^^^^^^^^^^^^^^^^^^
26+
|
27+
help: use the tuple variant pattern syntax instead
28+
|
29+
LL | Enum::Bar(a, b) => {}
30+
| ^^^^^^
2831

2932
error: aborting due to 3 previous errors
3033

src/test/ui/structs/struct-tuple-field-names.stderr

+12-6
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,23 @@ error[E0769]: tuple variant `E::S` written as struct variant
22
--> $DIR/struct-tuple-field-names.rs:8:9
33
|
44
LL | E::S { 0, 1 } => {}
5-
| ----^^^^^^^^^
6-
| |
7-
| help: use the tuple variant pattern syntax instead: `(_, _)`
5+
| ^^^^^^^^^^^^^
6+
|
7+
help: use the tuple variant pattern syntax instead
8+
|
9+
LL | E::S(_, _) => {}
10+
| ^^^^^^
811

912
error[E0769]: tuple variant `S` written as struct variant
1013
--> $DIR/struct-tuple-field-names.rs:13:9
1114
|
1215
LL | S { } => {}
13-
| -^^^^
14-
| |
15-
| help: use the tuple variant pattern syntax instead: `(_, _)`
16+
| ^^^^^
17+
|
18+
help: use the tuple variant pattern syntax instead
19+
|
20+
LL | S(_, _) => {}
21+
| ^^^^^^
1622

1723
error: aborting due to 2 previous errors
1824

src/test/ui/type/type-check/issue-41314.stderr

+6-3
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@ error[E0769]: tuple variant `X::Y` written as struct variant
22
--> $DIR/issue-41314.rs:7:9
33
|
44
LL | X::Y { number } => {}
5-
| ----^^^^^^^^^^^
6-
| |
7-
| help: use the tuple variant pattern syntax instead: `(number)`
5+
| ^^^^^^^^^^^^^^^
6+
|
7+
help: use the tuple variant pattern syntax instead
8+
|
9+
LL | X::Y(number) => {}
10+
| ^^^^^^^^
811

912
error: aborting due to previous error
1013

0 commit comments

Comments
 (0)