-
Notifications
You must be signed in to change notification settings - Fork 1.7k
feat: lint unchecked subtraction of a 'Duration' from an 'Instant' #9570
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
feat: lint unchecked subtraction of a 'Duration' from an 'Instant' #9570
Conversation
r? @dswij (rust-highfive has picked a reviewer for you, use r? to override) |
I think the best way would be to quell linting if the manual-instant-elapsed lint already picks up the expr. This might mean merging the two lint's passes to avoid duplicating the code. |
/// Unchecked subtraction could cause underflow on certain platforms, leading to bugs and/or | ||
/// unintentional panics. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It currently always panics if the subtraction overflows - https://doc.rust-lang.org/1.64.0/src/std/time.rs.html#420-426
☔ The latest upstream changes (presumably #9484) made this pull request unmergeable. Please resolve the merge conflicts. |
As far as I can see, the In the test file for // don't catch
let duration = prev_instant.elapsed();
Instant::now() - duration; But The Either way, I probably can merge the two lints. If we decide to do that, should we rename the (resulting) lint? |
No, we should keep the two lints, but we may be able to merge the lint passes, because if I understand correctly, one lint is basically a special case of the other or there is at least some overlap. |
I'm not sure about the overlap. Basically, the Instant::now() - duration; However, that same line is NOT detected by the Do you have an example of merging two lint passes? Would like to see how it works. |
Ah, I see, the manual elapsed lint checks for Instant - Instant, this checks for Instant - Duration. Merging the LintPass is simply putting the relevant code into one pass. One usually starts by copying the lint definition + |
I assume the file should be also renamed then? I will start working on that and see how it goes. Also, I think the |
@llogiq I found some time and managed to merge the |
☔ The latest upstream changes (presumably #9765) made this pull request unmergeable. Please resolve the merge conflicts. |
We don't merge from upstream, we rebasse onto it. I usually do this on the command line ( |
06b9e4b
to
36eac0c
Compare
@llogiq How does it look now? I gave my best 👀 |
Now for some reason CI seems to have excused itself. Don't worry, I'll look into it. |
I just noticed that |
Yes, that makes sense. |
@llogiq I think this is ready for review now. |
Thank you! @bors r+ |
☀️ Test successful - checks-action_dev_test, checks-action_remark_test, checks-action_test |
Hello all, I tried to tackle the open issue #9371 and this is what I came up with.
I have a difficulty currently - some tests are failing:
The
manual_instant_elapsed
is failing because ofInstant::now() - duration
test, this now gets also picked byunchecked_duration_subtraction
lint.What is the correct way to proceed in this case? Simply update the
.stderr
file formanual_instant_elapsed
lint?changelog: [
unchecked_duration_subtraction
]: Add lint for unchecked subtraction of aDuration
from anInstant
.fixes #9371