Skip to content

std::time inconsistencies #48980

Closed
Closed
@debris

Description

@debris

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

No one assigned

    Labels

    A-docsArea: 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.E-mediumCall for participation: Medium difficulty. Experience needed to fix: Intermediate.P-mediumMedium priorityT-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions