use the identifier span for missing struct field

This commit is contained in:
Andy Russell 2019-03-16 13:14:01 -04:00
parent 16e7e05e95
commit b392c5e3c1
No known key found for this signature in database
GPG key ID: BE2221033EDBC374
6 changed files with 15 additions and 15 deletions

View file

@ -971,7 +971,7 @@ https://doc.rust-lang.org/reference/types.html#trait-objects");
self.field_ty(span, f, substs)
})
.unwrap_or_else(|| {
inexistent_fields.push((span, field.ident));
inexistent_fields.push(field.ident);
no_field_errors = false;
tcx.types.err
})
@ -987,15 +987,15 @@ https://doc.rust-lang.org/reference/types.html#trait-objects");
.collect::<Vec<_>>();
if inexistent_fields.len() > 0 {
let (field_names, t, plural) = if inexistent_fields.len() == 1 {
(format!("a field named `{}`", inexistent_fields[0].1), "this", "")
(format!("a field named `{}`", inexistent_fields[0]), "this", "")
} else {
(format!("fields named {}",
inexistent_fields.iter()
.map(|(_, name)| format!("`{}`", name))
.map(|ident| format!("`{}`", ident))
.collect::<Vec<String>>()
.join(", ")), "these", "s")
};
let spans = inexistent_fields.iter().map(|(span, _)| *span).collect::<Vec<_>>();
let spans = inexistent_fields.iter().map(|ident| ident.span).collect::<Vec<_>>();
let mut err = struct_span_err!(tcx.sess,
spans,
E0026,
@ -1003,8 +1003,8 @@ https://doc.rust-lang.org/reference/types.html#trait-objects");
kind_name,
tcx.item_path_str(variant.did),
field_names);
if let Some((span, ident)) = inexistent_fields.last() {
err.span_label(*span,
if let Some(ident) = inexistent_fields.last() {
err.span_label(ident.span,
format!("{} `{}` does not have {} field{}",
kind_name,
tcx.item_path_str(variant.did),
@ -1016,8 +1016,8 @@ https://doc.rust-lang.org/reference/types.html#trait-objects");
find_best_match_for_name(input, &ident.as_str(), None);
if let Some(suggested_name) = suggested_name {
err.span_suggestion(
*span,
"did you mean",
ident.span,
"a field with a similar name exists",
suggested_name.to_string(),
Applicability::MaybeIncorrect,
);

View file

@ -2,10 +2,10 @@ error[E0026]: variant `MyOption::MySome` does not have a field named `x`
--> $DIR/issue-17800.rs:8:28
|
LL | MyOption::MySome { x: 42 } => (),
| ^^^^^
| ^
| |
| variant `MyOption::MySome` does not have this field
| help: did you mean: `0`
| help: a field with a similar name exists: `0`
error: aborting due to previous error

View file

@ -2,7 +2,7 @@ error[E0026]: struct `SimpleStruct` does not have a field named `state`
--> $DIR/issue-51102.rs:13:17
|
LL | state: 0,
| ^^^^^^^^ struct `SimpleStruct` does not have this field
| ^^^^^ struct `SimpleStruct` does not have this field
error[E0025]: field `no_state_here` bound multiple times in the pattern
--> $DIR/issue-51102.rs:24:17
@ -16,7 +16,7 @@ error[E0026]: variant `SimpleEnum::NoState` does not have a field named `state`
--> $DIR/issue-51102.rs:33:17
|
LL | state: 0
| ^^^^^^^^ variant `SimpleEnum::NoState` does not have this field
| ^^^^^ variant `SimpleEnum::NoState` does not have this field
error: aborting due to 3 previous errors

View file

@ -5,7 +5,7 @@ LL | A::A { fob } => { println!("{}", fob); }
| ^^^
| |
| variant `A::A` does not have this field
| help: did you mean: `foo`
| help: a field with a similar name exists: `foo`
error: aborting due to previous error

View file

@ -10,7 +10,7 @@ error[E0026]: struct `S` does not have a field named `0x1`
--> $DIR/numeric-fields.rs:7:17
|
LL | S{0: a, 0x1: b, ..} => {}
| ^^^^^^ struct `S` does not have this field
| ^^^ struct `S` does not have this field
error: aborting due to 2 previous errors

View file

@ -22,7 +22,7 @@ error[E0026]: struct `Foo` does not have a field named `absent`
--> $DIR/struct-field-cfg.rs:16:42
|
LL | let Foo { present: (), #[cfg(all())] absent: () } = foo;
| ^^^^^^^^^^ struct `Foo` does not have this field
| ^^^^^^ struct `Foo` does not have this field
error: aborting due to 4 previous errors