-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Conversation
…ther` has more than `i64::MAX` seconds
Hey! It looks like you've submitted a new PR for the library teams! If this PR contains changes to any Examples of
|
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. |
This appears to have fallen through the cracks. Not sure what to do, but I'll try this. r? rust-lang/libs |
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 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 |
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
No worries about the delay. Sorry the PR description was unclear. |
Use
checked_{add,sub}_unsigned
inchecked_{add,sub}_duration
so that the correct result is returned when adding/subtracting durations with more thani64::MAX
seconds.