Skip to content

Stabilize duration_abs_diff #127128

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

Merged
merged 1 commit into from
Jul 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
5 changes: 3 additions & 2 deletions library/core/src/time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -620,13 +620,14 @@ impl Duration {
/// Basic usage:
///
/// ```
/// #![feature(duration_abs_diff)]
/// use std::time::Duration;
///
/// assert_eq!(Duration::new(100, 0).abs_diff(Duration::new(80, 0)), Duration::new(20, 0));
/// assert_eq!(Duration::new(100, 400_000_000).abs_diff(Duration::new(110, 0)), Duration::new(9, 600_000_000));
/// ```
#[unstable(feature = "duration_abs_diff", issue = "117618")]
#[stable(feature = "duration_abs_diff", since = "CURRENT_RUSTC_VERSION")]
#[rustc_const_stable(feature = "duration_abs_diff", since = "CURRENT_RUSTC_VERSION")]
#[rustc_allow_const_fn_unstable(const_option)]
#[must_use = "this returns the result of the operation, \
without modifying the original"]
#[inline]
Copy link
Member

Choose a reason for hiding this comment

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

should be entirely uncontroversial, but @rust-lang/wg-const-eval this will be const

Copy link
Member

@RalfJung RalfJung Jun 29, 2024

Choose a reason for hiding this comment

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

rustc_allow_const_fn_unstable is fishy. But I guess worst-case we can replace the unwrap by a match if we somehow need to preserve const-ness here and const_precise_live_drops does not work out... as long as libs is fine with that fallback plan, I'm fine with stabilization here.

Copy link
Member

Choose a reason for hiding this comment

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

we've done worse crimes than inlining Option::unwrap, sounds fine :D

Copy link
Contributor Author

Choose a reason for hiding this comment

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

rustc_allow_const_fn_unstable is fishy.

I got that impression as well, I didn't expect having to add this. Should I get rid of this in favor of a match?

Copy link
Member

Choose a reason for hiding this comment

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

I think it's ok to keep as-is, it's just a convenience that could be removed in the future if necessary, but we can keep while we can.

Expand Down
1 change: 0 additions & 1 deletion library/core/tests/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
#![feature(core_private_bignum)]
#![feature(core_private_diy_float)]
#![feature(dec2flt)]
#![feature(duration_abs_diff)]
#![feature(duration_consts_float)]
#![feature(duration_constants)]
#![feature(duration_constructors)]
Expand Down
Loading