Skip to content

Commit 92dd526

Browse files
author
Tim
committed
Move check out of the match on the intrinsic name
1 parent 58af73c commit 92dd526

File tree

1 file changed

+7
-16
lines changed

1 file changed

+7
-16
lines changed

src/librustc_mir/interpret/intrinsics.rs

+7-16
Original file line numberDiff line numberDiff line change
@@ -132,23 +132,14 @@ impl<'a, 'mir, 'tcx, M: Machine<'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M> {
132132
let r_ty = substs.type_at(0);
133133
let r_layout_of = self.layout_of(r_ty)?;
134134
let r_val = r.to_scalar()?.to_bits(r_layout_of.size)?;
135+
if r_val >= bits {
136+
return err!(Intrinsic(
137+
format!("Overflowing shift by {} in {}", r_val, intrinsic_name),
138+
));
139+
}
135140
let bin_op = match intrinsic_name {
136-
"unchecked_shl" => {
137-
if r_val >= bits {
138-
return err!(Intrinsic(
139-
format!("Overflowing shift by {} in unchecked_shl", r_val),
140-
));
141-
}
142-
BinOp::Shl
143-
},
144-
"unchecked_shr" => {
145-
if r_val >= bits {
146-
return err!(Intrinsic(
147-
format!("Overflowing shift by {} in unchecked_shr", r_val),
148-
));
149-
}
150-
BinOp::Shr
151-
},
141+
"unchecked_shl" => BinOp::Shl,
142+
"unchecked_shr" => BinOp::Shr,
152143
_ => bug!("Already checked for int ops")
153144
};
154145
self.binop_ignore_overflow(bin_op, l, r, dest)?;

0 commit comments

Comments
 (0)