File tree Expand file tree Collapse file tree
compiler/rustc_hir_analysis/src/hir_ty_lowering
tests/ui/const-generics/mgca Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -2593,10 +2593,37 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
25932593
25942594 for init in inits {
25952595 if !variant_def. fields . iter ( ) . any ( |field_def| field_def. name == init. field . name ) {
2596- let err = tcx. dcx ( ) . struct_span_err (
2597- init. field . span ,
2598- format ! ( "struct `{}` has no field named `{}`" , variant_def. name, init. field) ,
2599- ) ;
2596+ let mut err = if adt_def. is_enum ( ) {
2597+ struct_span_code_err ! (
2598+ tcx. dcx( ) ,
2599+ init. field. span,
2600+ E0559 ,
2601+ "variant `{}::{}` has no field named `{}`" ,
2602+ ty,
2603+ variant_def. name,
2604+ init. field
2605+ )
2606+ } else {
2607+ struct_span_code_err ! (
2608+ tcx. dcx( ) ,
2609+ init. field. span,
2610+ E0560 ,
2611+ "struct `{}` has no field named `{}`" ,
2612+ variant_def. name,
2613+ init. field
2614+ )
2615+ } ;
2616+ if adt_def. is_enum ( ) {
2617+ err. span_label (
2618+ init. field . span ,
2619+ format ! ( "`{}::{}` does not have this field" , ty, variant_def. name) ,
2620+ ) ;
2621+ } else {
2622+ err. span_label (
2623+ init. field . span ,
2624+ format ! ( "`{}` does not have this field" , variant_def. name) ,
2625+ ) ;
2626+ }
26002627 return ty:: Const :: new_error ( tcx, err. emit ( ) ) ;
26012628 }
26022629 }
Original file line number Diff line number Diff line change 88fn foo < const N : E > ( ) { }
99
1010fn main ( ) {
11- E :: S { x : const { 1 } } ;
11+ foo :: < { E :: S { x : const { 1 } } } > ( ) ;
1212 //~^ ERROR variant `E::S` has no field named `x` [E0559]
1313}
Original file line number Diff line number Diff line change 11error[E0559]: variant `E::S` has no field named `x`
2- --> $DIR/adt_expr_unit_enum_extra_field.rs:11:12
2+ --> $DIR/adt_expr_unit_enum_extra_field.rs:11:19
33 |
4- LL | E::S { x: const { 1 } };
5- | ^ `E::S` does not have this field
6- |
7- = note: all struct fields are already assigned
4+ LL | foo::<{E::S { x: const { 1 } }}>();
5+ | ^ `E::S` does not have this field
86
97error: aborting due to 1 previous error
108
Original file line number Diff line number Diff line change @@ -7,5 +7,5 @@ fn foo<const N: Foo>() {}
77
88fn main ( ) {
99 foo :: < { Foo { field : const { 1 } } } > ( ) ;
10- //~^ ERROR struct `Foo` has no field named `field`
10+ //~^ ERROR struct `Foo` has no field named `field` [E0560]
1111}
Original file line number Diff line number Diff line change 1- error: struct `Foo` has no field named `field`
1+ error[E0560] : struct `Foo` has no field named `field`
22 --> $DIR/adt_expr_unit_struct_extra_field.rs:9:19
33 |
44LL | foo::<{ Foo { field: const { 1 } } }>();
5- | ^^^^^
5+ | ^^^^^ `Foo` does not have this field
66
77error: aborting due to 1 previous error
88
9+ For more information about this error, try `rustc --explain E0560`.
You can’t perform that action at this time.
0 commit comments