Skip to content

Commit 2243a2c

Browse files
committed
Unify handling of checking repeat-count validity.
1 parent 1973f7e commit 2243a2c

File tree

1 file changed

+1
-13
lines changed

1 file changed

+1
-13
lines changed

src/librustc_trans/trans/consts.rs

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -772,19 +772,7 @@ fn const_expr_unadjusted<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
772772
ast::ExprRepeat(ref elem, ref count) => {
773773
let unit_ty = ty::sequence_element_type(cx.tcx(), ety);
774774
let llunitty = type_of::type_of(cx, unit_ty);
775-
let n = match const_eval::eval_const_expr_partial(cx.tcx(), &**count, None) {
776-
Ok(const_eval::const_int(i)) => i as usize,
777-
Ok(const_eval::const_uint(i)) => i as usize,
778-
Ok(_) => {
779-
cx.sess().span_bug(count.span, "count must be integral const expression.")
780-
}
781-
Err(err) => {
782-
cx.sess().span_err(count.span, &format!("error evaluating count: {}",
783-
err.description()));
784-
// return 1 to allow compilation to proceed
785-
1 as usize
786-
}
787-
};
775+
let n = ty::eval_repeat_count(cx.tcx(), count);
788776
let unit_val = const_expr(cx, &**elem, param_substs).0;
789777
let vs: Vec<_> = repeat(unit_val).take(n).collect();
790778
if val_ty(unit_val) != llunitty {

0 commit comments

Comments
 (0)