about summary refs log tree commit diff
diff options
context:
space:
mode:
authorScott McMurray <scottmcm@users.noreply.github.com>2023-06-01 18:52:11 -0700
committerScott McMurray <scottmcm@users.noreply.github.com>2023-06-01 18:52:11 -0700
commitadb37d4999cbb83bd670bb767b3c8d08e43e3c7c (patch)
tree112db173cbd4ffce8d7686114d5bd4197ecbe0e5
parent73f104b6d6d5ae058a06a0f8eec3f370093e91a4 (diff)
downloadrust-adb37d4999cbb83bd670bb767b3c8d08e43e3c7c.tar.gz
rust-adb37d4999cbb83bd670bb767b3c8d08e43e3c7c.zip
Clarify when MIR `Div`/`Rem` trigger UB
-rw-r--r--compiler/rustc_middle/src/mir/syntax.rs13
1 files changed, 9 insertions, 4 deletions
diff --git a/compiler/rustc_middle/src/mir/syntax.rs b/compiler/rustc_middle/src/mir/syntax.rs
index 3e474c1d377..94a1e9ced77 100644
--- a/compiler/rustc_middle/src/mir/syntax.rs
+++ b/compiler/rustc_middle/src/mir/syntax.rs
@@ -1272,13 +1272,18 @@ pub enum BinOp {
     Mul,
     /// The `/` operator (division)
     ///
-    /// Division by zero is UB, because the compiler should have inserted checks
-    /// prior to this.
+    /// For integer types, division by zero is UB, as is `MIN / -1` for signed.
+    /// The compiler should have inserted checks prior to this.
+    ///
+    /// Floating-point division by zero is safe, and does not need guards.
     Div,
     /// The `%` operator (modulus)
     ///
-    /// Using zero as the modulus (second operand) is UB, because the compiler
-    /// should have inserted checks prior to this.
+    /// For integer types, using zero as the modulus (second operand) is UB,
+    /// as is `MIN % -1` for signed.
+    /// The compiler should have inserted checks prior to this.
+    ///
+    /// Floating-point remainder by zero is safe, and does not need guards.
     Rem,
     /// The `^` operator (bitwise xor)
     BitXor,