Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use the identifier span for missing struct field #59240

Merged
merged 1 commit into from
Mar 25, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions src/librustc_typeck/check/_match.rs
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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