Skip to content

Commit 70e52f8

Browse files
provide variant definition on tuple struct unknow field error
1 parent c917ba3 commit 70e52f8

File tree

3 files changed

+11
-3
lines changed

3 files changed

+11
-3
lines changed

src/librustc_typeck/check/expr.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1218,9 +1218,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
12181218
ty);
12191219
match variant.ctor_kind {
12201220
CtorKind::Fn => {
1221+
err.span_label(variant.ident.span, format!("`{adt}` defined here", adt=ty));
12211222
err.span_label(field.ident.span, "field does not exist");
12221223
err.span_label(ty_span, format!(
1223-
"`{adt}` is a tuple {kind_name}, use the appropriate syntax: `{adt}(/* fields */)`",
1224+
"`{adt}` is a tuple {kind_name},\
1225+
use the appropriate syntax: `{adt}(/* fields */)`",
12241226
adt=ty,
12251227
kind_name=kind_name
12261228
));

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

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

912
error: aborting due to previous error
1013

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

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
error[E0560]: struct `S` has no field named `0b1`
22
--> $DIR/numeric-fields.rs:4:15
33
|
4+
LL | struct S(u8, u16);
5+
| - `S` defined here
6+
...
47
LL | let s = S{0b1: 10, 0: 11};
58
| - ^^^ field does not exist
69
| |
7-
| `S` is a tuple struct, use the appropriate syntax: `S(/* fields */)`
10+
| `S` is a tuple struct,use the appropriate syntax: `S(/* fields */)`
811

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

0 commit comments

Comments
 (0)