-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Closed
Labels
A-docsArea: Documentation for any part of the project, including the compiler, standard library, and toolsArea: Documentation for any part of the project, including the compiler, standard library, and toolsC-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.E-mediumCall for participation: Medium difficulty. Experience needed to fix: Intermediate.Call for participation: Medium difficulty. Experience needed to fix: Intermediate.P-mediumMedium priorityMedium priorityT-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.Relevant to the library API team, which will review and decide on the PR/issue.
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
stanislav-tkach, vitvakatu, jennazenk, 0x7CFE and natembennettstanislav-tkach
Metadata
Metadata
Assignees
Labels
A-docsArea: Documentation for any part of the project, including the compiler, standard library, and toolsArea: Documentation for any part of the project, including the compiler, standard library, and toolsC-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.E-mediumCall for participation: Medium difficulty. Experience needed to fix: Intermediate.Call for participation: Medium difficulty. Experience needed to fix: Intermediate.P-mediumMedium priorityMedium priorityT-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.Relevant to the library API team, which will review and decide on the PR/issue.