Skip to content

Commit 82660a2

Browse files
authored
Rollup merge of #98738 - tmiasko:checked-binop, r=oli-obk
Clarify MIR semantics of checked binary operations
2 parents 17581a7 + b884797 commit 82660a2

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

compiler/rustc_middle/src/mir/syntax.rs

+12-4
Original file line numberDiff line numberDiff line change
@@ -990,11 +990,19 @@ pub enum Rvalue<'tcx> {
990990
/// matching types and return a value of that type.
991991
BinaryOp(BinOp, Box<(Operand<'tcx>, Operand<'tcx>)>),
992992

993-
/// Same as `BinaryOp`, but yields `(T, bool)` instead of `T`. In addition to performing the
994-
/// same computation as the matching `BinaryOp`, checks if the infinite precison result would be
995-
/// unequal to the actual result and sets the `bool` if this is the case.
993+
/// Same as `BinaryOp`, but yields `(T, bool)` with a `bool` indicating an error condition.
996994
///
997-
/// This only supports addition, subtraction, multiplication, and shift operations on integers.
995+
/// When overflow checking is disabled, the error condition is false. Otherwise, the error
996+
/// condition is determined as described below.
997+
///
998+
/// For addition, subtraction, and multiplication on integers the error condition is set when
999+
/// the infinite precision result would be unequal to the actual result.
1000+
///
1001+
/// For shift operations on integers the error condition is set when the value of right-hand
1002+
/// side is greater than or equal to the number of bits in the type of the left-hand side, or
1003+
/// when the value of right-hand side is negative.
1004+
///
1005+
/// Other combinations of types and operators are unsupported.
9981006
CheckedBinaryOp(BinOp, Box<(Operand<'tcx>, Operand<'tcx>)>),
9991007

10001008
/// Computes a value as described by the operation.

0 commit comments

Comments
 (0)