Skip to content

Commit 062a46f

Browse files
committed
Reduce diagnostic verbosity by removing labels
1 parent f332a9c commit 062a46f

9 files changed

+18
-23
lines changed

src/librustc_typeck/check/_match.rs

+9-8
Original file line numberDiff line numberDiff line change
@@ -938,14 +938,14 @@ https://doc.rust-lang.org/reference/types.html#trait-objects");
938938
}
939939

940940
if inexistent_fields.len() > 0 {
941-
let field_names = if inexistent_fields.len() == 1 {
942-
format!("a field named `{}`", inexistent_fields[0].1)
941+
let (field_names, t, plural) = if inexistent_fields.len() == 1 {
942+
(format!("a field named `{}`", inexistent_fields[0].1), "this", "")
943943
} else {
944-
format!("fields named {}",
945-
inexistent_fields.iter()
944+
(format!("fields named {}",
945+
inexistent_fields.iter()
946946
.map(|(_, name)| format!("`{}`", name))
947947
.collect::<Vec<String>>()
948-
.join(", "))
948+
.join(", ")), "these", "s")
949949
};
950950
let spans = inexistent_fields.iter().map(|(span, _)| *span).collect::<Vec<_>>();
951951
let mut err = struct_span_err!(tcx.sess,
@@ -955,12 +955,13 @@ https://doc.rust-lang.org/reference/types.html#trait-objects");
955955
kind_name,
956956
tcx.item_path_str(variant.did),
957957
field_names);
958-
for (span, name) in &inexistent_fields {
958+
if let Some((span, _)) = inexistent_fields.last() {
959959
err.span_label(*span,
960-
format!("{} `{}` does not have field `{}`",
960+
format!("{} `{}` does not have {} field{}",
961961
kind_name,
962962
tcx.item_path_str(variant.did),
963-
name));
963+
t,
964+
plural));
964965
}
965966
if tcx.sess.teach(&err.get_code().unwrap()) {
966967
err.note(

src/test/compile-fail/struct-pat-derived-error.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,8 @@ struct a {
1616
impl a {
1717
fn foo(&self) {
1818
let a { x, y } = self.d; //~ ERROR no field `d` on type `&a`
19-
//~^ ERROR struct `a` does not have a field named `x`
20-
//~^^ ERROR struct `a` does not have a field named `y`
21-
//~^^^ ERROR pattern does not mention field `b`
22-
//~^^^^ ERROR pattern does not mention field `c`
19+
//~^ ERROR struct `a` does not have fields named `x`, `y`
20+
//~| ERROR pattern does not mention fields `b`, `c`
2321
}
2422
}
2523

src/test/ui/error-codes/E0026-teach.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0026]: struct `Thing` does not have a field named `z`
22
--> $DIR/E0026-teach.rs:21:23
33
|
44
LL | Thing { x, y, z } => {}
5-
| ^ struct `Thing` does not have field `z`
5+
| ^ struct `Thing` does not have this field
66
|
77
= note: This error indicates that a struct pattern attempted to extract a non-existent field from a struct. Struct fields are identified by the name used before the colon : so struct patterns should resemble the declaration of the struct type being matched.
88

src/test/ui/error-codes/E0026.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0026]: struct `Thing` does not have a field named `z`
22
--> $DIR/E0026.rs:19:23
33
|
44
LL | Thing { x, y, z } => {}
5-
| ^ struct `Thing` does not have field `z`
5+
| ^ struct `Thing` does not have this field
66

77
error: aborting due to previous error
88

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ struct S(usize, usize, usize, usize);
1313
fn main() {
1414
if let S { a, b, c, d } = S(1, 2, 3, 4) {
1515
//~^ ERROR struct `S` does not have fields named `a`, `b`, `c`, `d` [E0026]
16-
//~^ ERROR pattern does not mention fields `0`, `1`, `2`, `3` [E0027]
16+
//~| ERROR pattern does not mention fields `0`, `1`, `2`, `3` [E0027]
1717
println!("hi");
1818
}
1919
}

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

+1-5
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,7 @@ error[E0026]: struct `S` does not have fields named `a`, `b`, `c`, `d`
22
--> $DIR/missing-fields-in-struct-pattern.rs:14:16
33
|
44
LL | if let S { a, b, c, d } = S(1, 2, 3, 4) {
5-
| ^ ^ ^ ^ struct `S` does not have field `d`
6-
| | | |
7-
| | | struct `S` does not have field `c`
8-
| | struct `S` does not have field `b`
9-
| struct `S` does not have field `a`
5+
| ^ ^ ^ ^ struct `S` does not have these fields
106

117
error[E0027]: pattern does not mention fields `0`, `1`, `2`, `3`
128
--> $DIR/missing-fields-in-struct-pattern.rs:14:12

src/test/ui/numeric-fields.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ error[E0026]: struct `S` does not have a field named `0x1`
1010
--> $DIR/numeric-fields.rs:17:17
1111
|
1212
LL | S{0: a, 0x1: b, ..} => {}
13-
| ^^^^^^ struct `S` does not have field `0x1`
13+
| ^^^^^^ struct `S` does not have this field
1414

1515
error: aborting due to 2 previous errors
1616

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0026]: variant `X::Y` does not have a field named `number`
22
--> $DIR/issue-41314.rs:17:16
33
|
44
LL | X::Y { number } => {} //~ ERROR does not have a field named `number`
5-
| ^^^^^^ variant `X::Y` does not have field `number`
5+
| ^^^^^^ variant `X::Y` does not have this field
66

77
error[E0027]: pattern does not mention field `0`
88
--> $DIR/issue-41314.rs:17:9

src/test/ui/union/union-fields-2.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ error[E0026]: union `U` does not have a field named `c`
5252
--> $DIR/union-fields-2.rs:28:19
5353
|
5454
LL | let U { a, b, c } = u; //~ ERROR union patterns should have exactly one field
55-
| ^ union `U` does not have field `c`
55+
| ^ union `U` does not have this field
5656

5757
error: union patterns should have exactly one field
5858
--> $DIR/union-fields-2.rs:28:9

0 commit comments

Comments
 (0)