Skip to content

Commit 469d6a8

Browse files
committed
fix(core): update doctest; address pr(rust-lang#139243) comments
1 parent c907535 commit 469d6a8

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

library/core/src/time.rs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -308,31 +308,32 @@ impl Duration {
308308
Duration { secs, nanos: subsec_nanos }
309309
}
310310

311-
/// Creates a new Duration from the specified number of nanoseconds.
311+
/// Creates a new `Duration` from the specified number of nanoseconds.
312312
///
313313
/// # Panics
314314
///
315-
/// Panics if the given number of nanoseconds is greater than what Duration can handle,
316-
/// which is `(u64::MAX * NANOS_PER_SEC) + NANOS_PER_SEC - 1`
317-
/// Use this function if you need to specify time greater than what can fit in u64
318-
/// (around 584 years).
315+
/// Panics if the given number of nanoseconds is greater than [`Duration::MAX`].
319316
///
320317
/// # Examples
321318
///
322319
/// ```
323320
/// #![feature(duration_from_nanos_u128)]
324321
/// use std::time::Duration;
325-
/// let time_in_nanos = 2u128.pow(64);
326-
/// let duration = Duration::from_nanos_u128(time_in_nanos);
322+
///
323+
/// let duration = Duration::from_nanos_u128(1_000_000_321);
324+
///
325+
/// assert_eq!(1, duration.as_secs());
326+
/// assert_eq!(321, duration.subsec_nanos());
327327
/// ```
328328
#[unstable(feature = "duration_from_nanos_u128", issue = "139201")]
329329
#[must_use]
330330
#[inline]
331+
#[track_caller]
331332
pub const fn from_nanos_u128(nanos: u128) -> Duration {
332333
const NANOS_PER_SEC: u128 = self::NANOS_PER_SEC as u128;
333334
let secs: u128 = nanos / NANOS_PER_SEC;
334335
if secs > u64::MAX as u128 {
335-
panic!("overflow in duration in Duration::from_nanos_u128");
336+
panic!("overflow in `Duration::from_nanos_u128`");
336337
}
337338
let subsec_nanos = (nanos % NANOS_PER_SEC) as u32;
338339
// SAFETY: x % 1_000_000_000 < 1_000_000_000 also, subsec_nanos >= 0 since u128 >=0 and u32 >=0

0 commit comments

Comments
 (0)