-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
extend unchecked_duration_subtraction
to check for Duration - Duration
#13800
base: master
Are you sure you want to change the base?
extend unchecked_duration_subtraction
to check for Duration - Duration
#13800
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @dswij (or someone else) some time within the next two weeks. Please see the contribution instructions for more information. Namely, in order to ensure the minimum review times lag, PR authors and assigned reviewers should ensure that the review label (
|
@@ -139,16 +142,23 @@ fn print_unchecked_duration_subtraction_sugg( | |||
expr: &Expr<'_>, | |||
) { | |||
let mut applicability = Applicability::MachineApplicable; | |||
let ty = cx.typeck_results().expr_ty(expr).peel_refs(); | |||
let (left_default, left_ty) = match ty::get_type_diagnostic_name(cx, ty) { | |||
Some(v) => (format!("<{}>", v.as_str().to_lowercase()), v.as_str().to_string()), |
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.
unsure if this is needed (the 'default'), thoughts? any better way to handle?
@sharksforarms |
Duration - Duration could panic in the same way as Instant - Duration
722aad6
to
59a03d7
Compare
@alex-semenyuk ah! thanks. forgot to rerun uibless. I rebased. |
@@ -41,7 +41,7 @@ declare_clippy_lint! { | |||
|
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.
While we're at it, can we also rename the struct (and the file) from InstantSubstraction
?
Seems like it won't give the right idea after the changes.
@@ -3,14 +3,21 @@ | |||
use std::time::{Duration, Instant}; |
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.
Can we also add some test cases for Duration - Duration - Duration
and see if the fixes are correct?
fixes #13734
This PR extends the
unchecked_duration_subtraction
lint to includeDuration - Duration
operations. Previously, it was onlyInstant - Duration
.Duration - Duration
is a common operation which may panic in the same way.Note: This is my first clippy PR, feedback is appreciated.
changelog: [
unchecked_duration_subtraction
]: extend lint to include subtraction of aDuration
with aDuration