Skip to content

Commit c917ba3

Browse files
adt hint pointing to adt span
1 parent 2191c1d commit c917ba3

File tree

3 files changed

+9
-10
lines changed

3 files changed

+9
-10
lines changed

src/librustc_typeck/check/expr.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -1125,7 +1125,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
11251125

11261126
err.emit();
11271127
} else {
1128-
self.report_unknown_field(adt_ty, variant, field, ast_fields, kind_name);
1128+
self.report_unknown_field(adt_ty, variant, field, ast_fields, kind_name, span);
11291129
}
11301130

11311131
tcx.types.err
@@ -1196,6 +1196,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
11961196
field: &hir::Field,
11971197
skip_fields: &[hir::Field],
11981198
kind_name: &str,
1199+
ty_span: Span
11991200
) {
12001201
if variant.recovered {
12011202
return;
@@ -1218,7 +1219,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
12181219
match variant.ctor_kind {
12191220
CtorKind::Fn => {
12201221
err.span_label(field.ident.span, "field does not exist");
1221-
err.span_label(field.ident.span, format!(
1222+
err.span_label(ty_span, format!(
12221223
"`{adt}` is a tuple {kind_name}, use the appropriate syntax: `{adt}(/* fields */)`",
12231224
adt=ty,
12241225
kind_name=kind_name

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

+3-4
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,9 @@ error[E0560]: struct `NonCopyable` has no field named `p`
22
--> $DIR/issue-4736.rs:4:26
33
|
44
LL | let z = NonCopyable{ p: () };
5-
| ^
6-
| |
7-
| field does not exist
8-
| `NonCopyable` is a tuple struct, use the appropriate syntax: `NonCopyable(/* fields */)`
5+
| ----------- ^ field does not exist
6+
| |
7+
| `NonCopyable` is a tuple struct, use the appropriate syntax: `NonCopyable(/* fields */)`
98

109
error: aborting due to previous error
1110

src/test/ui/numeric/numeric-fields.stderr

+3-4
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,9 @@ error[E0560]: struct `S` has no field named `0b1`
22
--> $DIR/numeric-fields.rs:4:15
33
|
44
LL | let s = S{0b1: 10, 0: 11};
5-
| ^^^
6-
| |
7-
| field does not exist
8-
| `S` is a tuple struct, use the appropriate syntax: `S(/* fields */)`
5+
| - ^^^ field does not exist
6+
| |
7+
| `S` is a tuple struct, use the appropriate syntax: `S(/* fields */)`
98

109
error[E0026]: struct `S` does not have a field named `0x1`
1110
--> $DIR/numeric-fields.rs:7:17

0 commit comments

Comments
 (0)