Skip to content

Commit 68a4460

Browse files
committed
replace & with && in {integer}::checked_rem
Using short-circuit operators makes it easier to perform some kinds of source code analysis, like MC/DC code coverage (a requirement in safety-critical environments). The optimized x86 assembly is the same between the old and new versions: ``` xor eax, eax test esi, esi je .LBB0_1 cmp edi, -2147483648 jne .LBB0_4 cmp esi, -1 jne .LBB0_4 ret .LBB0_1: ret .LBB0_4: mov eax, edi cdq idiv esi mov eax, 1 ret ```
1 parent 81130fe commit 68a4460

File tree

1 file changed

+1
-2
lines changed

1 file changed

+1
-2
lines changed

library/core/src/num/int_macros.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -661,8 +661,7 @@ macro_rules! int_impl {
661661
without modifying the original"]
662662
#[inline]
663663
pub const fn checked_rem(self, rhs: Self) -> Option<Self> {
664-
// Using `&` helps LLVM see that it is the same check made in division.
665-
if unlikely!(rhs == 0 || ((self == Self::MIN) & (rhs == -1))) {
664+
if unlikely!(rhs == 0 || ((self == Self::MIN) && (rhs == -1))) {
666665
None
667666
} else {
668667
// SAFETY: div by zero and by INT_MIN have been checked above

0 commit comments

Comments
 (0)