Skip to content

Commit e6c9c8d

Browse files
committed
Add contracts that require contract variables
These are now expressible thanks to aeae085.
1 parent 919d34a commit e6c9c8d

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

library/core/src/num/nonzero.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -817,6 +817,10 @@ macro_rules! nonzero_integer {
817817
#[must_use = "this returns the result of the operation, \
818818
without modifying the original"]
819819
#[inline(always)]
820+
#[rustc_allow_const_fn_unstable(contracts)]
821+
#[core::contracts::requires(let old : NonZero<$Int> = self; true)]
822+
#[core::contracts::ensures(
823+
move |result: &NonZero<$Int>| result.rotate_right(n).get() == old.get())]
820824
pub const fn rotate_left(self, n: u32) -> Self {
821825
let result = self.get().rotate_left(n);
822826
// SAFETY: Rotating bits preserves the property int > 0.
@@ -848,6 +852,10 @@ macro_rules! nonzero_integer {
848852
#[must_use = "this returns the result of the operation, \
849853
without modifying the original"]
850854
#[inline(always)]
855+
#[rustc_allow_const_fn_unstable(contracts)]
856+
#[core::contracts::requires(let old : NonZero<$Int> = self; true)]
857+
#[core::contracts::ensures(
858+
move |result: &NonZero<$Int>| result.rotate_left(n).get() == old.get())]
851859
pub const fn rotate_right(self, n: u32) -> Self {
852860
let result = self.get().rotate_right(n);
853861
// SAFETY: Rotating bits preserves the property int > 0.

0 commit comments

Comments
 (0)