Skip to content
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

Stabilize duration_checked_float #102271

Merged
merged 1 commit into from
Oct 24, 2022
Merged

Stabilize duration_checked_float #102271

merged 1 commit into from
Oct 24, 2022

Conversation

lopopolo
Copy link
Contributor

Stabilization Report

This stabilization report is for a stabilization of duration_checked_float, tracking issue: #83400.

Implementation History

API Summary

This stabilization report proposes the following API to be stabilized in core, along with their re-exports in std:

// 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 #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:

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

@rustbot rustbot added the T-libs Relevant to the library team, which will review and decide on the PR/issue. label Sep 25, 2022
@rustbot
Copy link
Collaborator

rustbot commented Sep 25, 2022

Hey! It looks like you've submitted a new PR for the library teams!

If this PR contains changes to any rust-lang/rust public library APIs then please comment with @rustbot label +T-libs-api -T-libs to tag it appropriately. If this PR contains changes to any unstable APIs please edit the PR description to add a link to the relevant API Change Proposal or create one if you haven't already. If you're unsure where your change falls no worries, just leave it as is and the reviewer will take a look and make a decision to forward on if necessary.

Examples of T-libs-api changes:

  • Stabilizing library features
  • Introducing insta-stable changes such as new implementations of existing stable traits on existing stable types
  • Introducing new or changing existing unstable library APIs (excluding permanently unstable features / features without a tracking issue)
  • Changing public documentation in ways that create new stability guarantees
  • Changing observable runtime behavior of library APIs

@rust-highfive
Copy link
Collaborator

r? @scottmcm

(rust-highfive has picked a reviewer for you, use r? to override)

@rustbot rustbot added the T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. label Sep 25, 2022
@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Sep 25, 2022
@inquisitivecrystal inquisitivecrystal added the relnotes Marks issues that should be documented in the release notes of the next release. label Sep 25, 2022
@mbartlett21
Copy link
Contributor

@lopopolo

Thanks for continuing along with this. The error changes lgtm.

@scottmcm
Copy link
Member

Since it looks like this hasn't had an FCP,
@rustbot label +needs-fcp
r? @joshtriplett

@rustbot rustbot added the needs-fcp This change is insta-stable, so needs a completed FCP to proceed. label Sep 26, 2022
@bors
Copy link
Contributor

bors commented Sep 26, 2022

☔ The latest upstream changes (presumably #102051) made this pull request unmergeable. Please resolve the merge conflicts.

@lopopolo
Copy link
Contributor Author

Pushed a rebase due to the std::error::Error changes being shuffled around with the new nightly.

@joshtriplett joshtriplett removed the T-libs Relevant to the library team, which will review and decide on the PR/issue. label Oct 3, 2022
@joshtriplett
Copy link
Member

@rfcbot merge

@rfcbot
Copy link

rfcbot commented Oct 3, 2022

Team member @joshtriplett 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 rfcbot added proposed-final-comment-period Proposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off. disposition-merge This issue / PR is in PFCP or FCP with a disposition to merge it. final-comment-period In the final comment period and will be merged soon unless new substantive objections are raised. and removed proposed-final-comment-period Proposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off. labels Oct 3, 2022
@rfcbot
Copy link

rfcbot commented Oct 5, 2022

🔔 This is now entering its final comment period, as per the review above. 🔔

matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Oct 14, 2022
…ro, r=thomcc

Fix `Duration::{try_,}from_secs_f{32,64}(-0.0)`

Make `Duration::{try_,}from_secs_f{32,64}(-0.0)` return `Duration::ZERO` (as they did before rust-lang#90247) instead of erroring/panicking.

I'll update this PR to remove the `#![feature(duration_checked_float)]` if rust-lang#102271 is merged before this PR.

Tracking issue for `try_from_secs_f{32,64}`: rust-lang#83400
@bors
Copy link
Contributor

bors commented Oct 15, 2022

☔ The latest upstream changes (presumably #103069) made this pull request unmergeable. Please resolve the merge conflicts.

@rfcbot rfcbot added finished-final-comment-period The final comment period is finished for this PR / Issue. to-announce Announce this issue on triage meeting and removed final-comment-period In the final comment period and will be merged soon unless new substantive objections are raised. labels Oct 15, 2022
@rfcbot
Copy link

rfcbot commented Oct 15, 2022

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.

@lopopolo
Copy link
Contributor Author

Pushed a rebase to address the merge conflict from #103059. It looks like the FCP is complete, so once CI passes I think this is ready for a stamp and merge.

@lopopolo
Copy link
Contributor Author

@joshtriplett I believe this is ready to be merged since the FCP has concluded.

@lopopolo
Copy link
Contributor Author

Did this miss the beta cutoff? 😢

@lopopolo
Copy link
Contributor Author

lopopolo commented Oct 24, 2022

@Amanieu @BurntSushi @dtolnay @joshtriplett @m-ou-se @yaahc can one of you r+ this PR to merge it? This FCP successfully completed 8 days ago.

@dtolnay
Copy link
Member

dtolnay commented Oct 24, 2022

@bors r+

@dtolnay dtolnay assigned dtolnay and unassigned joshtriplett Oct 24, 2022
@bors
Copy link
Contributor

bors commented Oct 24, 2022

📌 Commit 95040a7 has been approved by dtolnay

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Oct 24, 2022
Dylan-DPC added a commit to Dylan-DPC/rust that referenced this pull request Oct 24, 2022
…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``
bors added a commit to rust-lang-ci/rust that referenced this pull request Oct 24, 2022
Rollup of 7 pull requests

Successful merges:

 - rust-lang#99578 (Remove redundant lifetime bound from `impl Borrow for Cow`)
 - rust-lang#99939 (Sort tests at compile time, not at startup)
 - rust-lang#102271 (Stabilize `duration_checked_float`)
 - rust-lang#102766 (Don't link to `libresolv` in libstd on Darwin)
 - rust-lang#103277 (Update libstd's libc to 0.2.135 (to make `libstd` no longer pull in `libiconv.dylib` on Darwin))
 - rust-lang#103437 (Sync rustc_codegen_cranelift)
 - rust-lang#103466 (Fix grammar in docs for std::io::Read)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit c1f9d98 into rust-lang:master Oct 24, 2022
@rustbot rustbot added this to the 1.66.0 milestone Oct 24, 2022
@lopopolo lopopolo deleted the lopopolo/stabilize-duration-try-from-secs-float branch October 24, 2022 17:57
@apiraino apiraino removed the to-announce Announce this issue on triage meeting label Jan 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
disposition-merge This issue / PR is in PFCP or FCP with a disposition to merge it. finished-final-comment-period The final comment period is finished for this PR / Issue. needs-fcp This change is insta-stable, so needs a completed FCP to proceed. relnotes Marks issues that should be documented in the release notes of the next release. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.