rust-lang/rust

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

Unresolved Questions

XXX --- list all the "unresolved questions" found in the RFC to ensure they are
not forgotten

Implementation history

  • Constify most non-trait Duration methods as described: #72481
  • Make all methods of Duration unstably const: #76335
  • Partially stabilize duration_consts_2: #89542

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).

PR stabilizing non-float methods is up: #89542

MoSal commented

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?

MoSal commented

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?

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.

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.

rfcbot commented

๐Ÿ”” This is now entering its final comment period, as per the review above. ๐Ÿ””