Skip to content

Commit 60eca54

Browse files
committed
Auto merge of #59240 - euclio:struct-field-span, r=oli-obk
use the identifier span for missing struct field
2 parents 4691471 + b392c5e commit 60eca54

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
@@ -970,7 +970,7 @@ https://doc.rust-lang.org/reference/types.html#trait-objects");
970970
self.field_ty(span, f, substs)
971971
})
972972
.unwrap_or_else(|| {
973-
inexistent_fields.push((span, field.ident));
973+
inexistent_fields.push(field.ident);
974974
no_field_errors = false;
975975
tcx.types.err
976976
})
@@ -986,24 +986,24 @@ https://doc.rust-lang.org/reference/types.html#trait-objects");
986986
.collect::<Vec<_>>();
987987
if inexistent_fields.len() > 0 && !variant.recovered {
988988
let (field_names, t, plural) = if inexistent_fields.len() == 1 {
989-
(format!("a field named `{}`", inexistent_fields[0].1), "this", "")
989+
(format!("a field named `{}`", inexistent_fields[0]), "this", "")
990990
} else {
991991
(format!("fields named {}",
992992
inexistent_fields.iter()
993-
.map(|(_, name)| format!("`{}`", name))
993+
.map(|ident| format!("`{}`", ident))
994994
.collect::<Vec<String>>()
995995
.join(", ")), "these", "s")
996996
};
997-
let spans = inexistent_fields.iter().map(|(span, _)| *span).collect::<Vec<_>>();
997+
let spans = inexistent_fields.iter().map(|ident| ident.span).collect::<Vec<_>>();
998998
let mut err = struct_span_err!(tcx.sess,
999999
spans,
10001000
E0026,
10011001
"{} `{}` does not have {}",
10021002
kind_name,
10031003
tcx.def_path_str(variant.def_id),
10041004
field_names);
1005-
if let Some((span, ident)) = inexistent_fields.last() {
1006-
err.span_label(*span,
1005+
if let Some(ident) = inexistent_fields.last() {
1006+
err.span_label(ident.span,
10071007
format!("{} `{}` does not have {} field{}",
10081008
kind_name,
10091009
tcx.def_path_str(variant.def_id),
@@ -1015,8 +1015,8 @@ https://doc.rust-lang.org/reference/types.html#trait-objects");
10151015
find_best_match_for_name(input, &ident.as_str(), None);
10161016
if let Some(suggested_name) = suggested_name {
10171017
err.span_suggestion(
1018-
*span,
1019-
"did you mean",
1018+
ident.span,
1019+
"a field with a similar name exists",
10201020
suggested_name.to_string(),
10211021
Applicability::MaybeIncorrect,
10221022
);

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)