Skip to content

Commit e919f82

Browse files
committed
Address arith-overflow and error-handling in const_eval.rs.
1. Detect and report arithmetic overflow during const-expr eval. 2. Instead `eval_const_expr_partial` returning `Err(String)`, it now has a dedicated enum of different cases. The main benefit of this is the ability to pass along an interpretable payload, namely the two inputs that caused an overlfow. I attempted to minimize fallout to error output in tests, but some was unavoidable. Those changes are in a follow-on commit.
1 parent f9bbef7 commit e919f82

File tree

6 files changed

+234
-69
lines changed

6 files changed

+234
-69
lines changed

src/librustc/middle/check_const.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -307,8 +307,9 @@ impl<'a, 'tcx, 'v> Visitor<'v> for CheckCrateVisitor<'a, 'tcx> {
307307
match const_eval::eval_const_expr_partial(self.tcx, ex, None) {
308308
Ok(_) => {}
309309
Err(msg) => {
310-
span_err!(self.tcx.sess, ex.span, E0020,
311-
"{} in a constant expression", msg)
310+
span_err!(self.tcx.sess, msg.span, E0020,
311+
"{} in a constant expression",
312+
msg.description())
312313
}
313314
}
314315
}

0 commit comments

Comments
 (0)