about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMatthias Krüger <matthias.krueger@famsik.de>2022-07-04 23:11:07 +0200
committerGitHub <noreply@github.com>2022-07-04 23:11:07 +0200
commit82660a25250d7922a2d7fb279dfc8a1e7ae0b705 (patch)
treee78ef8a6c6f068242b2dc55ebc60b3aa59bea8c8
parent17581a79adb7b1c064222defa94a5a3d79f5bfb2 (diff)
parentb88479738ec8de29da27d9fd4bef5581c362e9b0 (diff)
downloadrust-82660a25250d7922a2d7fb279dfc8a1e7ae0b705.tar.gz
rust-82660a25250d7922a2d7fb279dfc8a1e7ae0b705.zip
Rollup merge of #98738 - tmiasko:checked-binop, r=oli-obk
Clarify MIR semantics of checked binary operations
-rw-r--r--compiler/rustc_middle/src/mir/syntax.rs16
1 files changed, 12 insertions, 4 deletions
diff --git a/compiler/rustc_middle/src/mir/syntax.rs b/compiler/rustc_middle/src/mir/syntax.rs
index f8ee59f306f..17824da2345 100644
--- a/compiler/rustc_middle/src/mir/syntax.rs
+++ b/compiler/rustc_middle/src/mir/syntax.rs
@@ -990,11 +990,19 @@ pub enum Rvalue<'tcx> {
     ///   matching types and return a value of that type.
     BinaryOp(BinOp, Box<(Operand<'tcx>, Operand<'tcx>)>),
 
-    /// Same as `BinaryOp`, but yields `(T, bool)` instead of `T`. In addition to performing the
-    /// same computation as the matching `BinaryOp`, checks if the infinite precison result would be
-    /// unequal to the actual result and sets the `bool` if this is the case.
+    /// Same as `BinaryOp`, but yields `(T, bool)` with a `bool` indicating an error condition.
     ///
-    /// This only supports addition, subtraction, multiplication, and shift operations on integers.
+    /// When overflow checking is disabled, the error condition is false. Otherwise, the error
+    /// condition is determined as described below.
+    ///
+    /// For addition, subtraction, and multiplication on integers the error condition is set when
+    /// the infinite precision result would be unequal to the actual result.
+    ///
+    /// For shift operations on integers the error condition is set when the value of right-hand
+    /// side is greater than or equal to the number of bits in the type of the left-hand side, or
+    /// when the value of right-hand side is negative.
+    ///
+    /// Other combinations of types and operators are unsupported.
     CheckedBinaryOp(BinOp, Box<(Operand<'tcx>, Operand<'tcx>)>),
 
     /// Computes a value as described by the operation.