@@ -1182,46 +1182,40 @@ pub fn eval_const_expr_partial<'tcx>(tcx: &ty::ctxt<'tcx>,
1182
1182
} ,
1183
1183
hir:: ExprTupField ( ref base, index) => {
1184
1184
let base_hint = ty_hint. erase_hint ( ) ;
1185
- if let Ok ( c) = eval_const_expr_partial ( tcx, base, base_hint, fn_args) {
1186
- if let Tuple ( tup_id) = c {
1187
- if let hir:: ExprTup ( ref fields) = tcx. map . expect_expr ( tup_id) . node {
1188
- if index. node < fields. len ( ) {
1189
- return eval_const_expr_partial ( tcx, & fields[ index. node ] , base_hint, fn_args)
1190
- } else {
1191
- signal ! ( e, TupleIndexOutOfBounds ) ;
1192
- }
1185
+ let c = try!( eval_const_expr_partial ( tcx, base, base_hint, fn_args) ) ;
1186
+ if let Tuple ( tup_id) = c {
1187
+ if let hir:: ExprTup ( ref fields) = tcx. map . expect_expr ( tup_id) . node {
1188
+ if index. node < fields. len ( ) {
1189
+ return eval_const_expr_partial ( tcx, & fields[ index. node ] , base_hint, fn_args)
1193
1190
} else {
1194
- unreachable ! ( )
1191
+ signal ! ( e , TupleIndexOutOfBounds ) ;
1195
1192
}
1196
1193
} else {
1197
- signal ! ( base , ExpectedConstTuple ) ;
1194
+ unreachable ! ( )
1198
1195
}
1199
1196
} else {
1200
- signal ! ( base, NonConstPath )
1197
+ signal ! ( base, ExpectedConstTuple ) ;
1201
1198
}
1202
1199
}
1203
1200
hir:: ExprField ( ref base, field_name) => {
1204
1201
let base_hint = ty_hint. erase_hint ( ) ;
1205
1202
// Get the base expression if it is a struct and it is constant
1206
- if let Ok ( c) = eval_const_expr_partial ( tcx, base, base_hint, fn_args) {
1207
- if let Struct ( struct_id) = c {
1208
- if let hir:: ExprStruct ( _, ref fields, _) = tcx. map . expect_expr ( struct_id) . node {
1209
- // Check that the given field exists and evaluate it
1210
- // if the idents are compared run-pass/issue-19244 fails
1211
- if let Some ( f) = fields. iter ( ) . find ( |f| f. name . node
1212
- == field_name. node ) {
1213
- return eval_const_expr_partial ( tcx, & * f. expr , base_hint, fn_args)
1214
- } else {
1215
- signal ! ( e, MissingStructField ) ;
1216
- }
1203
+ let c = try!( eval_const_expr_partial ( tcx, base, base_hint, fn_args) ) ;
1204
+ if let Struct ( struct_id) = c {
1205
+ if let hir:: ExprStruct ( _, ref fields, _) = tcx. map . expect_expr ( struct_id) . node {
1206
+ // Check that the given field exists and evaluate it
1207
+ // if the idents are compared run-pass/issue-19244 fails
1208
+ if let Some ( f) = fields. iter ( ) . find ( |f| f. name . node
1209
+ == field_name. node ) {
1210
+ return eval_const_expr_partial ( tcx, & * f. expr , base_hint, fn_args)
1217
1211
} else {
1218
- unreachable ! ( )
1212
+ signal ! ( e , MissingStructField ) ;
1219
1213
}
1220
1214
} else {
1221
- signal ! ( base , ExpectedConstStruct ) ;
1215
+ unreachable ! ( )
1222
1216
}
1223
1217
} else {
1224
- signal ! ( base, NonConstPath ) ;
1218
+ signal ! ( base, ExpectedConstStruct ) ;
1225
1219
}
1226
1220
}
1227
1221
_ => signal ! ( e, MiscCatchAll )
0 commit comments