-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Closed
Labels
A-timeArea: TimeArea: TimeC-bugCategory: This is a bug.Category: This is a bug.E-help-wantedCall for participation: Help is requested to fix this issue.Call for participation: Help is requested to fix this issue.O-AArch64Armv8-A or later processors in AArch64 modeArmv8-A or later processors in AArch64 modeO-macosOperating system: macOSOperating system: macOSP-mediumMedium priorityMedium priorityT-libsRelevant to the library team, which will review and decide on the PR/issue.Relevant to the library team, which will review and decide on the PR/issue.
Description
I tried this code on M1 macOS:
use std::time::{Duration, Instant};
fn main() {
let t0 = Instant::now();
let t1 = t0 + Duration::from_nanos(50);
let d = t1 - t0;
dbg!(t0, t1, d);
assert_eq!(t0 + d, t1);
}
It's expected to succeed.
Instead, this happened:
[src/main.rs:6] t0 = Instant {
t: 147092181000,
}
[src/main.rs:6] t1 = Instant {
t: 147092181001,
}
[src/main.rs:6] d = 41ns
thread 'main' panicked at 'assertion failed: `(left == right)`
left: `Instant { t: 147092181000 }`,
right: `Instant { t: 147092181001 }`', src/main.rs:7:5
It seems that there is something wrong with the Duration -> Instant
casting in Rust std:
rust/library/std/src/sys/unix/time.rs
Lines 227 to 232 in 1d6f242
fn checked_dur2intervals(dur: &Duration) -> Option<u64> { | |
let nanos = | |
dur.as_secs().checked_mul(NSEC_PER_SEC)?.checked_add(dur.subsec_nanos() as u64)?; | |
let info = info(); | |
Some(mul_div_u64(nanos, info.denom as u64, info.numer as u64)) | |
} |
This problem does not exist on x86_64-apple-darwin, because info.denom = info.numer = 1
.
Meta
rustc --version --verbose
:
rustc 1.56.1 (59eed8a2a 2021-11-01)
binary: rustc
commit-hash: 59eed8a2aac0230a8b53e89d4e99d55912ba6b35
commit-date: 2021-11-01
host: aarch64-apple-darwin
release: 1.56.1
LLVM version: 13.0.0
lyinch
Metadata
Metadata
Assignees
Labels
A-timeArea: TimeArea: TimeC-bugCategory: This is a bug.Category: This is a bug.E-help-wantedCall for participation: Help is requested to fix this issue.Call for participation: Help is requested to fix this issue.O-AArch64Armv8-A or later processors in AArch64 modeArmv8-A or later processors in AArch64 modeO-macosOperating system: macOSOperating system: macOSP-mediumMedium priorityMedium priorityT-libsRelevant to the library team, which will review and decide on the PR/issue.Relevant to the library team, which will review and decide on the PR/issue.