Skip to content

Commit

Permalink
Clean up the codes a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
ShoyuVanilla committed Dec 23, 2024
1 parent 90c2744 commit 26512c1
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions library/core/src/convert/num.rs
Original file line number Diff line number Diff line change
Expand Up @@ -570,12 +570,10 @@ mod verify {
($Small:ty => $Large:ty, $harness:ident) => {
#[kani::proof]
pub fn $harness() {
let x_inner: $Small = kani::any();
kani::assume(x_inner != 0);

let x = NonZero::new(x_inner).unwrap();
let x: NonZero<$Small> = kani::any();
let y = NonZero::<$Large>::from(x);

let x_inner = <$Small>::from(x);
assert_eq!(x_inner as $Large, <$Large>::from(y));
}
};
Expand Down Expand Up @@ -626,14 +624,16 @@ mod verify {
($source:ty => $target:ty, $harness:ident) => {
#[kani::proof]
pub fn $harness() {
let x_inner: $source = kani::any();
kani::assume(x_inner != 0);

let x = NonZero::new(x_inner).unwrap();
let x: NonZero<$source> = kani::any();
let y = NonZero::<$target>::try_from(x);

// The conversion must succeed if and only if the inner value of source type
// fits into the target type, i.e. inner type conversion succeeds.
let x_inner = <$source>::from(x);
let y_inner = <$target>::try_from(x_inner);
if let Ok(y_inner) = y_inner {
// And the inner value of converted nonzero must be equal to the direct
// conversion result.
assert!(y.is_ok_and(|y| <$target>::from(y) == y_inner));
} else {
assert!(y.is_err());
Expand Down

0 comments on commit 26512c1

Please sign in to comment.