about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--library/core/src/num/uint_macros.rs7
1 files changed, 7 insertions, 0 deletions
diff --git a/library/core/src/num/uint_macros.rs b/library/core/src/num/uint_macros.rs
index 565fc1930ea..f2190efa4d3 100644
--- a/library/core/src/num/uint_macros.rs
+++ b/library/core/src/num/uint_macros.rs
@@ -2017,6 +2017,13 @@ macro_rules! uint_impl {
                 one >>= 2;
             }
 
+            // SAFETY: the result is positive and fits in an integer with half as many bits.
+            // Inform the optimizer about it.
+            unsafe {
+                intrinsics::assume(0 < res);
+                intrinsics::assume(res < 1 << (Self::BITS / 2));
+            }
+
             res
         }