Skip to content

Commit adb37d4

Browse files
committed
Clarify when MIR Div/Rem trigger UB
1 parent 73f104b commit adb37d4

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

compiler/rustc_middle/src/mir/syntax.rs

+9-4
Original file line numberDiff line numberDiff line change
@@ -1272,13 +1272,18 @@ pub enum BinOp {
12721272
Mul,
12731273
/// The `/` operator (division)
12741274
///
1275-
/// Division by zero is UB, because the compiler should have inserted checks
1276-
/// prior to this.
1275+
/// For integer types, division by zero is UB, as is `MIN / -1` for signed.
1276+
/// The compiler should have inserted checks prior to this.
1277+
///
1278+
/// Floating-point division by zero is safe, and does not need guards.
12771279
Div,
12781280
/// The `%` operator (modulus)
12791281
///
1280-
/// Using zero as the modulus (second operand) is UB, because the compiler
1281-
/// should have inserted checks prior to this.
1282+
/// For integer types, using zero as the modulus (second operand) is UB,
1283+
/// as is `MIN % -1` for signed.
1284+
/// The compiler should have inserted checks prior to this.
1285+
///
1286+
/// Floating-point remainder by zero is safe, and does not need guards.
12821287
Rem,
12831288
/// The `^` operator (bitwise xor)
12841289
BitXor,

0 commit comments

Comments
 (0)