about summary refs log tree commit diff
diff options
context:
space:
mode:
authorPietro Albini <pietro.albini@ferrous-systems.com>2021-10-27 16:56:57 +0200
committerPietro Albini <pietro.albini@ferrous-systems.com>2021-10-27 17:00:46 +0200
commit9fb66969e38f1ce4b269f9506faf7ebc161ececa (patch)
treed2d909cf1eb177776d924ba420bd4d8539603f2a
parent5913ef6660aa7977d7cbee01b115d8a5e926b893 (diff)
downloadrust-9fb66969e38f1ce4b269f9506faf7ebc161ececa.tar.gz
rust-9fb66969e38f1ce4b269f9506faf7ebc161ececa.zip
replace `|` with `||` in {unsigned_int}::borrowing_sub
Using short-circuiting 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_64 assembly is the same
between the old and new versions:

```
mov eax, edi
add dl, -1
sbb eax, esi
setb dl
ret
```
-rw-r--r--library/core/src/num/uint_macros.rs2
1 files changed, 1 insertions, 1 deletions
diff --git a/library/core/src/num/uint_macros.rs b/library/core/src/num/uint_macros.rs
index 18c1353e7c6..691d0891b14 100644
--- a/library/core/src/num/uint_macros.rs
+++ b/library/core/src/num/uint_macros.rs
@@ -1606,7 +1606,7 @@ macro_rules! uint_impl {
             //   to generate optimal code for now, and LLVM doesn't have an equivalent intrinsic
             let (a, b) = self.overflowing_sub(rhs);
             let (c, d) = a.overflowing_sub(borrow as $SelfT);
-            (c, b | d)
+            (c, b || d)
         }
 
         /// Computes the absolute difference between `self` and `other`.