From 92dd526a4e8633b95754e2a8e2ef7169c30706f6 Mon Sep 17 00:00:00 2001 From: Tim Date: Thu, 6 Sep 2018 13:54:27 +0200 Subject: [PATCH] Move check out of the match on the intrinsic name --- src/librustc_mir/interpret/intrinsics.rs | 23 +++++++---------------- 1 file changed, 7 insertions(+), 16 deletions(-) diff --git a/src/librustc_mir/interpret/intrinsics.rs b/src/librustc_mir/interpret/intrinsics.rs index 0f122209baff..8637903bd71d 100644 --- a/src/librustc_mir/interpret/intrinsics.rs +++ b/src/librustc_mir/interpret/intrinsics.rs @@ -132,23 +132,14 @@ impl<'a, 'mir, 'tcx, M: Machine<'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M> { let r_ty = substs.type_at(0); let r_layout_of = self.layout_of(r_ty)?; let r_val = r.to_scalar()?.to_bits(r_layout_of.size)?; + if r_val >= bits { + return err!(Intrinsic( + format!("Overflowing shift by {} in {}", r_val, intrinsic_name), + )); + } let bin_op = match intrinsic_name { - "unchecked_shl" => { - if r_val >= bits { - return err!(Intrinsic( - format!("Overflowing shift by {} in unchecked_shl", r_val), - )); - } - BinOp::Shl - }, - "unchecked_shr" => { - if r_val >= bits { - return err!(Intrinsic( - format!("Overflowing shift by {} in unchecked_shr", r_val), - )); - } - BinOp::Shr - }, + "unchecked_shl" => BinOp::Shl, + "unchecked_shr" => BinOp::Shr, _ => bug!("Already checked for int ops") }; self.binop_ignore_overflow(bin_op, l, r, dest)?;