Skip to content

Detect SystemTime overflow in debug mode #42622

Closed
@dtolnay

Description

@dtolnay
use std::time::{Duration, UNIX_EPOCH};
use std::u64;

fn main() {
    let t = UNIX_EPOCH + Duration::new(u64::MAX, 0) + Duration::new(2, 0);
    println!("{}", t.duration_since(UNIX_EPOCH).unwrap().as_secs()); // 1
}

For me (Linux + Rust 1.19.0-nightly) this program prints 1. In debug mode I would expect this overflow to be caught and panic, similar to u64::MAX + 2.

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-enhancementCategory: An issue proposing an enhancement or a PR with one.T-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