-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Tracking Issue for constify-ing non-trait Duration
methods
#72440
Comments
I also would like to add a |
I don't think so -- adding a new constant seems pretty orthogonal to me. |
It's orthogonal but depends on |
FWIW, #72449 makes the other safe |
All right, #72449 will make |
Great! I'll wait for #72449 to land and update my PR accordingly. |
The tracking issue should also notice that stabilizing any of the |
Duration
methodsDuration
methods
…i-obk Constify most non-trait `Duration` methods as described in rust-lang#72440 The remaining methods could probably be made const once rust-lang#72449 lands with support for `f<32|64>::is_finite()`.
…i-obk Constify most non-trait `Duration` methods as described in rust-lang#72440 The remaining methods could probably be made const once rust-lang#72449 lands with support for `f<32|64>::is_finite()`.
Constify most non-trait `Duration` methods as described in rust-lang#72440 The remaining methods could probably be made const once rust-lang#72449 lands with support for `f<32|64>::is_finite()`.
Make the following methods of `Duration` unstable const under `duration_const_2`: - `from_secs_f64` - `from_secs_f32` - `mul_f64` - `mul_f32` - `div_f64` - `div_f32` This results in all methods of `Duration` being (unstable) const. Also adds tests for these methods in a const context, moved the test to `library` as part of rust-lang#76268. Possible because of rust-lang#72449, which made the relevant `f32` and `f64` methods const. Tracking issue: rust-lang#72440
…orse Make all methods of `Duration` unstably const Make the following methods of `Duration` unstable const under `duration_const_2`: - `from_secs_f64` - `from_secs_f32` - `mul_f64` - `mul_f32` - `div_f64` - `div_f32` This results in all methods of `Duration` being (unstable) const. Moved the tests to `library` as part of rust-lang#76268. Possible because of rust-lang#72449, which made the relevant `f32` and `f64` methods const. Tracking issue: rust-lang#72440 r? @ecstatic-morse
…orse Make all methods of `Duration` unstably const Make the following methods of `Duration` unstable const under `duration_const_2`: - `from_secs_f64` - `from_secs_f32` - `mul_f64` - `mul_f32` - `div_f64` - `div_f32` This results in all methods of `Duration` being (unstable) const. Moved the tests to `library` as part of rust-lang#76268. Possible because of rust-lang#72449, which made the relevant `f32` and `f64` methods const. Tracking issue: rust-lang#72440 r? @ecstatic-morse
…orse Make all methods of `Duration` unstably const Make the following methods of `Duration` unstable const under `duration_const_2`: - `from_secs_f64` - `from_secs_f32` - `mul_f64` - `mul_f32` - `div_f64` - `div_f32` This results in all methods of `Duration` being (unstable) const. Moved the tests to `library` as part of rust-lang#76268. Possible because of rust-lang#72449, which made the relevant `f32` and `f64` methods const. Tracking issue: rust-lang#72440 r? @ecstatic-morse
…orse Make all methods of `Duration` unstably const Make the following methods of `Duration` unstable const under `duration_const_2`: - `from_secs_f64` - `from_secs_f32` - `mul_f64` - `mul_f32` - `div_f64` - `div_f32` This results in all methods of `Duration` being (unstable) const. Moved the tests to `library` as part of rust-lang#76268. Possible because of rust-lang#72449, which made the relevant `f32` and `f64` methods const. Tracking issue: rust-lang#72440 r? @ecstatic-morse
…on-try-from-secs-float, r=dtolnay Stabilize `duration_checked_float` ## Stabilization Report This stabilization report is for a stabilization of `duration_checked_float`, tracking issue: rust-lang#83400. ### Implementation History - rust-lang#82179 - rust-lang#90247 - rust-lang#96051 - Changed error type to `FromFloatSecsError` in rust-lang#90247 - rust-lang#96051 changes the rounding mode to round-to-nearest instead of truncate. ## API Summary This stabilization report proposes the following API to be stabilized in `core`, along with their re-exports in `std`: ```rust // core::time impl Duration { pub const fn try_from_secs_f32(secs: f32) -> Result<Duration, TryFromFloatSecsError>; pub const fn try_from_secs_f64(secs: f64) -> Result<Duration, TryFromFloatSecsError>; } #[derive(Debug, Clone, PartialEq, Eq)] pub struct TryFromFloatSecsError { ... } impl core::fmt::Display for TryFromFloatSecsError { ... } impl core::error::Error for TryFromFloatSecsError { ... } ``` These functions are made const unstable under `duration_consts_float`, tracking issue rust-lang#72440. There is an open question in the tracking issue around what the error type should be called which I was hoping to resolve in the context of an FCP. In this stabilization PR, I have altered the name of the error type to `TryFromFloatSecsError`. In my opinion, the error type shares the name of the method (adjusted to accommodate both types of floats), which is consistent with other error types in `core`, `alloc` and `std` like `TryReserveError` and `TryFromIntError`. ## Experience Report Code such as this is ready to be converted to a checked API to ensure it is panic free: ```rust impl Time { pub fn checked_add_f64(&self, seconds: f64) -> Result<Self, TimeError> { // Fail safely during `f64` conversion to duration if seconds.is_nan() || seconds.is_infinite() { return Err(TzOutOfRangeError::new().into()); } if seconds.is_sign_positive() { self.checked_add(Duration::from_secs_f64(seconds)) } else { self.checked_sub(Duration::from_secs_f64(-seconds)) } } } ``` See: artichoke/artichoke#2194. `@rustbot` label +T-libs-api -T-libs cc `@mbartlett21`
…on-try-from-secs-float, r=dtolnay Stabilize `duration_checked_float` ## Stabilization Report This stabilization report is for a stabilization of `duration_checked_float`, tracking issue: rust-lang#83400. ### Implementation History - rust-lang#82179 - rust-lang#90247 - rust-lang#96051 - Changed error type to `FromFloatSecsError` in rust-lang#90247 - rust-lang#96051 changes the rounding mode to round-to-nearest instead of truncate. ## API Summary This stabilization report proposes the following API to be stabilized in `core`, along with their re-exports in `std`: ```rust // core::time impl Duration { pub const fn try_from_secs_f32(secs: f32) -> Result<Duration, TryFromFloatSecsError>; pub const fn try_from_secs_f64(secs: f64) -> Result<Duration, TryFromFloatSecsError>; } #[derive(Debug, Clone, PartialEq, Eq)] pub struct TryFromFloatSecsError { ... } impl core::fmt::Display for TryFromFloatSecsError { ... } impl core::error::Error for TryFromFloatSecsError { ... } ``` These functions are made const unstable under `duration_consts_float`, tracking issue rust-lang#72440. There is an open question in the tracking issue around what the error type should be called which I was hoping to resolve in the context of an FCP. In this stabilization PR, I have altered the name of the error type to `TryFromFloatSecsError`. In my opinion, the error type shares the name of the method (adjusted to accommodate both types of floats), which is consistent with other error types in `core`, `alloc` and `std` like `TryReserveError` and `TryFromIntError`. ## Experience Report Code such as this is ready to be converted to a checked API to ensure it is panic free: ```rust impl Time { pub fn checked_add_f64(&self, seconds: f64) -> Result<Self, TimeError> { // Fail safely during `f64` conversion to duration if seconds.is_nan() || seconds.is_infinite() { return Err(TzOutOfRangeError::new().into()); } if seconds.is_sign_positive() { self.checked_add(Duration::from_secs_f64(seconds)) } else { self.checked_sub(Duration::from_secs_f64(-seconds)) } } } ``` See: artichoke/artichoke#2194. ``@rustbot`` label +T-libs-api -T-libs cc ``@mbartlett21``
Didn't see this mentioned anywhere with a quick search, but Is |
Looking at this closer today, the The |
…, r=scottmcm Implement `Duration::as_millis_{f64,f32}` Implementation of rust-lang#122451. Linked const-unstability to rust-lang#72440, so the post there should probably be updated to mentions the 2 new methods when/if this PR is merged.
Rollup merge of rust-lang#122479 - GrigorenkoPV:duration_millis_float, r=scottmcm Implement `Duration::as_millis_{f64,f32}` Implementation of rust-lang#122451. Linked const-unstability to rust-lang#72440, so the post there should probably be updated to mentions the 2 new methods when/if this PR is merged.
@rust-lang/libs-api With #57241 being stable now, I think we can proceed with stabilizing these as well? :) EDIT: I updated the function list; some things listed there were actually not even unstably const any more. |
Team member @dtolnay has proposed to merge this. The next step is review by the rest of the tagged team members: No concerns currently listed. Once a majority of reviewers approve (and at most 2 approvals are outstanding), 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. |
🔔 This is now entering its final comment period, as per the review above. 🔔 |
The final comment period, with a disposition to merge, as per the review above, is now complete. As the automated representative of the governance process, I would like to thank the author for their work and everyone else who contributed. This will be merged soon. |
Rollup merge of rust-lang#131289 - RalfJung:duration_consts_float, r=tgross35 stabilize duration_consts_float Waiting for FCP in rust-lang#72440 to pass. `as_millis_f32` and `as_millis_f64` are not stable at all yet, so I moved their const-stability together with their regular stability (tracked at rust-lang#122451). Fixes rust-lang#72440
stabilize duration_consts_float Waiting for FCP in rust-lang/rust#72440 to pass. `as_millis_f32` and `as_millis_f64` are not stable at all yet, so I moved their const-stability together with their regular stability (tracked at rust-lang/rust#122451). Fixes rust-lang/rust#72440
This is a tracking issue for constify-ing non-trait
Duration
methodsThe feature gates for the issueis
#![feature(duration_consts_float)]
. The methods covered by that are:Duration::as_secs_f64
Duration::as_secs_f32
Duration::as_millis_f64
Duration::as_millis_f32
Duration::div_duration_f64
Duration::div_duration_f32
Steps
Unresolved Questions
XXX --- list all the "unresolved questions" found in the RFC to ensure they are
not forgotten
Implementation history
Duration
methods as described: Constify most non-traitDuration
methods as described in #72440 #72481Duration
unstably const #76335duration_consts_2
#89542The text was updated successfully, but these errors were encountered: