Skip to content

Commit 6f59f9a

Browse files
Rollup merge of rust-lang#59240 - euclio:struct-field-span, r=oli-obk
use the identifier span for missing struct field
2 parents d1344b3 + b392c5e commit 6f59f9a

File tree

6 files changed

+15
-15
lines changed

6 files changed

+15
-15
lines changed

src/librustc_typeck/check/_match.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -973,7 +973,7 @@ https://doc.rust-lang.org/reference/types.html#trait-objects");
973973
self.field_ty(span, f, substs)
974974
})
975975
.unwrap_or_else(|| {
976-
inexistent_fields.push((span, field.ident));
976+
inexistent_fields.push(field.ident);
977977
no_field_errors = false;
978978
tcx.types.err
979979
})
@@ -989,24 +989,24 @@ https://doc.rust-lang.org/reference/types.html#trait-objects");
989989
.collect::<Vec<_>>();
990990
if inexistent_fields.len() > 0 && !variant.recovered {
991991
let (field_names, t, plural) = if inexistent_fields.len() == 1 {
992-
(format!("a field named `{}`", inexistent_fields[0].1), "this", "")
992+
(format!("a field named `{}`", inexistent_fields[0]), "this", "")
993993
} else {
994994
(format!("fields named {}",
995995
inexistent_fields.iter()
996-
.map(|(_, name)| format!("`{}`", name))
996+
.map(|ident| format!("`{}`", ident))
997997
.collect::<Vec<String>>()
998998
.join(", ")), "these", "s")
999999
};
1000-
let spans = inexistent_fields.iter().map(|(span, _)| *span).collect::<Vec<_>>();
1000+
let spans = inexistent_fields.iter().map(|ident| ident.span).collect::<Vec<_>>();
10011001
let mut err = struct_span_err!(tcx.sess,
10021002
spans,
10031003
E0026,
10041004
"{} `{}` does not have {}",
10051005
kind_name,
10061006
tcx.def_path_str(variant.did),
10071007
field_names);
1008-
if let Some((span, ident)) = inexistent_fields.last() {
1009-
err.span_label(*span,
1008+
if let Some(ident) = inexistent_fields.last() {
1009+
err.span_label(ident.span,
10101010
format!("{} `{}` does not have {} field{}",
10111011
kind_name,
10121012
tcx.def_path_str(variant.did),
@@ -1018,8 +1018,8 @@ https://doc.rust-lang.org/reference/types.html#trait-objects");
10181018
find_best_match_for_name(input, &ident.as_str(), None);
10191019
if let Some(suggested_name) = suggested_name {
10201020
err.span_suggestion(
1021-
*span,
1022-
"did you mean",
1021+
ident.span,
1022+
"a field with a similar name exists",
10231023
suggested_name.to_string(),
10241024
Applicability::MaybeIncorrect,
10251025
);

src/test/ui/issues/issue-17800.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ error[E0026]: variant `MyOption::MySome` does not have a field named `x`
22
--> $DIR/issue-17800.rs:8:28
33
|
44
LL | MyOption::MySome { x: 42 } => (),
5-
| ^^^^^
5+
| ^
66
| |
77
| variant `MyOption::MySome` does not have this field
8-
| help: did you mean: `0`
8+
| help: a field with a similar name exists: `0`
99

1010
error: aborting due to previous error
1111

src/test/ui/issues/issue-51102.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0026]: struct `SimpleStruct` does not have a field named `state`
22
--> $DIR/issue-51102.rs:13:17
33
|
44
LL | state: 0,
5-
| ^^^^^^^^ struct `SimpleStruct` does not have this field
5+
| ^^^^^ struct `SimpleStruct` does not have this field
66

77
error[E0025]: field `no_state_here` bound multiple times in the pattern
88
--> $DIR/issue-51102.rs:24:17
@@ -16,7 +16,7 @@ error[E0026]: variant `SimpleEnum::NoState` does not have a field named `state`
1616
--> $DIR/issue-51102.rs:33:17
1717
|
1818
LL | state: 0
19-
| ^^^^^^^^ variant `SimpleEnum::NoState` does not have this field
19+
| ^^^^^ variant `SimpleEnum::NoState` does not have this field
2020

2121
error: aborting due to 3 previous errors
2222

src/test/ui/issues/issue-52717.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ LL | A::A { fob } => { println!("{}", fob); }
55
| ^^^
66
| |
77
| variant `A::A` does not have this field
8-
| help: did you mean: `foo`
8+
| help: a field with a similar name exists: `foo`
99

1010
error: aborting due to previous error
1111

src/test/ui/numeric/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:7:17
1111
|
1212
LL | S{0: a, 0x1: b, ..} => {}
13-
| ^^^^^^ struct `S` does not have this field
13+
| ^^^ struct `S` does not have this field
1414

1515
error: aborting due to 2 previous errors
1616

src/test/ui/structs/struct-field-cfg.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ error[E0026]: struct `Foo` does not have a field named `absent`
2222
--> $DIR/struct-field-cfg.rs:16:42
2323
|
2424
LL | let Foo { present: (), #[cfg(all())] absent: () } = foo;
25-
| ^^^^^^^^^^ struct `Foo` does not have this field
25+
| ^^^^^^ struct `Foo` does not have this field
2626

2727
error: aborting due to 4 previous errors
2828

0 commit comments

Comments
 (0)