Skip to content

Commit

Permalink
Fixes Duration constructor const fns other than new, reverts new to n…
Browse files Browse the repository at this point in the history
…on-const.
  • Loading branch information
remexre committed Jan 9, 2018
1 parent 2624c05 commit 7caf753
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions src/libstd/time/duration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ impl Duration {
/// ```
#[stable(feature = "duration", since = "1.3.0")]
#[inline]
pub const fn new(secs: u64, nanos: u32) -> Duration {
pub fn new(secs: u64, nanos: u32) -> Duration {
let secs = secs.checked_add((nanos / NANOS_PER_SEC) as u64)
.expect("overflow in Duration::new");
let nanos = nanos % NANOS_PER_SEC;
Expand Down Expand Up @@ -113,9 +113,10 @@ impl Duration {
#[stable(feature = "duration", since = "1.3.0")]
#[inline]
pub const fn from_millis(millis: u64) -> Duration {
let secs = millis / MILLIS_PER_SEC;
let nanos = ((millis % MILLIS_PER_SEC) as u32) * NANOS_PER_MILLI;
Duration { secs: secs, nanos: nanos }
Duration {
secs: millis / MILLIS_PER_SEC,
nanos: ((millis % MILLIS_PER_SEC) as u32) * NANOS_PER_MILLI,
}
}

/// Creates a new `Duration` from the specified number of microseconds.
Expand All @@ -134,9 +135,10 @@ impl Duration {
#[unstable(feature = "duration_from_micros", issue = "44400")]
#[inline]
pub const fn from_micros(micros: u64) -> Duration {
let secs = micros / MICROS_PER_SEC;
let nanos = ((micros % MICROS_PER_SEC) as u32) * NANOS_PER_MICRO;
Duration { secs: secs, nanos: nanos }
Duration {
secs: micros / MICROS_PER_SEC,
nanos: ((micros % MICROS_PER_SEC) as u32) * NANOS_PER_MICRO,
}
}

/// Creates a new `Duration` from the specified number of nanoseconds.
Expand All @@ -155,9 +157,10 @@ impl Duration {
#[unstable(feature = "duration_extras", issue = "46507")]
#[inline]
pub const fn from_nanos(nanos: u64) -> Duration {
let secs = nanos / (NANOS_PER_SEC as u64);
let nanos = (nanos % (NANOS_PER_SEC as u64)) as u32;
Duration { secs: secs, nanos: nanos }
Duration {
secs: nanos / (NANOS_PER_SEC as u64),
nanos: (nanos % (NANOS_PER_SEC as u64)) as u32,
}
}

/// Returns the number of _whole_ seconds contained by this `Duration`.
Expand Down

0 comments on commit 7caf753

Please sign in to comment.