Skip to content

Commit 7879099

Browse files
committed
Clarify error message and remove pretty printing in help suggestions.
1 parent 8a83c8f commit 7879099

File tree

7 files changed

+25
-17
lines changed

7 files changed

+25
-17
lines changed

compiler/rustc_typeck/src/check/pat.rs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1253,17 +1253,13 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
12531253
self.tcx.sess,
12541254
pat.span,
12551255
E0769,
1256-
"tuple variant `{}` uses a bare index in a struct pattern",
1256+
"tuple variant `{}` written as struct variant",
12571257
path
12581258
);
12591259
err.span_suggestion(
1260-
pat.span,
1260+
qpath.span().shrink_to_hi().until(pat.span),
12611261
"use the tuple variant pattern syntax instead",
1262-
format!(
1263-
"{}({})",
1264-
path,
1265-
self.get_suggested_tuple_struct_pattern(fields, variant)
1266-
),
1262+
format!("({})", self.get_suggested_tuple_struct_pattern(fields, variant)),
12671263
Applicability::MaybeIncorrect,
12681264
);
12691265
return Some(err);
@@ -1421,9 +1417,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
14211417
)
14221418
};
14231419
err.span_suggestion(
1424-
pat.span,
1420+
qpath.span().shrink_to_hi().until(pat.span),
14251421
"use the tuple variant pattern syntax instead",
1426-
format!("{}({})", path, sugg),
1422+
format!("({})", sugg),
14271423
appl,
14281424
);
14291425
return Some(err);

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ 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-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the tuple variant pattern syntax instead: `MyOption::MySome(42)`
5+
| ----------------^^^^^^^^^^
6+
| |
7+
| help: use the tuple variant pattern syntax instead: `(42)`
68

79
error: aborting due to previous error
810

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ 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-
| ^^^^^^^^^^^^^^^^ help: use the tuple variant pattern syntax instead: `S(a, b, c, d)`
5+
| -^^^^^^^^^^^^^^^
6+
| |
7+
| help: use the tuple variant pattern syntax instead: `(a, b, c, d)`
68

79
error: aborting due to previous error
810

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ 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-
| ^^^^^^^^^^^^^^^^^^ help: use the tuple variant pattern syntax instead: `Enum::Bar(a, b)`
25+
| ---------^^^^^^^^^
26+
| |
27+
| help: use the tuple variant pattern syntax instead: `(a, b)`
2628

2729
error: aborting due to 3 previous errors
2830

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ fn main() {
66
let x = E::S(1, 2.2);
77
match x {
88
E::S { 0, 1 } => {}
9-
//~^ ERROR tuple variant `E::S` uses a bare index in a struct pattern [E0769]
9+
//~^ ERROR tuple variant `E::S` written as struct variant [E0769]
1010
}
1111
let y = S(1, 2.2);
1212
match y {

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
1-
error[E0769]: tuple variant `E::S` uses a bare index in a struct pattern
1+
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-
| ^^^^^^^^^^^^^ help: use the tuple variant pattern syntax instead: `E::S(_, _)`
5+
| ----^^^^^^^^^
6+
| |
7+
| help: use the tuple variant pattern syntax instead: `(_, _)`
68

79
error[E0769]: tuple variant `S` written as struct variant
810
--> $DIR/struct-tuple-field-names.rs:13:9
911
|
1012
LL | S { } => {}
11-
| ^^^^^ help: use the tuple variant pattern syntax instead: `S(_, _)`
13+
| -^^^^
14+
| |
15+
| help: use the tuple variant pattern syntax instead: `(_, _)`
1216

1317
error: aborting due to 2 previous errors
1418

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

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

79
error: aborting due to previous error
810

0 commit comments

Comments
 (0)