Skip to content

Commit e4db677

Browse files
author
Oliver Schneider
committed
better error reporting
1 parent cdb6eec commit e4db677

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

src/librustc_trans/trans/consts.rs

+16-6
Original file line numberDiff line numberDiff line change
@@ -612,9 +612,19 @@ fn const_expr_unadjusted<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
612612
ast::ExprIndex(ref base, ref index) => {
613613
match const_eval::eval_const_expr_partial(cx.tcx(), &e, None) {
614614
Ok(val) => const_val_for_idx(cx, val, param_substs, ety),
615-
Err(NonConstPath) => {
615+
Err(const_eval::ConstEvalErr {
616+
kind: const_eval::ErrKind::NonConstPath, ..
617+
}) | Err(const_eval::ConstEvalErr {
618+
kind: const_eval::ErrKind::MiscCatchAll, ..
619+
}) => {
616620
let (bv, bt) = const_expr(cx, &**base, param_substs);
617-
let iv = try!(const_eval::eval_const_index(cx.tcx(), &**index));
621+
let iv = match const_eval::eval_const_index(cx.tcx(), &**index) {
622+
Ok(idx) => idx,
623+
Err(err) => {
624+
cx.sess().span_err(err.span, &*err.description());
625+
cx.sess().span_fatal(index.span,"constant evaluation of index failed");
626+
},
627+
};
618628
let (arr, len) = match bt.sty {
619629
ty::ty_vec(_, Some(u)) => (bv, C_uint(cx, u)),
620630
ty::ty_vec(_, None) | ty::ty_str => {
@@ -659,10 +669,10 @@ fn const_expr_unadjusted<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
659669
const_get_elt(cx, arr, &[iv as c_uint])
660670
}
661671
},
662-
Err(err) => cx.sess().span_fatal(
663-
e.span,
664-
&format!("constant indexing failed: {}", err.description()),
665-
),
672+
Err(err) => {
673+
cx.sess().span_err(err.span, &*err.description());
674+
cx.sess().span_fatal(e.span,"constant indexing failed");
675+
},
666676
}
667677
}
668678
ast::ExprCast(ref base, _) => {

0 commit comments

Comments
 (0)