@@ -721,6 +721,7 @@ macro_rules! nonzero_integer {
721721 #[ must_use = "this returns the result of the operation, \
722722 without modifying the original"]
723723 #[ inline( always) ]
724+ #[ ensures( |result| result. get( ) > 0 ) ]
724725 pub const fn count_ones( self ) -> NonZero <u32 > {
725726 // SAFETY:
726727 // `self` is non-zero, which means it has at least one bit set, which means
@@ -754,6 +755,8 @@ macro_rules! nonzero_integer {
754755 #[ must_use = "this returns the result of the operation, \
755756 without modifying the original"]
756757 #[ inline( always) ]
758+ #[ ensures( |result| result. get( ) > 0 ) ]
759+ #[ ensures( |result| result. rotate_right( n) . get( ) == old( self ) . get( ) ) ]
757760 pub const fn rotate_left( self , n: u32 ) -> Self {
758761 let result = self . get( ) . rotate_left( n) ;
759762 // SAFETY: Rotating bits preserves the property int > 0.
@@ -787,6 +790,8 @@ macro_rules! nonzero_integer {
787790 #[ must_use = "this returns the result of the operation, \
788791 without modifying the original"]
789792 #[ inline( always) ]
793+ #[ ensures( |result| result. get( ) > 0 ) ]
794+ #[ ensures( |result| result. rotate_left( n) . get( ) == old( self ) . get( ) ) ]
790795 pub const fn rotate_right( self , n: u32 ) -> Self {
791796 let result = self . get( ) . rotate_right( n) ;
792797 // SAFETY: Rotating bits preserves the property int > 0.
@@ -2571,56 +2576,4 @@ mod verify {
25712576 nonzero_check_clamp_panic ! ( core:: num:: NonZeroU64 , nonzero_check_clamp_panic_for_u64) ;
25722577 nonzero_check_clamp_panic ! ( core:: num:: NonZeroU128 , nonzero_check_clamp_panic_for_u128) ;
25732578 nonzero_check_clamp_panic ! ( core:: num:: NonZeroUsize , nonzero_check_clamp_panic_for_usize) ;
2574-
2575- macro_rules! nonzero_check_count_ones {
2576- ( $nonzero_type: ty, $nonzero_check_count_ones_for: ident) => {
2577- #[ kani:: proof]
2578- pub fn $nonzero_check_count_ones_for( ) {
2579- let x: $nonzero_type = kani:: any( ) ;
2580- let result = x. count_ones( ) ;
2581- // Since x is non-zero, count_ones should never return 0
2582- assert!( result. get( ) > 0 ) ;
2583- }
2584- } ;
2585- }
2586-
2587- // Use the macro to generate different versions of the function for multiple types
2588- nonzero_check_count_ones ! ( core:: num:: NonZeroI8 , nonzero_check_count_ones_for_i8) ;
2589- nonzero_check_count_ones ! ( core:: num:: NonZeroI16 , nonzero_check_count_ones_for_i16) ;
2590- nonzero_check_count_ones ! ( core:: num:: NonZeroI32 , nonzero_check_count_ones_for_i32) ;
2591- nonzero_check_count_ones ! ( core:: num:: NonZeroI64 , nonzero_check_count_ones_for_i64) ;
2592- nonzero_check_count_ones ! ( core:: num:: NonZeroI128 , nonzero_check_count_ones_for_i128) ;
2593- nonzero_check_count_ones ! ( core:: num:: NonZeroIsize , nonzero_check_count_ones_for_isize) ;
2594- nonzero_check_count_ones ! ( core:: num:: NonZeroU8 , nonzero_check_count_ones_for_u8) ;
2595- nonzero_check_count_ones ! ( core:: num:: NonZeroU16 , nonzero_check_count_ones_for_u16) ;
2596- nonzero_check_count_ones ! ( core:: num:: NonZeroU32 , nonzero_check_count_ones_for_u32) ;
2597- nonzero_check_count_ones ! ( core:: num:: NonZeroU64 , nonzero_check_count_ones_for_u64) ;
2598- nonzero_check_count_ones ! ( core:: num:: NonZeroU128 , nonzero_check_count_ones_for_u128) ;
2599- nonzero_check_count_ones ! ( core:: num:: NonZeroUsize , nonzero_check_count_ones_for_usize) ;
2600-
2601- macro_rules! nonzero_check_rotate_left_and_right {
2602- ( $nonzero_type: ty, $nonzero_check_rotate_for: ident) => {
2603- #[ kani:: proof]
2604- pub fn $nonzero_check_rotate_for( ) {
2605- let x: $nonzero_type = kani:: any( ) ;
2606- let n: u32 = kani:: any( ) ;
2607- let result = x. rotate_left( n) . rotate_right( n) ;
2608- assert!( result == x) ;
2609- }
2610- } ;
2611- }
2612-
2613- // Use the macro to generate different versions of the function for multiple types
2614- nonzero_check_rotate_left_and_right ! ( core:: num:: NonZeroI8 , nonzero_check_rotate_for_i8) ;
2615- nonzero_check_rotate_left_and_right ! ( core:: num:: NonZeroI16 , nonzero_check_rotate_for_i16) ;
2616- nonzero_check_rotate_left_and_right ! ( core:: num:: NonZeroI32 , nonzero_check_rotate_for_i32) ;
2617- nonzero_check_rotate_left_and_right ! ( core:: num:: NonZeroI64 , nonzero_check_rotate_for_i64) ;
2618- nonzero_check_rotate_left_and_right ! ( core:: num:: NonZeroI128 , nonzero_check_rotate_for_i128) ;
2619- nonzero_check_rotate_left_and_right ! ( core:: num:: NonZeroIsize , nonzero_check_rotate_for_isize) ;
2620- nonzero_check_rotate_left_and_right ! ( core:: num:: NonZeroU8 , nonzero_check_rotate_for_u8) ;
2621- nonzero_check_rotate_left_and_right ! ( core:: num:: NonZeroU16 , nonzero_check_rotate_for_u16) ;
2622- nonzero_check_rotate_left_and_right ! ( core:: num:: NonZeroU32 , nonzero_check_rotate_for_u32) ;
2623- nonzero_check_rotate_left_and_right ! ( core:: num:: NonZeroU64 , nonzero_check_rotate_for_u64) ;
2624- nonzero_check_rotate_left_and_right ! ( core:: num:: NonZeroU128 , nonzero_check_rotate_for_u128) ;
2625- nonzero_check_rotate_left_and_right ! ( core:: num:: NonZeroUsize , nonzero_check_rotate_for_usize) ;
26262579}
0 commit comments