Tracking Issue for constify-ing non-trait `Duration` methods
marmeladema opened this issue ยท 14 comments
This is a tracking issue for constify-ing non-trait Duration
methods
The 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
- Adjust documentation (see instructions on rustc-dev-guide)
- Stabilization PR (see instructions on rustc-dev-guide)
Unresolved Questions
XXX --- list all the "unresolved questions" found in the RFC to ensure they are
not forgotten
Implementation history
I also would like to add a Duration::MAX
associated const. Should it be part of the same tracking issue?
I don't think so -- adding a new constant seems pretty orthogonal to me.
I don't think so -- adding a new constant seems pretty orthogonal to me.
It's orthogonal but depends on Duration::new
being const so I thought having a tracking issue just for one associated const might be overkill.
Because they end up calling f32|64::is_finite which ultimately call mem::transmute which is not const.
FWIW, #72449 makes the other safe transmute
wrappers const. Once that lands, abs_private
and is_finite
could also be made const.
All right, #72449 will make is_finite
const as well, so you should be able to use that.
Great! I'll wait for #72449 to land and update my PR accordingly.
The tracking issue should also notice that stabilizing any of the f32
/f64
methods is blocked on stabilizing floating point in const at all (#57241).
Didn't see this mentioned anywhere with a quick search, but Duration::from_secs_f64
is not const
anymore?
Is #![feature(duration_consts_float)]
no-op now?
Didn't see this mentioned anywhere with a quick search, but
Duration::from_secs_f64
is notconst
anymore?Is
#![feature(duration_consts_float)]
no-op now?
Looking at this closer today, the from_*
and try_from_*
float functions were no longer
const
after #110393. That's because the try_from_secs
macro makes use of $int_ty::from($expr)
, the trait impls of which are no longer const
.
The from
calls can be replaced with ($expr as $int_ty)
if it is desired to restore the const
impls.
@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.
@rfcbot fcp merge
const
for these 6 already-stable Duration methods, unblocked by #128596 in Rust 1.82 (current beta).
- https://doc.rust-lang.org/nightly/core/time/struct.Duration.html#method.as_secs_f64
- https://doc.rust-lang.org/nightly/core/time/struct.Duration.html#method.as_secs_f32
- https://doc.rust-lang.org/nightly/core/time/struct.Duration.html#method.as_millis_f64
- https://doc.rust-lang.org/nightly/core/time/struct.Duration.html#method.as_millis_f32
- https://doc.rust-lang.org/nightly/core/time/struct.Duration.html#method.div_duration_f64
- https://doc.rust-lang.org/nightly/core/time/struct.Duration.html#method.div_duration_f32
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. ๐