mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-01 15:01:51 +00:00
Reduce diagnostic verbosity by removing labels
This commit is contained in:
parent
f332a9ce56
commit
062a46fdd1
@ -938,14 +938,14 @@ https://doc.rust-lang.org/reference/types.html#trait-objects");
|
||||
}
|
||||
|
||||
if inexistent_fields.len() > 0 {
|
||||
let field_names = if inexistent_fields.len() == 1 {
|
||||
format!("a field named `{}`", inexistent_fields[0].1)
|
||||
let (field_names, t, plural) = if inexistent_fields.len() == 1 {
|
||||
(format!("a field named `{}`", inexistent_fields[0].1), "this", "")
|
||||
} else {
|
||||
format!("fields named {}",
|
||||
(format!("fields named {}",
|
||||
inexistent_fields.iter()
|
||||
.map(|(_, name)| format!("`{}`", name))
|
||||
.collect::<Vec<String>>()
|
||||
.join(", "))
|
||||
.join(", ")), "these", "s")
|
||||
};
|
||||
let spans = inexistent_fields.iter().map(|(span, _)| *span).collect::<Vec<_>>();
|
||||
let mut err = struct_span_err!(tcx.sess,
|
||||
@ -955,12 +955,13 @@ https://doc.rust-lang.org/reference/types.html#trait-objects");
|
||||
kind_name,
|
||||
tcx.item_path_str(variant.did),
|
||||
field_names);
|
||||
for (span, name) in &inexistent_fields {
|
||||
if let Some((span, _)) = inexistent_fields.last() {
|
||||
err.span_label(*span,
|
||||
format!("{} `{}` does not have field `{}`",
|
||||
format!("{} `{}` does not have {} field{}",
|
||||
kind_name,
|
||||
tcx.item_path_str(variant.did),
|
||||
name));
|
||||
t,
|
||||
plural));
|
||||
}
|
||||
if tcx.sess.teach(&err.get_code().unwrap()) {
|
||||
err.note(
|
||||
|
@ -16,10 +16,8 @@ struct a {
|
||||
impl a {
|
||||
fn foo(&self) {
|
||||
let a { x, y } = self.d; //~ ERROR no field `d` on type `&a`
|
||||
//~^ ERROR struct `a` does not have a field named `x`
|
||||
//~^^ ERROR struct `a` does not have a field named `y`
|
||||
//~^^^ ERROR pattern does not mention field `b`
|
||||
//~^^^^ ERROR pattern does not mention field `c`
|
||||
//~^ ERROR struct `a` does not have fields named `x`, `y`
|
||||
//~| ERROR pattern does not mention fields `b`, `c`
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2,7 +2,7 @@ error[E0026]: struct `Thing` does not have a field named `z`
|
||||
--> $DIR/E0026-teach.rs:21:23
|
||||
|
|
||||
LL | Thing { x, y, z } => {}
|
||||
| ^ struct `Thing` does not have field `z`
|
||||
| ^ struct `Thing` does not have this field
|
||||
|
|
||||
= 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.
|
||||
|
||||
|
@ -2,7 +2,7 @@ error[E0026]: struct `Thing` does not have a field named `z`
|
||||
--> $DIR/E0026.rs:19:23
|
||||
|
|
||||
LL | Thing { x, y, z } => {}
|
||||
| ^ struct `Thing` does not have field `z`
|
||||
| ^ struct `Thing` does not have this field
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
@ -13,7 +13,7 @@ struct S(usize, usize, usize, usize);
|
||||
fn main() {
|
||||
if let S { a, b, c, d } = S(1, 2, 3, 4) {
|
||||
//~^ ERROR struct `S` does not have fields named `a`, `b`, `c`, `d` [E0026]
|
||||
//~^ ERROR pattern does not mention fields `0`, `1`, `2`, `3` [E0027]
|
||||
//~| ERROR pattern does not mention fields `0`, `1`, `2`, `3` [E0027]
|
||||
println!("hi");
|
||||
}
|
||||
}
|
||||
|
@ -2,11 +2,7 @@ error[E0026]: struct `S` does not have fields named `a`, `b`, `c`, `d`
|
||||
--> $DIR/missing-fields-in-struct-pattern.rs:14:16
|
||||
|
|
||||
LL | if let S { a, b, c, d } = S(1, 2, 3, 4) {
|
||||
| ^ ^ ^ ^ struct `S` does not have field `d`
|
||||
| | | |
|
||||
| | | struct `S` does not have field `c`
|
||||
| | struct `S` does not have field `b`
|
||||
| struct `S` does not have field `a`
|
||||
| ^ ^ ^ ^ struct `S` does not have these fields
|
||||
|
||||
error[E0027]: pattern does not mention fields `0`, `1`, `2`, `3`
|
||||
--> $DIR/missing-fields-in-struct-pattern.rs:14:12
|
||||
|
@ -10,7 +10,7 @@ error[E0026]: struct `S` does not have a field named `0x1`
|
||||
--> $DIR/numeric-fields.rs:17:17
|
||||
|
|
||||
LL | S{0: a, 0x1: b, ..} => {}
|
||||
| ^^^^^^ struct `S` does not have field `0x1`
|
||||
| ^^^^^^ struct `S` does not have this field
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
|
@ -2,7 +2,7 @@ error[E0026]: variant `X::Y` does not have a field named `number`
|
||||
--> $DIR/issue-41314.rs:17:16
|
||||
|
|
||||
LL | X::Y { number } => {} //~ ERROR does not have a field named `number`
|
||||
| ^^^^^^ variant `X::Y` does not have field `number`
|
||||
| ^^^^^^ variant `X::Y` does not have this field
|
||||
|
||||
error[E0027]: pattern does not mention field `0`
|
||||
--> $DIR/issue-41314.rs:17:9
|
||||
|
@ -52,7 +52,7 @@ error[E0026]: union `U` does not have a field named `c`
|
||||
--> $DIR/union-fields-2.rs:28:19
|
||||
|
|
||||
LL | let U { a, b, c } = u; //~ ERROR union patterns should have exactly one field
|
||||
| ^ union `U` does not have field `c`
|
||||
| ^ union `U` does not have this field
|
||||
|
||||
error: union patterns should have exactly one field
|
||||
--> $DIR/union-fields-2.rs:28:9
|
||||
|
Loading…
Reference in New Issue
Block a user