@@ -1687,6 +1687,19 @@ mod verify {
16871687 }
16881688 }
16891689
1690+ // Verify `wrapping_{shl, shr}` which internally uses `unchecked_{shl,shr}`
1691+ macro_rules! generate_wrapping_shift_harness {
1692+ ( $type: ty, $method: ident, $harness_name: ident) => {
1693+ #[ kani:: proof_for_contract( $type:: $method) ]
1694+ pub fn $harness_name( ) {
1695+ let num1: $type = kani:: any:: <$type>( ) ;
1696+ let num2: u32 = kani:: any:: <u32 >( ) ;
1697+
1698+ let _ = num1. $method( num2) ;
1699+ }
1700+ }
1701+ }
1702+
16901703 // `unchecked_add` proofs
16911704 //
16921705 // Target types:
@@ -1905,4 +1918,29 @@ mod verify {
19051918 widening_mul_u64_large, u64 :: MAX - 10u64 , u64 :: MAX ,
19061919 widening_mul_u64_mid_edge, ( u64 :: MAX / 2 ) - 10u64 , ( u64 :: MAX / 2 ) + 10u64
19071920 ) ;
1921+
1922+ // `wrapping_shl` proofs
1923+ //
1924+ // Target types:
1925+ // i{8,16,32,64,128,size} and u{8,16,32,64,128,size} -- 12 types in total
1926+ //
1927+ // Target contracts:
1928+ // #[ensures(|result| *result == self << (rhs & (Self::BITS - 1)))]
1929+ //
1930+ // Target function:
1931+ // pub const fn wrapping_shl(self, rhs: u32) -> Self
1932+ //
1933+ // This function performs an panic-free bitwise left shift operation.
1934+ generate_wrapping_shift_harness ! ( i8 , wrapping_shl, checked_wrapping_shl_i8) ;
1935+ generate_wrapping_shift_harness ! ( i16 , wrapping_shl, checked_wrapping_shl_i16) ;
1936+ generate_wrapping_shift_harness ! ( i32 , wrapping_shl, checked_wrapping_shl_i32) ;
1937+ generate_wrapping_shift_harness ! ( i64 , wrapping_shl, checked_wrapping_shl_i64) ;
1938+ generate_wrapping_shift_harness ! ( i128 , wrapping_shl, checked_wrapping_shl_i128) ;
1939+ generate_wrapping_shift_harness ! ( isize , wrapping_shl, checked_wrapping_shl_isize) ;
1940+ generate_wrapping_shift_harness ! ( u8 , wrapping_shl, checked_wrapping_shl_u8) ;
1941+ generate_wrapping_shift_harness ! ( u16 , wrapping_shl, checked_wrapping_shl_u16) ;
1942+ generate_wrapping_shift_harness ! ( u32 , wrapping_shl, checked_wrapping_shl_u32) ;
1943+ generate_wrapping_shift_harness ! ( u64 , wrapping_shl, checked_wrapping_shl_u64) ;
1944+ generate_wrapping_shift_harness ! ( u128 , wrapping_shl, checked_wrapping_shl_u128) ;
1945+ generate_wrapping_shift_harness ! ( usize , wrapping_shl, checked_wrapping_shl_usize) ;
19081946}
0 commit comments