Skip to content

Commit 5e02a4e

Browse files
authored
rename unchecked_duration_subtraction to unchecked_time_subtraction and check for Duration - Duration (#13800)
fixes #13734 This PR renames `unchecked_duration_subtraction` lint to `unchecked_time_subtraction` and extends it 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_time_subtraction`]: renamed from `unchecked_duration_subtraction`, extend lint to include subtraction of a `Duration` with a `Duration`
2 parents abdc61f + f296de4 commit 5e02a4e

21 files changed

+489
-302
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6704,6 +6704,7 @@ Released 2018-09-13
67046704
[`type_repetition_in_bounds`]: https://rust-lang.github.io/rust-clippy/master/index.html#type_repetition_in_bounds
67056705
[`unbuffered_bytes`]: https://rust-lang.github.io/rust-clippy/master/index.html#unbuffered_bytes
67066706
[`unchecked_duration_subtraction`]: https://rust-lang.github.io/rust-clippy/master/index.html#unchecked_duration_subtraction
6707+
[`unchecked_time_subtraction`]: https://rust-lang.github.io/rust-clippy/master/index.html#unchecked_time_subtraction
67076708
[`unconditional_recursion`]: https://rust-lang.github.io/rust-clippy/master/index.html#unconditional_recursion
67086709
[`undocumented_unsafe_blocks`]: https://rust-lang.github.io/rust-clippy/master/index.html#undocumented_unsafe_blocks
67096710
[`undropped_manually_drops`]: https://rust-lang.github.io/rust-clippy/master/index.html#undropped_manually_drops

book/src/lint_configuration.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -895,7 +895,7 @@ The minimum rust version that the project supports. Defaults to the `rust-versio
895895
* [`transmute_ptr_to_ref`](https://rust-lang.github.io/rust-clippy/master/index.html#transmute_ptr_to_ref)
896896
* [`tuple_array_conversions`](https://rust-lang.github.io/rust-clippy/master/index.html#tuple_array_conversions)
897897
* [`type_repetition_in_bounds`](https://rust-lang.github.io/rust-clippy/master/index.html#type_repetition_in_bounds)
898-
* [`unchecked_duration_subtraction`](https://rust-lang.github.io/rust-clippy/master/index.html#unchecked_duration_subtraction)
898+
* [`unchecked_time_subtraction`](https://rust-lang.github.io/rust-clippy/master/index.html#unchecked_time_subtraction)
899899
* [`uninlined_format_args`](https://rust-lang.github.io/rust-clippy/master/index.html#uninlined_format_args)
900900
* [`unnecessary_lazy_evaluations`](https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_lazy_evaluations)
901901
* [`unnested_or_patterns`](https://rust-lang.github.io/rust-clippy/master/index.html#unnested_or_patterns)

clippy_config/src/conf.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -791,7 +791,7 @@ define_Conf! {
791791
transmute_ptr_to_ref,
792792
tuple_array_conversions,
793793
type_repetition_in_bounds,
794-
unchecked_duration_subtraction,
794+
unchecked_time_subtraction,
795795
uninlined_format_args,
796796
unnecessary_lazy_evaluations,
797797
unnested_or_patterns,

clippy_lints/src/declared_lints.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,8 +226,6 @@ pub static LINTS: &[&::declare_clippy_lint::LintInfo] = &[
226226
crate::inherent_to_string::INHERENT_TO_STRING_SHADOW_DISPLAY_INFO,
227227
crate::init_numbered_fields::INIT_NUMBERED_FIELDS_INFO,
228228
crate::inline_fn_without_body::INLINE_FN_WITHOUT_BODY_INFO,
229-
crate::instant_subtraction::MANUAL_INSTANT_ELAPSED_INFO,
230-
crate::instant_subtraction::UNCHECKED_DURATION_SUBTRACTION_INFO,
231229
crate::int_plus_one::INT_PLUS_ONE_INFO,
232230
crate::integer_division_remainder_used::INTEGER_DIVISION_REMAINDER_USED_INFO,
233231
crate::invalid_upcast_comparisons::INVALID_UPCAST_COMPARISONS_INFO,
@@ -705,6 +703,8 @@ pub static LINTS: &[&::declare_clippy_lint::LintInfo] = &[
705703
crate::tabs_in_doc_comments::TABS_IN_DOC_COMMENTS_INFO,
706704
crate::temporary_assignment::TEMPORARY_ASSIGNMENT_INFO,
707705
crate::tests_outside_test_module::TESTS_OUTSIDE_TEST_MODULE_INFO,
706+
crate::time_subtraction::MANUAL_INSTANT_ELAPSED_INFO,
707+
crate::time_subtraction::UNCHECKED_TIME_SUBTRACTION_INFO,
708708
crate::to_digit_is_some::TO_DIGIT_IS_SOME_INFO,
709709
crate::to_string_trait_impl::TO_STRING_TRAIT_IMPL_INFO,
710710
crate::toplevel_ref_arg::TOPLEVEL_REF_ARG_INFO,

clippy_lints/src/deprecated_lints.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,8 @@ declare_with_version! { RENAMED(RENAMED_VERSION) = [
184184
("clippy::transmute_int_to_float", "unnecessary_transmutes"),
185185
#[clippy::version = "1.88.0"]
186186
("clippy::transmute_num_to_bytes", "unnecessary_transmutes"),
187+
#[clippy::version = "1.90.0"]
188+
("clippy::unchecked_duration_subtraction", "clippy::unchecked_time_subtraction"),
187189
#[clippy::version = ""]
188190
("clippy::undropped_manually_drops", "undropped_manually_drops"),
189191
#[clippy::version = ""]

clippy_lints/src/instant_subtraction.rs

Lines changed: 0 additions & 151 deletions
This file was deleted.

clippy_lints/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,6 @@ mod inherent_impl;
176176
mod inherent_to_string;
177177
mod init_numbered_fields;
178178
mod inline_fn_without_body;
179-
mod instant_subtraction;
180179
mod int_plus_one;
181180
mod integer_division_remainder_used;
182181
mod invalid_upcast_comparisons;
@@ -357,6 +356,7 @@ mod swap_ptr_to_ref;
357356
mod tabs_in_doc_comments;
358357
mod temporary_assignment;
359358
mod tests_outside_test_module;
359+
mod time_subtraction;
360360
mod to_digit_is_some;
361361
mod to_string_trait_impl;
362362
mod toplevel_ref_arg;
@@ -718,7 +718,7 @@ pub fn register_lint_passes(store: &mut rustc_lint::LintStore, conf: &'static Co
718718
store.register_late_pass(move |_| Box::new(manual_rotate::ManualRotate));
719719
store.register_late_pass(move |_| Box::new(operators::Operators::new(conf)));
720720
store.register_late_pass(move |_| Box::new(std_instead_of_core::StdReexports::new(conf)));
721-
store.register_late_pass(move |_| Box::new(instant_subtraction::InstantSubtraction::new(conf)));
721+
store.register_late_pass(move |_| Box::new(time_subtraction::UncheckedTimeSubtraction::new(conf)));
722722
store.register_late_pass(|_| Box::new(partialeq_to_none::PartialeqToNone));
723723
store.register_late_pass(move |_| Box::new(manual_abs_diff::ManualAbsDiff::new(conf)));
724724
store.register_late_pass(move |_| Box::new(manual_clamp::ManualClamp::new(conf)));

0 commit comments

Comments
 (0)