@@ -3463,6 +3463,22 @@ fn check_expr_with_unifier(fcx: &FnCtxt,
3463
3463
fcx. write_ty ( id, enum_type) ;
3464
3464
}
3465
3465
3466
+ fn check_struct_fields_on_error ( fcx : & FnCtxt ,
3467
+ id : ast:: NodeId ,
3468
+ fields : & [ ast:: Field ] ,
3469
+ base_expr : Option < Gc < ast:: Expr > > ) {
3470
+ // Make sure to still write the types
3471
+ // otherwise we might ICE
3472
+ fcx. write_error ( id) ;
3473
+ for field in fields. iter ( ) {
3474
+ check_expr ( fcx, & * field. expr ) ;
3475
+ }
3476
+ match base_expr {
3477
+ Some ( ref base) => check_expr ( fcx, & * * base) ,
3478
+ None => { }
3479
+ }
3480
+ }
3481
+
3466
3482
type ExprCheckerWithTy = fn ( & FnCtxt , & ast:: Expr , ty:: t ) ;
3467
3483
3468
3484
let tcx = fcx. ccx . tcx ;
@@ -3982,6 +3998,16 @@ fn check_expr_with_unifier(fcx: &FnCtxt,
3982
3998
variant_id, fields. as_slice ( ) ) ;
3983
3999
enum_id
3984
4000
}
4001
+ Some ( def:: DefTrait ( def_id) ) => {
4002
+ span_err ! ( tcx. sess, path. span, E0159 ,
4003
+ "`{}` is a trait not a structure" ,
4004
+ pprust:: path_to_string( path) ) ;
4005
+ check_struct_fields_on_error ( fcx,
4006
+ id,
4007
+ fields. as_slice ( ) ,
4008
+ base_expr) ;
4009
+ def_id
4010
+ } ,
3985
4011
Some ( def) => {
3986
4012
// Verify that this was actually a struct.
3987
4013
let typ = ty:: lookup_item_type ( fcx. ccx . tcx , def. def_id ( ) ) ;
@@ -3998,17 +4024,10 @@ fn check_expr_with_unifier(fcx: &FnCtxt,
3998
4024
span_err ! ( tcx. sess, path. span, E0071 ,
3999
4025
"`{}` does not name a structure" ,
4000
4026
pprust:: path_to_string( path) ) ;
4001
-
4002
- // Make sure to still write the types
4003
- // otherwise we might ICE
4004
- fcx. write_error ( id) ;
4005
- for field in fields. iter ( ) {
4006
- check_expr ( fcx, & * field. expr ) ;
4007
- }
4008
- match base_expr {
4009
- Some ( ref base) => check_expr ( fcx, & * * base) ,
4010
- None => { }
4011
- }
4027
+ check_struct_fields_on_error ( fcx,
4028
+ id,
4029
+ fields. as_slice ( ) ,
4030
+ base_expr) ;
4012
4031
}
4013
4032
}
4014
4033
0 commit comments