From 9fb66969e38f1ce4b269f9506faf7ebc161ececa Mon Sep 17 00:00:00 2001 From: Pietro Albini Date: Wed, 27 Oct 2021 16:56:57 +0200 Subject: [PATCH] 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 ``` --- library/core/src/num/uint_macros.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/core/src/num/uint_macros.rs b/library/core/src/num/uint_macros.rs index 18c1353e7c62..691d0891b144 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`.