@@ -388,6 +388,30 @@ impl Step for PageTableIndex {
388388 let idx = usize:: from ( start) . checked_sub ( count) ?;
389389 Some ( Self :: new ( idx as u16 ) )
390390 }
391+
392+ // Kani's bundled toolchain predates these methods being added to `Step`.
393+ // Exclude them there so the crate still compiles under `cargo kani`.
394+ // This can be removed once Kani upgrades its bundled toolchain to nightly-2026-07-10 or later.
395+ #[ cfg( not( kani) ) ]
396+ #[ inline]
397+ fn forward_overflowing ( start : Self , count : usize ) -> ( Self , bool ) {
398+ match Self :: forward_checked ( start, count) {
399+ Some ( next) => ( next, false ) ,
400+ None => ( start, true ) ,
401+ }
402+ }
403+
404+ // Kani's bundled toolchain predates these methods being added to `Step`.
405+ // Exclude them there so the crate still compiles under `cargo kani`.
406+ // This can be removed once Kani upgrades its bundled toolchain to nightly-2026-07-10 or later.
407+ #[ cfg( not( kani) ) ]
408+ #[ inline]
409+ fn backward_overflowing ( start : Self , count : usize ) -> ( Self , bool ) {
410+ match Self :: backward_checked ( start, count) {
411+ Some ( next) => ( next, false ) ,
412+ None => ( start, true ) ,
413+ }
414+ }
391415}
392416
393417/// A 12-bit offset into a 4KiB Page.
@@ -485,3 +509,25 @@ impl PageTableLevel {
485509 1u64 << ( ( ( self as u8 - 1 ) * 9 ) + 12 )
486510 }
487511}
512+
513+ #[ cfg( all( test, feature = "step_trait" ) ) ]
514+ mod tests {
515+ use super :: * ;
516+ use core:: iter:: Step ;
517+
518+ #[ test]
519+ fn page_table_index_step_overflowing ( ) {
520+ assert_eq ! (
521+ Step :: forward_overflowing( PageTableIndex :: new( 0 ) , 511 ) ,
522+ ( PageTableIndex :: new( 511 ) , false )
523+ ) ;
524+ assert_eq ! (
525+ Step :: backward_overflowing( PageTableIndex :: new( 511 ) , 511 ) ,
526+ ( PageTableIndex :: new( 0 ) , false )
527+ ) ;
528+
529+ // Overflow the 0..512 range: only the flag is specified.
530+ assert ! ( Step :: forward_overflowing( PageTableIndex :: new( 511 ) , 1 ) . 1 ) ;
531+ assert ! ( Step :: backward_overflowing( PageTableIndex :: new( 0 ) , 1 ) . 1 ) ;
532+ }
533+ }
0 commit comments