Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Makes the constructors of Duration const fns. #47300

Merged
merged 3 commits into from
Jan 24, 2018
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 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 fn new(secs: u64, nanos: u32) -> Duration {
pub const fn new(secs: u64, nanos: u32) -> Duration {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think checked_add and expect are const fn yet and can't be made const fn yet

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ugh, I'll remove new from the PR then.

let secs = secs.checked_add((nanos / NANOS_PER_SEC) as u64)
.expect("overflow in Duration::new");
let nanos = nanos % NANOS_PER_SEC;
Expand All @@ -94,7 +94,7 @@ impl Duration {
/// ```
#[stable(feature = "duration", since = "1.3.0")]
#[inline]
pub fn from_secs(secs: u64) -> Duration {
pub const fn from_secs(secs: u64) -> Duration {
Duration { secs: secs, nanos: 0 }
}

Expand All @@ -112,7 +112,7 @@ impl Duration {
/// ```
#[stable(feature = "duration", since = "1.3.0")]
#[inline]
pub fn from_millis(millis: u64) -> Duration {
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 }
Expand All @@ -133,7 +133,7 @@ impl Duration {
/// ```
#[unstable(feature = "duration_from_micros", issue = "44400")]
#[inline]
pub fn from_micros(micros: u64) -> Duration {
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 }
Expand All @@ -154,7 +154,7 @@ impl Duration {
/// ```
#[unstable(feature = "duration_extras", issue = "46507")]
#[inline]
pub fn from_nanos(nanos: u64) -> Duration {
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 }
Expand Down