Closed
Description
When investigating one of the issues in parity-ethereum repo I noticed several inconsistencies in std::time
.
I prepared two short snippets
snippet A
use std::time::{Instant, Duration};
fn main() {
let now = Instant::now();
let max_nanoseconds = u64::max_value() / 1_000_000_000;
let duration = Duration::new(max_nanoseconds, 0);
println!("{:?}", now + duration);
}
snippet B
use std::time::{Instant, Duration};
fn main() {
let now = Instant::now();
let max_nanoseconds = u64::max_value() / 1_000_000_000 + 1;
let duration = Duration::new(max_nanoseconds, 0);
println!("{:?}", now + duration);
}
Both of the attached snippets are properly executed on linux (gist), but they panic on macos.
snippet A panics with 'overflow when adding duration to instant'
snippet B panics with 'overflow converting duration to nanoseconds'
This is an inconsistent behaviour of standard library and I believe that above snippets should panic (or work) on all platforms in the same way
Metadata
Metadata
Assignees
Labels
Area: Documentation for any part of the project, including the compiler, standard library, and toolsCategory: An issue proposing an enhancement or a PR with one.Call for participation: Medium difficulty. Experience needed to fix: Intermediate.Medium priorityRelevant to the library API team, which will review and decide on the PR/issue.