From 36eac0cb4ae2e372193f73c3181d5290431d3ae4 Mon Sep 17 00:00:00 2001 From: Nadir Fejzic Date: Thu, 10 Nov 2022 15:55:45 +0100 Subject: [PATCH] fix: update lints --- clippy_lints/src/declared_lints.rs | 3 ++- clippy_lints/src/lib.rs | 1 - src/docs/unchecked_duration_subtraction.txt | 19 ------------------- 3 files changed, 2 insertions(+), 21 deletions(-) delete mode 100644 src/docs/unchecked_duration_subtraction.txt diff --git a/clippy_lints/src/declared_lints.rs b/clippy_lints/src/declared_lints.rs index 98265410e..7a705e563 100644 --- a/clippy_lints/src/declared_lints.rs +++ b/clippy_lints/src/declared_lints.rs @@ -202,6 +202,8 @@ pub(crate) static LINTS: &[&crate::LintInfo] = &[ crate::inherent_to_string::INHERENT_TO_STRING_SHADOW_DISPLAY_INFO, crate::init_numbered_fields::INIT_NUMBERED_FIELDS_INFO, crate::inline_fn_without_body::INLINE_FN_WITHOUT_BODY_INFO, + crate::instant_subtraction::MANUAL_INSTANT_ELAPSED_INFO, + crate::instant_subtraction::UNCHECKED_DURATION_SUBTRACTION_INFO, crate::int_plus_one::INT_PLUS_ONE_INFO, crate::invalid_upcast_comparisons::INVALID_UPCAST_COMPARISONS_INFO, crate::invalid_utf8_in_unchecked::INVALID_UTF8_IN_UNCHECKED_INFO, @@ -250,7 +252,6 @@ pub(crate) static LINTS: &[&crate::LintInfo] = &[ crate::manual_async_fn::MANUAL_ASYNC_FN_INFO, crate::manual_bits::MANUAL_BITS_INFO, crate::manual_clamp::MANUAL_CLAMP_INFO, - crate::manual_instant_elapsed::MANUAL_INSTANT_ELAPSED_INFO, crate::manual_is_ascii_check::MANUAL_IS_ASCII_CHECK_INFO, crate::manual_let_else::MANUAL_LET_ELSE_INFO, crate::manual_non_exhaustive::MANUAL_NON_EXHAUSTIVE_INFO, diff --git a/clippy_lints/src/lib.rs b/clippy_lints/src/lib.rs index ce0e7ebfb..3cfb2f491 100644 --- a/clippy_lints/src/lib.rs +++ b/clippy_lints/src/lib.rs @@ -921,7 +921,6 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf: store.register_late_pass(|_| Box::new(from_raw_with_void_ptr::FromRawWithVoidPtr)); store.register_late_pass(|_| Box::new(suspicious_xor_used_as_pow::ConfusingXorAndPow)); store.register_late_pass(move |_| Box::new(manual_is_ascii_check::ManualIsAsciiCheck::new(msrv))); - store.register_late_pass(move || Box::new(unchecked_duration_subtraction::UncheckedDurationSubtraction::new(msrv))); // add lints here, do not remove this comment, it's used in `new_lint` } diff --git a/src/docs/unchecked_duration_subtraction.txt b/src/docs/unchecked_duration_subtraction.txt deleted file mode 100644 index 15a4c02c6..000000000 --- a/src/docs/unchecked_duration_subtraction.txt +++ /dev/null @@ -1,19 +0,0 @@ -### What it does -Finds patterns of unchecked subtraction of [`Duration`] from [`Instant::now()`]. - -### Why is this bad? -Unchecked subtraction could cause underflow on certain platforms, leading to -unintentional panics. - -### Example -``` -let time_passed = Instant::now() - Duration::from_secs(5); -``` - -Use instead: -``` -let time_passed = Instant::now().checked_sub(Duration::from_secs(5)); -``` - -[`Duration`]: std::time::Duration -[`Instant::now()`]: std::time::Instant::now; \ No newline at end of file