From 8db319f9578aa4cc5647a187f92aa00a6f4ad335 Mon Sep 17 00:00:00 2001 From: Krishna Veera Reddy Date: Sat, 7 Dec 2019 19:10:06 -0800 Subject: [PATCH 1/8] Use `mem::take` instead of `mem::replace` when applicable `std::mem::take` can be used to replace a value of type `T` with `T::default()` instead of `std::mem::replace`. --- CHANGELOG.md | 1 + clippy_lints/src/lib.rs | 2 + clippy_lints/src/mem_replace.rs | 186 +++++++++++++++++++++----------- src/lintlist/mod.rs | 7 ++ tests/ui/mem_replace.fixed | 21 +++- tests/ui/mem_replace.rs | 21 +++- tests/ui/mem_replace.stderr | 20 +++- 7 files changed, 189 insertions(+), 69 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 50a7f44ad8e65..05d437d3598c9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1173,6 +1173,7 @@ Released 2018-09-13 [`mem_discriminant_non_enum`]: https://rust-lang.github.io/rust-clippy/master/index.html#mem_discriminant_non_enum [`mem_forget`]: https://rust-lang.github.io/rust-clippy/master/index.html#mem_forget [`mem_replace_option_with_none`]: https://rust-lang.github.io/rust-clippy/master/index.html#mem_replace_option_with_none +[`mem_replace_with_default`]: https://rust-lang.github.io/rust-clippy/master/index.html#mem_replace_with_default [`mem_replace_with_uninit`]: https://rust-lang.github.io/rust-clippy/master/index.html#mem_replace_with_uninit [`min_max`]: https://rust-lang.github.io/rust-clippy/master/index.html#min_max [`misaligned_transmute`]: https://rust-lang.github.io/rust-clippy/master/index.html#misaligned_transmute diff --git a/clippy_lints/src/lib.rs b/clippy_lints/src/lib.rs index 49101695a58bd..abcddc88527ca 100644 --- a/clippy_lints/src/lib.rs +++ b/clippy_lints/src/lib.rs @@ -599,6 +599,7 @@ pub fn register_plugins(store: &mut lint::LintStore, sess: &Session, conf: &Conf &mem_discriminant::MEM_DISCRIMINANT_NON_ENUM, &mem_forget::MEM_FORGET, &mem_replace::MEM_REPLACE_OPTION_WITH_NONE, + &mem_replace::MEM_REPLACE_WITH_DEFAULT, &mem_replace::MEM_REPLACE_WITH_UNINIT, &methods::CHARS_LAST_CMP, &methods::CHARS_NEXT_CMP, @@ -1594,6 +1595,7 @@ pub fn register_plugins(store: &mut lint::LintStore, sess: &Session, conf: &Conf store.register_group(true, "clippy::nursery", Some("clippy_nursery"), vec![ LintId::of(&attrs::EMPTY_LINE_AFTER_OUTER_ATTR), LintId::of(&fallible_impl_from::FALLIBLE_IMPL_FROM), + LintId::of(&mem_replace::MEM_REPLACE_WITH_DEFAULT), LintId::of(&missing_const_for_fn::MISSING_CONST_FOR_FN), LintId::of(&mul_add::MANUAL_MUL_ADD), LintId::of(&mutex_atomic::MUTEX_INTEGER), diff --git a/clippy_lints/src/mem_replace.rs b/clippy_lints/src/mem_replace.rs index b7b0538cbaee9..5ad41a53b89ba 100644 --- a/clippy_lints/src/mem_replace.rs +++ b/clippy_lints/src/mem_replace.rs @@ -3,7 +3,7 @@ use crate::utils::{ }; use if_chain::if_chain; use rustc::declare_lint_pass; -use rustc::hir::{BorrowKind, Expr, ExprKind, Mutability, QPath}; +use rustc::hir::{BorrowKind, Expr, ExprKind, HirVec, Mutability, QPath}; use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass}; use rustc_errors::Applicability; use rustc_session::declare_tool_lint; @@ -67,8 +67,127 @@ declare_clippy_lint! { "`mem::replace(&mut _, mem::uninitialized())` or `mem::replace(&mut _, mem::zeroed())`" } +declare_clippy_lint! { + /// **What it does:** Checks for `std::mem::replace` on a value of type + /// `T` with `T::default()`. + /// + /// **Why is this bad?** `std::mem` module already has the method `take` to + /// take the current value and replace it with the default value of that type. + /// + /// **Known problems:** None. + /// + /// **Example:** + /// ```rust + /// let mut text = String::from("foo"); + /// let replaced = std::mem::replace(&mut text, String::default()); + /// ``` + /// Is better expressed with: + /// ```rust + /// let mut text = String::from("foo"); + /// let taken = std::mem::take(&mut text); + /// ``` + pub MEM_REPLACE_WITH_DEFAULT, + nursery, + "replacing a value of type `T` with `T::default()` instead of using `std::mem::take`" +} + declare_lint_pass!(MemReplace => - [MEM_REPLACE_OPTION_WITH_NONE, MEM_REPLACE_WITH_UNINIT]); + [MEM_REPLACE_OPTION_WITH_NONE, MEM_REPLACE_WITH_UNINIT, MEM_REPLACE_WITH_DEFAULT]); + +fn check_replace_option_with_none(cx: &LateContext<'_, '_>, expr: &'_ Expr, args: &HirVec) { + if let ExprKind::Path(ref replacement_qpath) = args[1].kind { + // Check that second argument is `Option::None` + if match_qpath(replacement_qpath, &paths::OPTION_NONE) { + // Since this is a late pass (already type-checked), + // and we already know that the second argument is an + // `Option`, we do not need to check the first + // argument's type. All that's left is to get + // replacee's path. + let replaced_path = match args[0].kind { + ExprKind::AddrOf(BorrowKind::Ref, Mutability::Mut, ref replaced) => { + if let ExprKind::Path(QPath::Resolved(None, ref replaced_path)) = replaced.kind { + replaced_path + } else { + return; + } + }, + ExprKind::Path(QPath::Resolved(None, ref replaced_path)) => replaced_path, + _ => return, + }; + + let mut applicability = Applicability::MachineApplicable; + span_lint_and_sugg( + cx, + MEM_REPLACE_OPTION_WITH_NONE, + expr.span, + "replacing an `Option` with `None`", + "consider `Option::take()` instead", + format!( + "{}.take()", + snippet_with_applicability(cx, replaced_path.span, "", &mut applicability) + ), + applicability, + ); + } + } +} + +fn check_replace_with_uninit(cx: &LateContext<'_, '_>, expr: &'_ Expr, args: &HirVec) { + if let ExprKind::Call(ref repl_func, ref repl_args) = args[1].kind { + if_chain! { + if repl_args.is_empty(); + if let ExprKind::Path(ref repl_func_qpath) = repl_func.kind; + if let Some(repl_def_id) = cx.tables.qpath_res(repl_func_qpath, repl_func.hir_id).opt_def_id(); + then { + if match_def_path(cx, repl_def_id, &paths::MEM_UNINITIALIZED) { + span_help_and_lint( + cx, + MEM_REPLACE_WITH_UNINIT, + expr.span, + "replacing with `mem::uninitialized()`", + "consider using the `take_mut` crate instead", + ); + } else if match_def_path(cx, repl_def_id, &paths::MEM_ZEROED) && + !cx.tables.expr_ty(&args[1]).is_primitive() { + span_help_and_lint( + cx, + MEM_REPLACE_WITH_UNINIT, + expr.span, + "replacing with `mem::zeroed()`", + "consider using a default value or the `take_mut` crate instead", + ); + } + } + } + } +} + +fn check_replace_with_default(cx: &LateContext<'_, '_>, expr: &'_ Expr, args: &HirVec) { + if let ExprKind::Call(ref repl_func, ref repl_args) = args[1].kind { + if_chain! { + if repl_args.is_empty(); + if let ExprKind::Path(ref repl_func_qpath) = repl_func.kind; + if let Some(repl_def_id) = cx.tables.qpath_res(repl_func_qpath, repl_func.hir_id).opt_def_id(); + if match_def_path(cx, repl_def_id, &paths::DEFAULT_TRAIT_METHOD); + then { + let mut applicability = Applicability::MachineApplicable; + + span_lint_and_sugg( + cx, + MEM_REPLACE_WITH_DEFAULT, + expr.span, + "replacing a value of type `T` with `T::default()` is better expressed using `std::mem::take`", + "consider using", + format!( + "std::mem::take({})", + snippet_with_applicability(cx, args[0].span, "", &mut applicability) + ), + applicability, + ); + } + } + } +} impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MemReplace { fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) { @@ -80,67 +199,10 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MemReplace { if let Some(def_id) = cx.tables.qpath_res(func_qpath, func.hir_id).opt_def_id(); if match_def_path(cx, def_id, &paths::MEM_REPLACE); - // Check that second argument is `Option::None` then { - if let ExprKind::Path(ref replacement_qpath) = func_args[1].kind { - if match_qpath(replacement_qpath, &paths::OPTION_NONE) { - - // Since this is a late pass (already type-checked), - // and we already know that the second argument is an - // `Option`, we do not need to check the first - // argument's type. All that's left is to get - // replacee's path. - let replaced_path = match func_args[0].kind { - ExprKind::AddrOf(BorrowKind::Ref, Mutability::Mut, ref replaced) => { - if let ExprKind::Path(QPath::Resolved(None, ref replaced_path)) = replaced.kind { - replaced_path - } else { - return - } - }, - ExprKind::Path(QPath::Resolved(None, ref replaced_path)) => replaced_path, - _ => return, - }; - - let mut applicability = Applicability::MachineApplicable; - span_lint_and_sugg( - cx, - MEM_REPLACE_OPTION_WITH_NONE, - expr.span, - "replacing an `Option` with `None`", - "consider `Option::take()` instead", - format!("{}.take()", snippet_with_applicability(cx, replaced_path.span, "", &mut applicability)), - applicability, - ); - } - } - if let ExprKind::Call(ref repl_func, ref repl_args) = func_args[1].kind { - if_chain! { - if repl_args.is_empty(); - if let ExprKind::Path(ref repl_func_qpath) = repl_func.kind; - if let Some(repl_def_id) = cx.tables.qpath_res(repl_func_qpath, repl_func.hir_id).opt_def_id(); - then { - if match_def_path(cx, repl_def_id, &paths::MEM_UNINITIALIZED) { - span_help_and_lint( - cx, - MEM_REPLACE_WITH_UNINIT, - expr.span, - "replacing with `mem::uninitialized()`", - "consider using the `take_mut` crate instead", - ); - } else if match_def_path(cx, repl_def_id, &paths::MEM_ZEROED) && - !cx.tables.expr_ty(&func_args[1]).is_primitive() { - span_help_and_lint( - cx, - MEM_REPLACE_WITH_UNINIT, - expr.span, - "replacing with `mem::zeroed()`", - "consider using a default value or the `take_mut` crate instead", - ); - } - } - } - } + check_replace_option_with_none(cx, expr, &func_args); + check_replace_with_uninit(cx, expr, &func_args); + check_replace_with_default(cx, expr, &func_args); } } } diff --git a/src/lintlist/mod.rs b/src/lintlist/mod.rs index 08cbff404442b..4b820250c8df0 100644 --- a/src/lintlist/mod.rs +++ b/src/lintlist/mod.rs @@ -1099,6 +1099,13 @@ pub const ALL_LINTS: [Lint; 342] = [ deprecation: None, module: "mem_replace", }, + Lint { + name: "mem_replace_with_default", + group: "nursery", + desc: "replacing a value of type `T` with `T::default()` instead of using `std::mem::take`", + deprecation: None, + module: "mem_replace", + }, Lint { name: "mem_replace_with_uninit", group: "correctness", diff --git a/tests/ui/mem_replace.fixed b/tests/ui/mem_replace.fixed index 4e47ac95d82d3..19205dc38223c 100644 --- a/tests/ui/mem_replace.fixed +++ b/tests/ui/mem_replace.fixed @@ -9,13 +9,30 @@ // run-rustfix #![allow(unused_imports)] -#![warn(clippy::all, clippy::style, clippy::mem_replace_option_with_none)] +#![warn( + clippy::all, + clippy::style, + clippy::mem_replace_option_with_none, + clippy::mem_replace_with_default +)] use std::mem; -fn main() { +fn replace_option_with_none() { let mut an_option = Some(1); let _ = an_option.take(); let an_option = &mut Some(1); let _ = an_option.take(); } + +fn replace_with_default() { + let mut s = String::from("foo"); + let _ = std::mem::take(&mut s); + let s = &mut String::from("foo"); + let _ = std::mem::take(s); +} + +fn main() { + replace_option_with_none(); + replace_with_default(); +} diff --git a/tests/ui/mem_replace.rs b/tests/ui/mem_replace.rs index 6824ab18e7faa..97ac283abc663 100644 --- a/tests/ui/mem_replace.rs +++ b/tests/ui/mem_replace.rs @@ -9,13 +9,30 @@ // run-rustfix #![allow(unused_imports)] -#![warn(clippy::all, clippy::style, clippy::mem_replace_option_with_none)] +#![warn( + clippy::all, + clippy::style, + clippy::mem_replace_option_with_none, + clippy::mem_replace_with_default +)] use std::mem; -fn main() { +fn replace_option_with_none() { let mut an_option = Some(1); let _ = mem::replace(&mut an_option, None); let an_option = &mut Some(1); let _ = mem::replace(an_option, None); } + +fn replace_with_default() { + let mut s = String::from("foo"); + let _ = std::mem::replace(&mut s, String::default()); + let s = &mut String::from("foo"); + let _ = std::mem::replace(s, String::default()); +} + +fn main() { + replace_option_with_none(); + replace_with_default(); +} diff --git a/tests/ui/mem_replace.stderr b/tests/ui/mem_replace.stderr index 791c4d71dbfc8..44495a973c870 100644 --- a/tests/ui/mem_replace.stderr +++ b/tests/ui/mem_replace.stderr @@ -1,5 +1,5 @@ error: replacing an `Option` with `None` - --> $DIR/mem_replace.rs:18:13 + --> $DIR/mem_replace.rs:23:13 | LL | let _ = mem::replace(&mut an_option, None); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider `Option::take()` instead: `an_option.take()` @@ -7,10 +7,24 @@ LL | let _ = mem::replace(&mut an_option, None); = note: `-D clippy::mem-replace-option-with-none` implied by `-D warnings` error: replacing an `Option` with `None` - --> $DIR/mem_replace.rs:20:13 + --> $DIR/mem_replace.rs:25:13 | LL | let _ = mem::replace(an_option, None); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider `Option::take()` instead: `an_option.take()` -error: aborting due to 2 previous errors +error: replacing a value of type `T` with `T::default()` is better expressed using `std::mem::take` + --> $DIR/mem_replace.rs:30:13 + | +LL | let _ = std::mem::replace(&mut s, String::default()); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::mem::take(&mut s)` + | + = note: `-D clippy::mem-replace-with-default` implied by `-D warnings` + +error: replacing a value of type `T` with `T::default()` is better expressed using `std::mem::take` + --> $DIR/mem_replace.rs:32:13 + | +LL | let _ = std::mem::replace(s, String::default()); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::mem::take(s)` + +error: aborting due to 4 previous errors From 2a75241c1abc54c1becd7eff108160beef4490f8 Mon Sep 17 00:00:00 2001 From: Krishna Veera Reddy Date: Sun, 8 Dec 2019 09:26:37 -0800 Subject: [PATCH 2/8] Add test cases for replace with `Default::default()` --- tests/ui/mem_replace.fixed | 1 + tests/ui/mem_replace.rs | 1 + tests/ui/mem_replace.stderr | 8 +++++++- 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/tests/ui/mem_replace.fixed b/tests/ui/mem_replace.fixed index 19205dc38223c..58657b934fbfe 100644 --- a/tests/ui/mem_replace.fixed +++ b/tests/ui/mem_replace.fixed @@ -30,6 +30,7 @@ fn replace_with_default() { let _ = std::mem::take(&mut s); let s = &mut String::from("foo"); let _ = std::mem::take(s); + let _ = std::mem::take(s); } fn main() { diff --git a/tests/ui/mem_replace.rs b/tests/ui/mem_replace.rs index 97ac283abc663..eac0ce586a088 100644 --- a/tests/ui/mem_replace.rs +++ b/tests/ui/mem_replace.rs @@ -30,6 +30,7 @@ fn replace_with_default() { let _ = std::mem::replace(&mut s, String::default()); let s = &mut String::from("foo"); let _ = std::mem::replace(s, String::default()); + let _ = std::mem::replace(s, Default::default()); } fn main() { diff --git a/tests/ui/mem_replace.stderr b/tests/ui/mem_replace.stderr index 44495a973c870..d5dc66873b2fe 100644 --- a/tests/ui/mem_replace.stderr +++ b/tests/ui/mem_replace.stderr @@ -26,5 +26,11 @@ error: replacing a value of type `T` with `T::default()` is better expressed usi LL | let _ = std::mem::replace(s, String::default()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::mem::take(s)` -error: aborting due to 4 previous errors +error: replacing a value of type `T` with `T::default()` is better expressed using `std::mem::take` + --> $DIR/mem_replace.rs:33:13 + | +LL | let _ = std::mem::replace(s, Default::default()); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::mem::take(s)` + +error: aborting due to 5 previous errors From 26812f733daaf65e514c058c51138511f6f5b60c Mon Sep 17 00:00:00 2001 From: Krishna Veera Reddy Date: Sun, 8 Dec 2019 11:46:21 -0800 Subject: [PATCH 3/8] Prevent `mem_replace_with_default` lint within macros Also added test cases for internal and external macros. --- clippy_lints/src/mem_replace.rs | 8 ++++---- tests/ui/auxiliary/macro_rules.rs | 7 +++++++ tests/ui/mem_replace.fixed | 14 ++++++++++++++ tests/ui/mem_replace.rs | 14 ++++++++++++++ tests/ui/mem_replace.stderr | 10 +++++----- 5 files changed, 44 insertions(+), 9 deletions(-) diff --git a/clippy_lints/src/mem_replace.rs b/clippy_lints/src/mem_replace.rs index 5ad41a53b89ba..ab0bdb4d02c47 100644 --- a/clippy_lints/src/mem_replace.rs +++ b/clippy_lints/src/mem_replace.rs @@ -1,10 +1,10 @@ use crate::utils::{ - match_def_path, match_qpath, paths, snippet_with_applicability, span_help_and_lint, span_lint_and_sugg, + in_macro, match_def_path, match_qpath, paths, snippet_with_applicability, span_help_and_lint, span_lint_and_sugg, }; use if_chain::if_chain; use rustc::declare_lint_pass; use rustc::hir::{BorrowKind, Expr, ExprKind, HirVec, Mutability, QPath}; -use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass}; +use rustc::lint::{in_external_macro, LateContext, LateLintPass, LintArray, LintPass}; use rustc_errors::Applicability; use rustc_session::declare_tool_lint; @@ -163,9 +163,9 @@ fn check_replace_with_uninit(cx: &LateContext<'_, '_>, expr: &'_ Expr, args: &Hi } fn check_replace_with_default(cx: &LateContext<'_, '_>, expr: &'_ Expr, args: &HirVec) { - if let ExprKind::Call(ref repl_func, ref repl_args) = args[1].kind { + if let ExprKind::Call(ref repl_func, _) = args[1].kind { if_chain! { - if repl_args.is_empty(); + if !in_macro(expr.span) && !in_external_macro(cx.tcx.sess, expr.span); if let ExprKind::Path(ref repl_func_qpath) = repl_func.kind; if let Some(repl_def_id) = cx.tables.qpath_res(repl_func_qpath, repl_func.hir_id).opt_def_id(); if match_def_path(cx, repl_def_id, &paths::DEFAULT_TRAIT_METHOD); diff --git a/tests/ui/auxiliary/macro_rules.rs b/tests/ui/auxiliary/macro_rules.rs index 504d6733abfe0..eafc68bd6bcf4 100644 --- a/tests/ui/auxiliary/macro_rules.rs +++ b/tests/ui/auxiliary/macro_rules.rs @@ -39,3 +39,10 @@ macro_rules! string_add { let z = y + "..."; }; } + +#[macro_export] +macro_rules! take_external { + ($s:expr) => { + std::mem::replace($s, Default::default()) + }; +} diff --git a/tests/ui/mem_replace.fixed b/tests/ui/mem_replace.fixed index 58657b934fbfe..8606e98335dfe 100644 --- a/tests/ui/mem_replace.fixed +++ b/tests/ui/mem_replace.fixed @@ -8,6 +8,7 @@ // except according to those terms. // run-rustfix +// aux-build:macro_rules.rs #![allow(unused_imports)] #![warn( clippy::all, @@ -16,8 +17,17 @@ clippy::mem_replace_with_default )] +#[macro_use] +extern crate macro_rules; + use std::mem; +macro_rules! take { + ($s:expr) => { + std::mem::replace($s, Default::default()) + }; +} + fn replace_option_with_none() { let mut an_option = Some(1); let _ = an_option.take(); @@ -31,6 +41,10 @@ fn replace_with_default() { let s = &mut String::from("foo"); let _ = std::mem::take(s); let _ = std::mem::take(s); + + // dont lint within macros + take!(s); + take_external!(s); } fn main() { diff --git a/tests/ui/mem_replace.rs b/tests/ui/mem_replace.rs index eac0ce586a088..c116107a923c6 100644 --- a/tests/ui/mem_replace.rs +++ b/tests/ui/mem_replace.rs @@ -8,6 +8,7 @@ // except according to those terms. // run-rustfix +// aux-build:macro_rules.rs #![allow(unused_imports)] #![warn( clippy::all, @@ -16,8 +17,17 @@ clippy::mem_replace_with_default )] +#[macro_use] +extern crate macro_rules; + use std::mem; +macro_rules! take { + ($s:expr) => { + std::mem::replace($s, Default::default()) + }; +} + fn replace_option_with_none() { let mut an_option = Some(1); let _ = mem::replace(&mut an_option, None); @@ -31,6 +41,10 @@ fn replace_with_default() { let s = &mut String::from("foo"); let _ = std::mem::replace(s, String::default()); let _ = std::mem::replace(s, Default::default()); + + // dont lint within macros + take!(s); + take_external!(s); } fn main() { diff --git a/tests/ui/mem_replace.stderr b/tests/ui/mem_replace.stderr index d5dc66873b2fe..9c925cefb04cb 100644 --- a/tests/ui/mem_replace.stderr +++ b/tests/ui/mem_replace.stderr @@ -1,5 +1,5 @@ error: replacing an `Option` with `None` - --> $DIR/mem_replace.rs:23:13 + --> $DIR/mem_replace.rs:33:13 | LL | let _ = mem::replace(&mut an_option, None); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider `Option::take()` instead: `an_option.take()` @@ -7,13 +7,13 @@ LL | let _ = mem::replace(&mut an_option, None); = note: `-D clippy::mem-replace-option-with-none` implied by `-D warnings` error: replacing an `Option` with `None` - --> $DIR/mem_replace.rs:25:13 + --> $DIR/mem_replace.rs:35:13 | LL | let _ = mem::replace(an_option, None); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider `Option::take()` instead: `an_option.take()` error: replacing a value of type `T` with `T::default()` is better expressed using `std::mem::take` - --> $DIR/mem_replace.rs:30:13 + --> $DIR/mem_replace.rs:40:13 | LL | let _ = std::mem::replace(&mut s, String::default()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::mem::take(&mut s)` @@ -21,13 +21,13 @@ LL | let _ = std::mem::replace(&mut s, String::default()); = note: `-D clippy::mem-replace-with-default` implied by `-D warnings` error: replacing a value of type `T` with `T::default()` is better expressed using `std::mem::take` - --> $DIR/mem_replace.rs:32:13 + --> $DIR/mem_replace.rs:42:13 | LL | let _ = std::mem::replace(s, String::default()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::mem::take(s)` error: replacing a value of type `T` with `T::default()` is better expressed using `std::mem::take` - --> $DIR/mem_replace.rs:33:13 + --> $DIR/mem_replace.rs:43:13 | LL | let _ = std::mem::replace(s, Default::default()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::mem::take(s)` From 78b4dfc57cffd96c5f48b0bc0b350066ab1d0ceb Mon Sep 17 00:00:00 2001 From: Krishna Veera Reddy Date: Wed, 18 Dec 2019 22:15:55 -0800 Subject: [PATCH 4/8] Move `mem_replace_with_default` out of nursery --- clippy_lints/src/lib.rs | 3 ++- clippy_lints/src/mem_replace.rs | 2 +- src/lintlist/mod.rs | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/clippy_lints/src/lib.rs b/clippy_lints/src/lib.rs index abcddc88527ca..3aace11716e7d 100644 --- a/clippy_lints/src/lib.rs +++ b/clippy_lints/src/lib.rs @@ -1183,6 +1183,7 @@ pub fn register_plugins(store: &mut lint::LintStore, sess: &Session, conf: &Conf LintId::of(&matches::SINGLE_MATCH), LintId::of(&mem_discriminant::MEM_DISCRIMINANT_NON_ENUM), LintId::of(&mem_replace::MEM_REPLACE_OPTION_WITH_NONE), + LintId::of(&mem_replace::MEM_REPLACE_WITH_DEFAULT), LintId::of(&mem_replace::MEM_REPLACE_WITH_UNINIT), LintId::of(&methods::CHARS_LAST_CMP), LintId::of(&methods::CHARS_NEXT_CMP), @@ -1370,6 +1371,7 @@ pub fn register_plugins(store: &mut lint::LintStore, sess: &Session, conf: &Conf LintId::of(&matches::MATCH_WILD_ERR_ARM), LintId::of(&matches::SINGLE_MATCH), LintId::of(&mem_replace::MEM_REPLACE_OPTION_WITH_NONE), + LintId::of(&mem_replace::MEM_REPLACE_WITH_DEFAULT), LintId::of(&methods::CHARS_LAST_CMP), LintId::of(&methods::INTO_ITER_ON_REF), LintId::of(&methods::ITER_CLONED_COLLECT), @@ -1595,7 +1597,6 @@ pub fn register_plugins(store: &mut lint::LintStore, sess: &Session, conf: &Conf store.register_group(true, "clippy::nursery", Some("clippy_nursery"), vec![ LintId::of(&attrs::EMPTY_LINE_AFTER_OUTER_ATTR), LintId::of(&fallible_impl_from::FALLIBLE_IMPL_FROM), - LintId::of(&mem_replace::MEM_REPLACE_WITH_DEFAULT), LintId::of(&missing_const_for_fn::MISSING_CONST_FOR_FN), LintId::of(&mul_add::MANUAL_MUL_ADD), LintId::of(&mutex_atomic::MUTEX_INTEGER), diff --git a/clippy_lints/src/mem_replace.rs b/clippy_lints/src/mem_replace.rs index ab0bdb4d02c47..3405ccf06310b 100644 --- a/clippy_lints/src/mem_replace.rs +++ b/clippy_lints/src/mem_replace.rs @@ -87,7 +87,7 @@ declare_clippy_lint! { /// let taken = std::mem::take(&mut text); /// ``` pub MEM_REPLACE_WITH_DEFAULT, - nursery, + style, "replacing a value of type `T` with `T::default()` instead of using `std::mem::take`" } diff --git a/src/lintlist/mod.rs b/src/lintlist/mod.rs index 4b820250c8df0..c396c3ab8a859 100644 --- a/src/lintlist/mod.rs +++ b/src/lintlist/mod.rs @@ -1101,7 +1101,7 @@ pub const ALL_LINTS: [Lint; 342] = [ }, Lint { name: "mem_replace_with_default", - group: "nursery", + group: "style", desc: "replacing a value of type `T` with `T::default()` instead of using `std::mem::take`", deprecation: None, module: "mem_replace", From aa66f760c30419ee97af38990476c39ecf38a883 Mon Sep 17 00:00:00 2001 From: Krishna Veera Reddy Date: Sun, 22 Dec 2019 11:05:19 -0800 Subject: [PATCH 5/8] Destructure `mem:replace` arguments --- clippy_lints/src/mem_replace.rs | 40 ++++++++++++++++----------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/clippy_lints/src/mem_replace.rs b/clippy_lints/src/mem_replace.rs index 3405ccf06310b..4e0d2c24f751a 100644 --- a/clippy_lints/src/mem_replace.rs +++ b/clippy_lints/src/mem_replace.rs @@ -3,10 +3,11 @@ use crate::utils::{ }; use if_chain::if_chain; use rustc::declare_lint_pass; -use rustc::hir::{BorrowKind, Expr, ExprKind, HirVec, Mutability, QPath}; +use rustc::hir::{BorrowKind, Expr, ExprKind, Mutability, QPath}; use rustc::lint::{in_external_macro, LateContext, LateLintPass, LintArray, LintPass}; use rustc_errors::Applicability; use rustc_session::declare_tool_lint; +use syntax::source_map::Span; declare_clippy_lint! { /// **What it does:** Checks for `mem::replace()` on an `Option` with @@ -94,8 +95,8 @@ declare_clippy_lint! { declare_lint_pass!(MemReplace => [MEM_REPLACE_OPTION_WITH_NONE, MEM_REPLACE_WITH_UNINIT, MEM_REPLACE_WITH_DEFAULT]); -fn check_replace_option_with_none(cx: &LateContext<'_, '_>, expr: &'_ Expr, args: &HirVec) { - if let ExprKind::Path(ref replacement_qpath) = args[1].kind { +fn check_replace_option_with_none(cx: &LateContext<'_, '_>, src: &Expr, dest: &Expr, expr_span: Span) { + if let ExprKind::Path(ref replacement_qpath) = src.kind { // Check that second argument is `Option::None` if match_qpath(replacement_qpath, &paths::OPTION_NONE) { // Since this is a late pass (already type-checked), @@ -103,7 +104,7 @@ fn check_replace_option_with_none(cx: &LateContext<'_, '_>, expr: &'_ Expr, args // `Option`, we do not need to check the first // argument's type. All that's left is to get // replacee's path. - let replaced_path = match args[0].kind { + let replaced_path = match dest.kind { ExprKind::AddrOf(BorrowKind::Ref, Mutability::Mut, ref replaced) => { if let ExprKind::Path(QPath::Resolved(None, ref replaced_path)) = replaced.kind { replaced_path @@ -119,7 +120,7 @@ fn check_replace_option_with_none(cx: &LateContext<'_, '_>, expr: &'_ Expr, args span_lint_and_sugg( cx, MEM_REPLACE_OPTION_WITH_NONE, - expr.span, + expr_span, "replacing an `Option` with `None`", "consider `Option::take()` instead", format!( @@ -132,8 +133,8 @@ fn check_replace_option_with_none(cx: &LateContext<'_, '_>, expr: &'_ Expr, args } } -fn check_replace_with_uninit(cx: &LateContext<'_, '_>, expr: &'_ Expr, args: &HirVec) { - if let ExprKind::Call(ref repl_func, ref repl_args) = args[1].kind { +fn check_replace_with_uninit(cx: &LateContext<'_, '_>, src: &Expr, expr_span: Span) { + if let ExprKind::Call(ref repl_func, ref repl_args) = src.kind { if_chain! { if repl_args.is_empty(); if let ExprKind::Path(ref repl_func_qpath) = repl_func.kind; @@ -143,16 +144,16 @@ fn check_replace_with_uninit(cx: &LateContext<'_, '_>, expr: &'_ Expr, args: &Hi span_help_and_lint( cx, MEM_REPLACE_WITH_UNINIT, - expr.span, + expr_span, "replacing with `mem::uninitialized()`", "consider using the `take_mut` crate instead", ); } else if match_def_path(cx, repl_def_id, &paths::MEM_ZEROED) && - !cx.tables.expr_ty(&args[1]).is_primitive() { + !cx.tables.expr_ty(src).is_primitive() { span_help_and_lint( cx, MEM_REPLACE_WITH_UNINIT, - expr.span, + expr_span, "replacing with `mem::zeroed()`", "consider using a default value or the `take_mut` crate instead", ); @@ -162,10 +163,10 @@ fn check_replace_with_uninit(cx: &LateContext<'_, '_>, expr: &'_ Expr, args: &Hi } } -fn check_replace_with_default(cx: &LateContext<'_, '_>, expr: &'_ Expr, args: &HirVec) { - if let ExprKind::Call(ref repl_func, _) = args[1].kind { +fn check_replace_with_default(cx: &LateContext<'_, '_>, src: &Expr, dest: &Expr, expr_span: Span) { + if let ExprKind::Call(ref repl_func, _) = src.kind { if_chain! { - if !in_macro(expr.span) && !in_external_macro(cx.tcx.sess, expr.span); + if !in_macro(expr_span) && !in_external_macro(cx.tcx.sess, expr_span); if let ExprKind::Path(ref repl_func_qpath) = repl_func.kind; if let Some(repl_def_id) = cx.tables.qpath_res(repl_func_qpath, repl_func.hir_id).opt_def_id(); if match_def_path(cx, repl_def_id, &paths::DEFAULT_TRAIT_METHOD); @@ -175,12 +176,12 @@ fn check_replace_with_default(cx: &LateContext<'_, '_>, expr: &'_ Expr, args: &H span_lint_and_sugg( cx, MEM_REPLACE_WITH_DEFAULT, - expr.span, + expr_span, "replacing a value of type `T` with `T::default()` is better expressed using `std::mem::take`", "consider using", format!( "std::mem::take({})", - snippet_with_applicability(cx, args[0].span, "", &mut applicability) + snippet_with_applicability(cx, dest.span, "", &mut applicability) ), applicability, ); @@ -194,15 +195,14 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MemReplace { if_chain! { // Check that `expr` is a call to `mem::replace()` if let ExprKind::Call(ref func, ref func_args) = expr.kind; - if func_args.len() == 2; if let ExprKind::Path(ref func_qpath) = func.kind; if let Some(def_id) = cx.tables.qpath_res(func_qpath, func.hir_id).opt_def_id(); if match_def_path(cx, def_id, &paths::MEM_REPLACE); - + if let [dest, src] = &**func_args; then { - check_replace_option_with_none(cx, expr, &func_args); - check_replace_with_uninit(cx, expr, &func_args); - check_replace_with_default(cx, expr, &func_args); + check_replace_option_with_none(cx, src, dest, expr.span); + check_replace_with_uninit(cx, src, expr.span); + check_replace_with_default(cx, src, dest, expr.span); } } } From c09e79e226502ad2687163b9581a2034b4a7e225 Mon Sep 17 00:00:00 2001 From: Krishna Veera Reddy Date: Tue, 24 Dec 2019 07:59:35 -0800 Subject: [PATCH 6/8] Lint within internal macros without a suggestion --- clippy_lints/src/mem_replace.rs | 27 ++++++++++++++++----------- tests/ui/mem_replace.fixed | 14 -------------- tests/ui/mem_replace.rs | 14 -------------- tests/ui/mem_replace.stderr | 10 +++++----- tests/ui/mem_replace_macro.rs | 23 +++++++++++++++++++++++ tests/ui/mem_replace_macro.stderr | 13 +++++++++++++ 6 files changed, 57 insertions(+), 44 deletions(-) create mode 100644 tests/ui/mem_replace_macro.rs create mode 100644 tests/ui/mem_replace_macro.stderr diff --git a/clippy_lints/src/mem_replace.rs b/clippy_lints/src/mem_replace.rs index 4e0d2c24f751a..17a088e09a082 100644 --- a/clippy_lints/src/mem_replace.rs +++ b/clippy_lints/src/mem_replace.rs @@ -1,5 +1,6 @@ use crate::utils::{ - in_macro, match_def_path, match_qpath, paths, snippet_with_applicability, span_help_and_lint, span_lint_and_sugg, + in_macro, match_def_path, match_qpath, paths, snippet, snippet_with_applicability, span_help_and_lint, + span_lint_and_sugg, span_lint_and_then, }; use if_chain::if_chain; use rustc::declare_lint_pass; @@ -166,24 +167,28 @@ fn check_replace_with_uninit(cx: &LateContext<'_, '_>, src: &Expr, expr_span: Sp fn check_replace_with_default(cx: &LateContext<'_, '_>, src: &Expr, dest: &Expr, expr_span: Span) { if let ExprKind::Call(ref repl_func, _) = src.kind { if_chain! { - if !in_macro(expr_span) && !in_external_macro(cx.tcx.sess, expr_span); + if !in_external_macro(cx.tcx.sess, expr_span); if let ExprKind::Path(ref repl_func_qpath) = repl_func.kind; if let Some(repl_def_id) = cx.tables.qpath_res(repl_func_qpath, repl_func.hir_id).opt_def_id(); if match_def_path(cx, repl_def_id, &paths::DEFAULT_TRAIT_METHOD); then { - let mut applicability = Applicability::MachineApplicable; - - span_lint_and_sugg( + span_lint_and_then( cx, MEM_REPLACE_WITH_DEFAULT, expr_span, "replacing a value of type `T` with `T::default()` is better expressed using `std::mem::take`", - "consider using", - format!( - "std::mem::take({})", - snippet_with_applicability(cx, dest.span, "", &mut applicability) - ), - applicability, + |db| { + if !in_macro(expr_span) { + let suggestion = format!("std::mem::take({})", snippet(cx, dest.span, "")); + + db.span_suggestion( + expr_span, + "consider using", + suggestion, + Applicability::MachineApplicable + ); + } + } ); } } diff --git a/tests/ui/mem_replace.fixed b/tests/ui/mem_replace.fixed index 8606e98335dfe..58657b934fbfe 100644 --- a/tests/ui/mem_replace.fixed +++ b/tests/ui/mem_replace.fixed @@ -8,7 +8,6 @@ // except according to those terms. // run-rustfix -// aux-build:macro_rules.rs #![allow(unused_imports)] #![warn( clippy::all, @@ -17,17 +16,8 @@ clippy::mem_replace_with_default )] -#[macro_use] -extern crate macro_rules; - use std::mem; -macro_rules! take { - ($s:expr) => { - std::mem::replace($s, Default::default()) - }; -} - fn replace_option_with_none() { let mut an_option = Some(1); let _ = an_option.take(); @@ -41,10 +31,6 @@ fn replace_with_default() { let s = &mut String::from("foo"); let _ = std::mem::take(s); let _ = std::mem::take(s); - - // dont lint within macros - take!(s); - take_external!(s); } fn main() { diff --git a/tests/ui/mem_replace.rs b/tests/ui/mem_replace.rs index c116107a923c6..eac0ce586a088 100644 --- a/tests/ui/mem_replace.rs +++ b/tests/ui/mem_replace.rs @@ -8,7 +8,6 @@ // except according to those terms. // run-rustfix -// aux-build:macro_rules.rs #![allow(unused_imports)] #![warn( clippy::all, @@ -17,17 +16,8 @@ clippy::mem_replace_with_default )] -#[macro_use] -extern crate macro_rules; - use std::mem; -macro_rules! take { - ($s:expr) => { - std::mem::replace($s, Default::default()) - }; -} - fn replace_option_with_none() { let mut an_option = Some(1); let _ = mem::replace(&mut an_option, None); @@ -41,10 +31,6 @@ fn replace_with_default() { let s = &mut String::from("foo"); let _ = std::mem::replace(s, String::default()); let _ = std::mem::replace(s, Default::default()); - - // dont lint within macros - take!(s); - take_external!(s); } fn main() { diff --git a/tests/ui/mem_replace.stderr b/tests/ui/mem_replace.stderr index 9c925cefb04cb..d5dc66873b2fe 100644 --- a/tests/ui/mem_replace.stderr +++ b/tests/ui/mem_replace.stderr @@ -1,5 +1,5 @@ error: replacing an `Option` with `None` - --> $DIR/mem_replace.rs:33:13 + --> $DIR/mem_replace.rs:23:13 | LL | let _ = mem::replace(&mut an_option, None); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider `Option::take()` instead: `an_option.take()` @@ -7,13 +7,13 @@ LL | let _ = mem::replace(&mut an_option, None); = note: `-D clippy::mem-replace-option-with-none` implied by `-D warnings` error: replacing an `Option` with `None` - --> $DIR/mem_replace.rs:35:13 + --> $DIR/mem_replace.rs:25:13 | LL | let _ = mem::replace(an_option, None); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider `Option::take()` instead: `an_option.take()` error: replacing a value of type `T` with `T::default()` is better expressed using `std::mem::take` - --> $DIR/mem_replace.rs:40:13 + --> $DIR/mem_replace.rs:30:13 | LL | let _ = std::mem::replace(&mut s, String::default()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::mem::take(&mut s)` @@ -21,13 +21,13 @@ LL | let _ = std::mem::replace(&mut s, String::default()); = note: `-D clippy::mem-replace-with-default` implied by `-D warnings` error: replacing a value of type `T` with `T::default()` is better expressed using `std::mem::take` - --> $DIR/mem_replace.rs:42:13 + --> $DIR/mem_replace.rs:32:13 | LL | let _ = std::mem::replace(s, String::default()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::mem::take(s)` error: replacing a value of type `T` with `T::default()` is better expressed using `std::mem::take` - --> $DIR/mem_replace.rs:43:13 + --> $DIR/mem_replace.rs:33:13 | LL | let _ = std::mem::replace(s, Default::default()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::mem::take(s)` diff --git a/tests/ui/mem_replace_macro.rs b/tests/ui/mem_replace_macro.rs new file mode 100644 index 0000000000000..e67e01737ba6d --- /dev/null +++ b/tests/ui/mem_replace_macro.rs @@ -0,0 +1,23 @@ +// aux-build:macro_rules.rs +#![warn(clippy::mem_replace_with_default)] + +#[macro_use] +extern crate macro_rules; + +use std::mem; + +macro_rules! take { + ($s:expr) => { + std::mem::replace($s, Default::default()) + }; +} + +fn replace_with_default() { + let s = &mut String::from("foo"); + take!(s); + take_external!(s); +} + +fn main() { + replace_with_default(); +} diff --git a/tests/ui/mem_replace_macro.stderr b/tests/ui/mem_replace_macro.stderr new file mode 100644 index 0000000000000..d7830331b29f3 --- /dev/null +++ b/tests/ui/mem_replace_macro.stderr @@ -0,0 +1,13 @@ +error: replacing a value of type `T` with `T::default()` is better expressed using `std::mem::take` + --> $DIR/mem_replace_macro.rs:11:9 + | +LL | std::mem::replace($s, Default::default()) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +... +LL | take!(s); + | --------- in this macro invocation + | + = note: `-D clippy::mem-replace-with-default` implied by `-D warnings` + +error: aborting due to previous error + From a8413a32b379788d9610a78f6a2352a26a0d02e7 Mon Sep 17 00:00:00 2001 From: Krishna Veera Reddy Date: Tue, 24 Dec 2019 08:26:58 -0800 Subject: [PATCH 7/8] Remove unnecessary import --- tests/ui/mem_replace_macro.rs | 2 -- tests/ui/mem_replace_macro.stderr | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/tests/ui/mem_replace_macro.rs b/tests/ui/mem_replace_macro.rs index e67e01737ba6d..0c09344b80d10 100644 --- a/tests/ui/mem_replace_macro.rs +++ b/tests/ui/mem_replace_macro.rs @@ -4,8 +4,6 @@ #[macro_use] extern crate macro_rules; -use std::mem; - macro_rules! take { ($s:expr) => { std::mem::replace($s, Default::default()) diff --git a/tests/ui/mem_replace_macro.stderr b/tests/ui/mem_replace_macro.stderr index d7830331b29f3..a0872b1a6bf4e 100644 --- a/tests/ui/mem_replace_macro.stderr +++ b/tests/ui/mem_replace_macro.stderr @@ -1,5 +1,5 @@ error: replacing a value of type `T` with `T::default()` is better expressed using `std::mem::take` - --> $DIR/mem_replace_macro.rs:11:9 + --> $DIR/mem_replace_macro.rs:9:9 | LL | std::mem::replace($s, Default::default()) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ From 42e4595d3ab7844d840ab4ef3fa8eb80116484f6 Mon Sep 17 00:00:00 2001 From: Krishna Veera Reddy Date: Sat, 28 Dec 2019 21:52:08 -0800 Subject: [PATCH 8/8] Indicate anonymous lifetimes for types --- README.md | 2 +- clippy_lints/src/mem_replace.rs | 6 +++--- src/lintlist/mod.rs | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 01fc20f0f27d9..215ad6f563012 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ A collection of lints to catch common mistakes and improve your [Rust](https://github.com/rust-lang/rust) code. -[There are 342 lints included in this crate!](https://rust-lang.github.io/rust-clippy/master/index.html) +[There are 343 lints included in this crate!](https://rust-lang.github.io/rust-clippy/master/index.html) We have a bunch of lint categories to allow you to choose how much Clippy is supposed to ~~annoy~~ help you: diff --git a/clippy_lints/src/mem_replace.rs b/clippy_lints/src/mem_replace.rs index 17a088e09a082..5a1e3b73ded7e 100644 --- a/clippy_lints/src/mem_replace.rs +++ b/clippy_lints/src/mem_replace.rs @@ -96,7 +96,7 @@ declare_clippy_lint! { declare_lint_pass!(MemReplace => [MEM_REPLACE_OPTION_WITH_NONE, MEM_REPLACE_WITH_UNINIT, MEM_REPLACE_WITH_DEFAULT]); -fn check_replace_option_with_none(cx: &LateContext<'_, '_>, src: &Expr, dest: &Expr, expr_span: Span) { +fn check_replace_option_with_none(cx: &LateContext<'_, '_>, src: &Expr<'_>, dest: &Expr<'_>, expr_span: Span) { if let ExprKind::Path(ref replacement_qpath) = src.kind { // Check that second argument is `Option::None` if match_qpath(replacement_qpath, &paths::OPTION_NONE) { @@ -134,7 +134,7 @@ fn check_replace_option_with_none(cx: &LateContext<'_, '_>, src: &Expr, dest: &E } } -fn check_replace_with_uninit(cx: &LateContext<'_, '_>, src: &Expr, expr_span: Span) { +fn check_replace_with_uninit(cx: &LateContext<'_, '_>, src: &Expr<'_>, expr_span: Span) { if let ExprKind::Call(ref repl_func, ref repl_args) = src.kind { if_chain! { if repl_args.is_empty(); @@ -164,7 +164,7 @@ fn check_replace_with_uninit(cx: &LateContext<'_, '_>, src: &Expr, expr_span: Sp } } -fn check_replace_with_default(cx: &LateContext<'_, '_>, src: &Expr, dest: &Expr, expr_span: Span) { +fn check_replace_with_default(cx: &LateContext<'_, '_>, src: &Expr<'_>, dest: &Expr<'_>, expr_span: Span) { if let ExprKind::Call(ref repl_func, _) = src.kind { if_chain! { if !in_external_macro(cx.tcx.sess, expr_span); diff --git a/src/lintlist/mod.rs b/src/lintlist/mod.rs index c396c3ab8a859..cd3336bdb3784 100644 --- a/src/lintlist/mod.rs +++ b/src/lintlist/mod.rs @@ -6,7 +6,7 @@ pub use lint::Lint; pub use lint::LINT_LEVELS; // begin lint list, do not remove this comment, it’s used in `update_lints` -pub const ALL_LINTS: [Lint; 342] = [ +pub const ALL_LINTS: [Lint; 343] = [ Lint { name: "absurd_extreme_comparisons", group: "correctness",