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

extend unchecked_duration_subtraction to check for Duration - Duration #13800

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

sharksforarms
Copy link

fixes #13734

This PR extends the unchecked_duration_subtraction lint to include Duration - Duration operations. Previously, it was only Instant - 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 a Duration with a Duration

@rustbot
Copy link
Collaborator

rustbot commented Dec 9, 2024

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 (S-waiting-on-review and S-waiting-on-author) stays updated, invoking these commands when appropriate:

  • @rustbot author: the review is finished, PR author should check the comments and take action accordingly
  • @rustbot review: the author is ready for a review, this PR will be queued again in the reviewer's queue

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Dec 9, 2024
@@ -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()),
Copy link
Author

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?

@alex-semenyuk
Copy link
Member

@sharksforarms
Could you please take a look tests, seems some are failed

Duration - Duration could panic in the same way as Instant - Duration
@sharksforarms sharksforarms force-pushed the sharksforarms/duration-sub branch from 722aad6 to 59a03d7 Compare December 10, 2024 20:13
@sharksforarms
Copy link
Author

@alex-semenyuk ah! thanks. forgot to rerun uibless. I rebased.

@@ -41,7 +41,7 @@ declare_clippy_lint! {

Copy link
Member

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};
Copy link
Member

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Duration arithmetic
4 participants