Skip to content

Commit 26512c1

Browse files
committed
Clean up the codes a bit
1 parent 90c2744 commit 26512c1

File tree

1 file changed

+8
-8
lines changed
  • library/core/src/convert

1 file changed

+8
-8
lines changed

library/core/src/convert/num.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -570,12 +570,10 @@ mod verify {
570570
($Small:ty => $Large:ty, $harness:ident) => {
571571
#[kani::proof]
572572
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();
577574
let y = NonZero::<$Large>::from(x);
578575

576+
let x_inner = <$Small>::from(x);
579577
assert_eq!(x_inner as $Large, <$Large>::from(y));
580578
}
581579
};
@@ -626,14 +624,16 @@ mod verify {
626624
($source:ty => $target:ty, $harness:ident) => {
627625
#[kani::proof]
628626
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();
633628
let y = NonZero::<$target>::try_from(x);
634629

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);
635633
let y_inner = <$target>::try_from(x_inner);
636634
if let Ok(y_inner) = y_inner {
635+
// And the inner value of converted nonzero must be equal to the direct
636+
// conversion result.
637637
assert!(y.is_ok_and(|y| <$target>::from(y) == y_inner));
638638
} else {
639639
assert!(y.is_err());

0 commit comments

Comments
 (0)