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

Fix checked_{add,sub}_duration incorrectly returning None when other has more than i64::MAX seconds #103056

Merged
merged 1 commit into from
May 5, 2023

Conversation

beetrees
Copy link
Contributor

Use checked_{add,sub}_unsigned in checked_{add,sub}_duration so that the correct result is returned when adding/subtracting durations with more than i64::MAX seconds.

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

rustbot commented Oct 14, 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

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @joshtriplett (or someone else) soon.

Please see the contribution instructions for more information.

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Oct 14, 2022
@beetrees
Copy link
Contributor Author

This appears to have fallen through the cracks. Not sure what to do, but I'll try this.

r? rust-lang/libs

@rustbot rustbot assigned thomcc and unassigned joshtriplett Mar 30, 2023
@thomcc
Copy link
Member

thomcc commented May 5, 2023

Huh, that's really subtle. At the moment, we have a bug where (using subtraction in the example even though it's true for addition as well):

// Panics (`checked_sub` returned `None`)
Instant::now() - Duration::from_secs(i64::MAX as u64 + 100)

will fail, even though:

// Works fine.
Instant::now() - Duration::from_secs(i64::MAX as u64) - Duration::from_secs(100)

succeeds. This is because we erroneously fail if we can't convert the Duration's seconds (a u64) into a signed int, which isn't actually necessary to perform the conversion.

And this patch fixes it. Thanks!

Sorry for the delay with review, I've been busy with family issues (and it wasn't immediately clear to me what this was fixing the test or issue description).

@bors r+ rollup

@bors
Copy link
Contributor

bors commented May 5, 2023

📌 Commit 5def753 has been approved by thomcc

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 May 5, 2023
bors added a commit to rust-lang-ci/rust that referenced this pull request May 5, 2023
Rollup of 6 pull requests

Successful merges:

 - rust-lang#103056 (Fix `checked_{add,sub}_duration` incorrectly returning `None` when `other` has more than `i64::MAX` seconds)
 - rust-lang#108801 (Implement RFC 3348, `c"foo"` literals)
 - rust-lang#110773 (Reduce MIR dump file count for MIR-opt tests)
 - rust-lang#110876 (Added default target cpu to `--print target-cpus` output and updated docs)
 - rust-lang#111068 (Improve check-cfg implementation)
 - rust-lang#111238 (btree_map: `Cursor{,Mut}::peek_prev` must agree)

Failed merges:

 - rust-lang#110694 (Implement builtin # syntax and use it for offset_of!(...))

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 3502e48 into rust-lang:master May 5, 2023
@rustbot rustbot added this to the 1.71.0 milestone May 5, 2023
@beetrees
Copy link
Contributor Author

No worries about the delay. Sorry the PR description was unclear.

@beetrees beetrees deleted the timespec-bug-fix branch May 15, 2023 14:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-libs Relevant to the library team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants