@@ -3515,34 +3515,34 @@ fn check_expr_with_unifier<'a, 'tcx, F>(fcx: &FnCtxt<'a, 'tcx>,
3515
3515
}
3516
3516
ast:: ExprIndex ( ref base, ref idx) => {
3517
3517
check_expr_with_lvalue_pref ( fcx, & * * base, lvalue_pref) ;
3518
+ check_expr ( fcx, & * * idx) ;
3519
+
3518
3520
let base_t = fcx. expr_ty ( & * * base) ;
3521
+ let idx_t = fcx. expr_ty ( & * * idx) ;
3522
+
3519
3523
if ty:: type_is_error ( base_t) {
3520
3524
fcx. write_ty ( id, base_t) ;
3525
+ } else if ty:: type_is_error ( idx_t) {
3526
+ fcx. write_ty ( id, idx_t) ;
3521
3527
} else {
3522
- check_expr ( fcx, & * * idx) ;
3523
- let idx_t = fcx. expr_ty ( & * * idx) ;
3524
- if ty:: type_is_error ( idx_t) {
3525
- fcx. write_ty ( id, idx_t) ;
3526
- } else {
3527
- let base_t = structurally_resolved_type ( fcx, expr. span , base_t) ;
3528
- match lookup_indexing ( fcx, expr, base, base_t, idx_t, lvalue_pref) {
3529
- Some ( ( index_ty, element_ty) ) => {
3530
- let idx_expr_ty = fcx. expr_ty ( idx) ;
3531
- demand:: eqtype ( fcx, expr. span , index_ty, idx_expr_ty) ;
3532
- fcx. write_ty ( id, element_ty) ;
3533
- }
3534
- None => {
3535
- check_expr_has_type ( fcx, & * * idx, fcx. tcx ( ) . types . err ) ;
3536
- fcx. type_error_message (
3537
- expr. span ,
3538
- |actual| {
3539
- format ! ( "cannot index a value of type `{}`" ,
3540
- actual)
3541
- } ,
3542
- base_t,
3543
- None ) ;
3544
- fcx. write_ty ( id, fcx. tcx ( ) . types . err ) ;
3545
- }
3528
+ let base_t = structurally_resolved_type ( fcx, expr. span , base_t) ;
3529
+ match lookup_indexing ( fcx, expr, base, base_t, idx_t, lvalue_pref) {
3530
+ Some ( ( index_ty, element_ty) ) => {
3531
+ let idx_expr_ty = fcx. expr_ty ( idx) ;
3532
+ demand:: eqtype ( fcx, expr. span , index_ty, idx_expr_ty) ;
3533
+ fcx. write_ty ( id, element_ty) ;
3534
+ }
3535
+ None => {
3536
+ check_expr_has_type ( fcx, & * * idx, fcx. tcx ( ) . types . err ) ;
3537
+ fcx. type_error_message (
3538
+ expr. span ,
3539
+ |actual| {
3540
+ format ! ( "cannot index a value of type `{}`" ,
3541
+ actual)
3542
+ } ,
3543
+ base_t,
3544
+ None ) ;
3545
+ fcx. write_ty ( id, fcx. tcx ( ) . types . err ) ;
3546
3546
}
3547
3547
}
3548
3548
}
0 commit comments