Skip to content

Fix NonZero TryFrom out-of-range harnesses and add missing conversions - #811

Open
fromtaoyuanhsinchuuuu wants to merge 1 commit into
model-checking:mainfrom
fromtaoyuanhsinchuuuu:fix/nonzero-try-from-harnesses
Open

fromtaoyuanhsinchuuuu wants to merge 1 commit into
model-checking:mainfrom
fromtaoyuanhsinchuuuu:fix/nonzero-try-from-harnesses

Conversation

@fromtaoyuanhsinchuuuu

Copy link
Copy Markdown

Fixes two verification coverage gaps in core::convert::num for Challenge 14 (TryFrom<NonZero<_>>):

  • Replaced the #[kani::should_panic] check_nonzero_int_try_from_nonzero_int_should_panic harness in generate_nonzero_int_try_from_nonzero_int_harness! (which previously admitted v == 0, panicking in NonZero::new(x_inner).unwrap() before try_from was called and missing UB-free wrong-Ok mutants) with a plain #[kani::proof] harness check_nonzero_int_try_from_nonzero_int_out_of_range. It checks non-emptiness of the out-of-range domain, samples v != 0 outside [$target::MIN, $target::MAX], records a kani::cover non-vacuity witness, constructs NonZero::new(x_inner).unwrap(), and asserts NonZero::<$target>::try_from(x).is_err().
  • Added the 23 missing TryFrom<NonZero<_>> harness instantiations (u8 => i8, all 11 from usize, and all 11 from isize) with #[cfg(target_pointer_width = "16" / "32" / "64")] fallible/infallible splits so all 97 impl_nonzero_int_try_from_nonzero_int! conversions are verified for both in-range and out-of-range behavior.
  • Verified with Kani (231 harnesses in convert::num::verify passing, 0 failures) and confirmed via mutation testing that all 86 out-of-range harnesses fail if try_from returns Ok instead of Err.

Resolves #800

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 and MIT licenses.

@fromtaoyuanhsinchuuuu
fromtaoyuanhsinchuuuu requested a review from a team as a code owner December 2, 2026 18:25

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Challenge 14: TryFrom<NonZero<_>> should_panic harnesses cannot detect a UB-free try_from that never returns Err; 23 listed conversions have no harness

1 participant