-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Makes the constructors of Duration const fns. #47300
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @aidanhs (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. Please see the contribution instructions for more information. |
src/libstd/time/duration.rs
Outdated
@@ -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 { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
It's not possible to have local variables in const fn yet. You'd need to convert everything to expression syntax. |
Yeah, I committed the sin of PR'ing before the tests finished running locally... Should be fixed now? |
src/libstd/time/duration.rs
Outdated
pub const fn from_millis(millis: u64) -> Duration { | ||
Duration { | ||
secs: millis / MILLIS_PER_SEC, | ||
nanos: ((millis % MILLIS_PER_SEC) as u32) * NANOS_PER_MILLI, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You seem to have added literal tabs instead of 4 spaces.
r? @sfackler |
These seem reasonable to me to become const fns. @rfcbot fcp merge |
Team member @sfackler has proposed to merge this. The next step is review by the rest of the tagged teams: No concerns currently listed. Once these reviewers reach consensus, this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up! See this document for info about what commands tagged team members can give me. |
Triage ping, ticky boxes for you! @BurntSushi @Kimundi |
🔔 This is now entering its final comment period, as per the review above. 🔔 |
🔔 This is now entering its final comment period, as per the review above. 🔔 |
@bors: r+ |
📌 Commit c25178c has been approved by |
…alexcrichton Makes the constructors of Duration const fns. This affects `Duration::new`, `Duration::from_secs`, `Duration::from_millis`, `Duration::from_micros`, and `Duration::from_nanos`.
☀️ Test successful - status-appveyor, status-travis |
This affects
Duration::new
,Duration::from_secs
,Duration::from_millis
,Duration::from_micros
, andDuration::from_nanos
.