fix: update lints

This commit is contained in:
Nadir Fejzic 2022-11-10 15:55:45 +01:00
parent 862ac29192
commit 36eac0cb4a
3 changed files with 2 additions and 21 deletions

View file

@ -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,

View file

@ -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`
}

View file

@ -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;