@@ -570,12 +570,10 @@ mod verify {
570
570
( $Small: ty => $Large: ty, $harness: ident) => {
571
571
#[ kani:: proof]
572
572
pub fn $harness( ) {
573
- let x_inner: $Small = kani:: any( ) ;
574
- kani:: assume( x_inner != 0 ) ;
575
-
576
- let x = NonZero :: new( x_inner) . unwrap( ) ;
573
+ let x: NonZero <$Small> = kani:: any( ) ;
577
574
let y = NonZero :: <$Large>:: from( x) ;
578
575
576
+ let x_inner = <$Small>:: from( x) ;
579
577
assert_eq!( x_inner as $Large, <$Large>:: from( y) ) ;
580
578
}
581
579
} ;
@@ -626,14 +624,16 @@ mod verify {
626
624
( $source: ty => $target: ty, $harness: ident) => {
627
625
#[ kani:: proof]
628
626
pub fn $harness( ) {
629
- let x_inner: $source = kani:: any( ) ;
630
- kani:: assume( x_inner != 0 ) ;
631
-
632
- let x = NonZero :: new( x_inner) . unwrap( ) ;
627
+ let x: NonZero <$source> = kani:: any( ) ;
633
628
let y = NonZero :: <$target>:: try_from( x) ;
634
629
630
+ // The conversion must succeed if and only if the inner value of source type
631
+ // fits into the target type, i.e. inner type conversion succeeds.
632
+ let x_inner = <$source>:: from( x) ;
635
633
let y_inner = <$target>:: try_from( x_inner) ;
636
634
if let Ok ( y_inner) = y_inner {
635
+ // And the inner value of converted nonzero must be equal to the direct
636
+ // conversion result.
637
637
assert!( y. is_ok_and( |y| <$target>:: from( y) == y_inner) ) ;
638
638
} else {
639
639
assert!( y. is_err( ) ) ;
0 commit comments