Skip to content

Commit

Permalink
use the identifier span for missing struct field
Browse files Browse the repository at this point in the history
  • Loading branch information
euclio committed Mar 16, 2019
1 parent 16e7e05 commit b392c5e
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 15 deletions.
16 changes: 8 additions & 8 deletions src/librustc_typeck/check/_match.rs
Expand Up @@ -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
})
Expand All @@ -987,24 +987,24 @@ 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,
"{} `{}` does not have {}",
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),
Expand All @@ -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,
);
Expand Down
4 changes: 2 additions & 2 deletions src/test/ui/issues/issue-17800.stderr
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions src/test/ui/issues/issue-51102.stderr
Expand Up @@ -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
Expand All @@ -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

Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/issues/issue-52717.stderr
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/numeric/numeric-fields.stderr
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/structs/struct-field-cfg.stderr
Expand Up @@ -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

Expand Down

0 comments on commit b392c5e

Please sign in to comment.