Repository navigation
Strengthen Duration::from_secs contract to exclude fractional seconds - #658
Conversation
|
Note: reviewed as part of Ch9 triage. This PR is a narrow but sound contract hardening (adds |
|
Thanks for the review. This PR is already ready for review (marked ready on August 29). I rechecked the current head, I agree that this is contract hardening rather than a Ch9 solution. The matching constructors would be a separate follow-up so this PR stays focused. |
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues are reported for the strengthened whole-seconds contract of Duration::from_secs.
No open issues 🎉
What changed in this PR
Strengthens the verification contract for Duration::from_secs to capture its whole-seconds semantics, addressing the contract-strength concern discussed in #630.
Changes:
- Adds a postcondition requiring zero subsecond nanoseconds.
- Preserves the existing guarantees and leaves the standard-library implementation unchanged.
| File | Description |
|---|---|
library/core/src/time.rs |
Requires Duration::from_secs to return a duration with no fractional seconds. |
Review effort: Balanced
9104a6b
Summary
Duration::from_secsto return zero subsecond nanoseconds.Motivation
The current contract guarantees that the result is representation-safe and that its
secsfield equals the input, but it does not constrain the fractional component. An implementation can therefore preservesecs, add any valid number of nanoseconds, and still satisfy the contract.The new clause captures the documented whole-seconds semantics:
#[ensures(|duration| duration.nanos.as_inner() == 0)]Mutation evidence
The mutation kill rate increases from 0/3 to 3/3. The contract harnesses use unconstrained
u64inputs, nokani::assume, and a separate cover check reachesu64::MAX.Validation
MUTATION_MATRIX=PASSresult.nanos == 0cargo fmt --check: passedgit diff --check: passedThe production diff is contract-only and adds no precondition or runtime behavior change.
Related to the contract-strength discussion in #630.
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 and MIT licenses.