-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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 confusing error message for sub_instant #51255
Conversation
When subtracting an Instant from another, the function will panick when `RHS > self`, but the error message confusingly displays a different error: ```rust let i = Instant::now(); let other = Instant::now(); if other > i { println!("{:?}", i - other); } ``` This results in a panic: ``` thread 'test_instant' panicked at 'other was less than the current instant', libstd/sys/unix/time.rs:292:17 ```
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @kennytm (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. Please see the contribution instructions for more information. |
Thank you @avdv! Would you mind updating this file as well? Also, I think the error message from the Windows and CloudABI implementations are even more clearer: |
Uses the same wording as [`src/libstd/sys/windows/time.rs`][1]. 1: https://github.com/avdv/rust/blob/95e2bf253d864c5e14ad000ffa2040ce85916056/src/libstd/sys/windows/time.rs#L65
Hi @kennytm, I went with the first alternative phrase; I liked it the best. I updated the PR accordingly. Cheers. |
@bors r+ rollup |
📌 Commit 33c4b37 has been approved by |
⌛ Testing commit 33c4b37 with merge 56f7181b2af07b5357d2bd8c7ad4d3e2435a8cf0... |
💔 Test failed - status-travis |
The job Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
The job Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
Fix confusing error message for sub_instant When subtracting an Instant from another, the function will panick when `RHS > self`, but the error message confusingly displays a different error: ```rust let i = Instant::now(); let other = Instant::now(); if other > i { println!("{:?}", i - other); } ``` This results in a panic: ``` thread 'test_instant' panicked at 'other was less than the current instant', libstd/sys/unix/time.rs:292:17 ``` But clearly, `other` was actually greater than the current instant.
Rollup of 7 pull requests Successful merges: - #50852 (Add doc comment to hiding portions of code example) - #51183 (Update rustdoc book to suggest using Termination trait instead of hidden ‘foo’ function) - #51255 (Fix confusing error message for sub_instant) - #51256 (Fix crate-name option in rustdoc) - #51308 (Check array indices in constant propagation) - #51343 (test: Ignore some problematic tests on sparc and sparc64) - #51358 (Tests that #39963 is fixed on MIR borrowck) Failed merges:
When subtracting an Instant from another, the function will panick when
RHS > self
, but the error message confusingly displays a different error:This results in a panic:
But clearly,
other
was actually greater than the current instant.