Skip to content

Commit 0f87a81

Browse files
committed
Auto merge of #12822 - Alexendoo:for-each-expr, r=dswij
Make `for_each_expr` visit closures by default, rename the old version `for_each_expr_without_closures` A lot of the time `for_each_expr` is picked when closures should be visited so I think it makes sense for this to be the default with the alternative available for when you don't need to visit them. The first commit renames `for_each_expr` to `for_each_expr_without_closures` and `for_each_expr_with_closures` to `for_each_expr` The second commit switches a few uses that I caught over to include closures to fix a few bugs changelog: none
2 parents 0b441d5 + 68e7356 commit 0f87a81

40 files changed

+148
-88
lines changed

clippy_lints/src/blocks_in_conditions.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use clippy_utils::diagnostics::{span_lint, span_lint_and_sugg};
22
use clippy_utils::source::snippet_block_with_applicability;
33
use clippy_utils::ty::implements_trait;
4-
use clippy_utils::visitors::{for_each_expr, Descend};
4+
use clippy_utils::visitors::{for_each_expr_without_closures, Descend};
55
use clippy_utils::{get_parent_expr, higher, is_from_proc_macro};
66
use core::ops::ControlFlow;
77
use rustc_errors::Applicability;
@@ -125,7 +125,7 @@ impl<'tcx> LateLintPass<'tcx> for BlocksInConditions {
125125
}
126126
}
127127
} else {
128-
let _: Option<!> = for_each_expr(cond, |e| {
128+
let _: Option<!> = for_each_expr_without_closures(cond, |e| {
129129
if let ExprKind::Closure(closure) = e.kind {
130130
// do not lint if the closure is called using an iterator (see #1141)
131131
if let Some(parent) = get_parent_expr(cx, e)

clippy_lints/src/casts/cast_sign_loss.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::ops::ControlFlow;
33

44
use clippy_utils::consts::{constant, Constant};
55
use clippy_utils::diagnostics::span_lint;
6-
use clippy_utils::visitors::{for_each_expr, Descend};
6+
use clippy_utils::visitors::{for_each_expr_without_closures, Descend};
77
use clippy_utils::{method_chain_args, sext};
88
use rustc_hir::{BinOpKind, Expr, ExprKind};
99
use rustc_lint::LateContext;
@@ -266,7 +266,7 @@ fn expr_add_sign(cx: &LateContext<'_>, expr: &Expr<'_>) -> Sign {
266266
fn exprs_with_muldiv_binop_peeled<'e>(expr: &'e Expr<'_>) -> Vec<&'e Expr<'e>> {
267267
let mut res = vec![];
268268

269-
for_each_expr(expr, |sub_expr| -> ControlFlow<Infallible, Descend> {
269+
for_each_expr_without_closures(expr, |sub_expr| -> ControlFlow<Infallible, Descend> {
270270
// We don't check for mul/div/rem methods here, but we could.
271271
if let ExprKind::Binary(op, lhs, _rhs) = sub_expr.kind {
272272
if matches!(op.node, BinOpKind::Mul | BinOpKind::Div) {
@@ -315,7 +315,7 @@ fn exprs_with_muldiv_binop_peeled<'e>(expr: &'e Expr<'_>) -> Vec<&'e Expr<'e>> {
315315
fn exprs_with_add_binop_peeled<'e>(expr: &'e Expr<'_>) -> Vec<&'e Expr<'e>> {
316316
let mut res = vec![];
317317

318-
for_each_expr(expr, |sub_expr| -> ControlFlow<Infallible, Descend> {
318+
for_each_expr_without_closures(expr, |sub_expr| -> ControlFlow<Infallible, Descend> {
319319
// We don't check for add methods here, but we could.
320320
if let ExprKind::Binary(op, _lhs, _rhs) = sub_expr.kind {
321321
if matches!(op.node, BinOpKind::Add) {

clippy_lints/src/casts/unnecessary_cast.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use clippy_utils::diagnostics::span_lint_and_sugg;
22
use clippy_utils::numeric_literal::NumericLiteral;
33
use clippy_utils::source::snippet_opt;
4-
use clippy_utils::visitors::{for_each_expr, Visitable};
4+
use clippy_utils::visitors::{for_each_expr_without_closures, Visitable};
55
use clippy_utils::{get_parent_expr, is_hir_ty_cfg_dependant, is_ty_alias, path_to_local};
66
use rustc_ast::{LitFloatType, LitIntType, LitKind};
77
use rustc_errors::Applicability;
@@ -245,7 +245,7 @@ fn fp_ty_mantissa_nbits(typ: Ty<'_>) -> u32 {
245245
/// TODO: Maybe we should move this to `clippy_utils` so others won't need to go down this dark,
246246
/// dark path reimplementing this (or something similar).
247247
fn is_cast_from_ty_alias<'tcx>(cx: &LateContext<'tcx>, expr: impl Visitable<'tcx>, cast_from: Ty<'tcx>) -> bool {
248-
for_each_expr(expr, |expr| {
248+
for_each_expr_without_closures(expr, |expr| {
249249
// Calls are a `Path`, and usage of locals are a `Path`. So, this checks
250250
// - call() as i32
251251
// - local as i32

clippy_lints/src/cognitive_complexity.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
use clippy_utils::diagnostics::span_lint_and_help;
44
use clippy_utils::source::snippet_opt;
55
use clippy_utils::ty::is_type_diagnostic_item;
6-
use clippy_utils::visitors::for_each_expr;
6+
use clippy_utils::visitors::for_each_expr_without_closures;
77
use clippy_utils::{get_async_fn_body, is_async_fn, LimitStack};
88
use core::ops::ControlFlow;
99
use rustc_ast::ast::Attribute;
@@ -65,7 +65,7 @@ impl CognitiveComplexity {
6565

6666
let mut cc = 1u64;
6767
let mut returns = 0u64;
68-
let _: Option<!> = for_each_expr(expr, |e| {
68+
let _: Option<!> = for_each_expr_without_closures(expr, |e| {
6969
match e.kind {
7070
ExprKind::If(_, _, _) => {
7171
cc += 1;

clippy_lints/src/collection_is_never_read.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use clippy_utils::diagnostics::span_lint;
22
use clippy_utils::ty::{is_type_diagnostic_item, is_type_lang_item};
3-
use clippy_utils::visitors::{for_each_expr_with_closures, Visitable};
3+
use clippy_utils::visitors::{for_each_expr, Visitable};
44
use clippy_utils::{get_enclosing_block, path_to_local_id};
55
use core::ops::ControlFlow;
66
use rustc_hir::{Body, ExprKind, HirId, LangItem, LetStmt, Node, PatKind};
@@ -82,7 +82,7 @@ fn has_no_read_access<'tcx, T: Visitable<'tcx>>(cx: &LateContext<'tcx>, id: HirI
8282
let mut has_read_access = false;
8383

8484
// Inspect all expressions and sub-expressions in the block.
85-
for_each_expr_with_closures(cx, block, |expr| {
85+
for_each_expr(cx, block, |expr| {
8686
// Ignore expressions that are not simply `id`.
8787
if !path_to_local_id(expr, id) {
8888
return ControlFlow::Continue(());

clippy_lints/src/copies.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use clippy_utils::diagnostics::{span_lint_and_note, span_lint_and_then};
22
use clippy_utils::source::{first_line_of_span, indent_of, reindent_multiline, snippet, snippet_opt};
33
use clippy_utils::ty::{needs_ordered_drop, InteriorMut};
4-
use clippy_utils::visitors::for_each_expr;
4+
use clippy_utils::visitors::for_each_expr_without_closures;
55
use clippy_utils::{
66
capture_local_usage, eq_expr_value, find_binding_init, get_enclosing_block, hash_expr, hash_stmt, if_sequence,
77
is_else_clause, is_lint_allowed, path_to_local, search_same, ContainsName, HirEqInterExpr, SpanlessEq,
@@ -362,7 +362,7 @@ fn eq_binding_names(s: &Stmt<'_>, names: &[(HirId, Symbol)]) -> bool {
362362

363363
/// Checks if the statement modifies or moves any of the given locals.
364364
fn modifies_any_local<'tcx>(cx: &LateContext<'tcx>, s: &'tcx Stmt<'_>, locals: &HirIdSet) -> bool {
365-
for_each_expr(s, |e| {
365+
for_each_expr_without_closures(s, |e| {
366366
if let Some(id) = path_to_local(e)
367367
&& locals.contains(&id)
368368
&& !capture_local_usage(cx, e).is_imm_ref()
@@ -413,7 +413,7 @@ fn scan_block_for_eq<'tcx>(
413413

414414
let mut cond_locals = HirIdSet::default();
415415
for &cond in conds {
416-
let _: Option<!> = for_each_expr(cond, |e| {
416+
let _: Option<!> = for_each_expr_without_closures(cond, |e| {
417417
if let Some(id) = path_to_local(e) {
418418
cond_locals.insert(id);
419419
}

clippy_lints/src/functions/must_use.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use clippy_utils::attrs::is_proc_macro;
1414
use clippy_utils::diagnostics::{span_lint_and_help, span_lint_and_then};
1515
use clippy_utils::source::snippet_opt;
1616
use clippy_utils::ty::is_must_use_ty;
17-
use clippy_utils::visitors::for_each_expr;
17+
use clippy_utils::visitors::for_each_expr_without_closures;
1818
use clippy_utils::{return_ty, trait_ref_of_method};
1919

2020
use core::ops::ControlFlow;
@@ -226,7 +226,7 @@ fn is_mutated_static(e: &hir::Expr<'_>) -> bool {
226226
}
227227

228228
fn mutates_static<'tcx>(cx: &LateContext<'tcx>, body: &'tcx hir::Body<'_>) -> bool {
229-
for_each_expr(body.value, |e| {
229+
for_each_expr_without_closures(body.value, |e| {
230230
use hir::ExprKind::{AddrOf, Assign, AssignOp, Call, MethodCall};
231231

232232
match e.kind {

clippy_lints/src/functions/not_unsafe_ptr_arg_deref.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use rustc_span::def_id::LocalDefId;
55

66
use clippy_utils::diagnostics::span_lint;
77
use clippy_utils::ty::type_is_unsafe_function;
8-
use clippy_utils::visitors::for_each_expr_with_closures;
8+
use clippy_utils::visitors::for_each_expr;
99
use clippy_utils::{iter_input_pats, path_to_local};
1010

1111
use core::ops::ControlFlow;
@@ -49,7 +49,7 @@ fn check_raw_ptr<'tcx>(
4949

5050
if !raw_ptrs.is_empty() {
5151
let typeck = cx.tcx.typeck_body(body.id());
52-
let _: Option<!> = for_each_expr_with_closures(cx, body.value, |e| {
52+
let _: Option<!> = for_each_expr(cx, body.value, |e| {
5353
match e.kind {
5454
hir::ExprKind::Call(f, args) if type_is_unsafe_function(cx, typeck.expr_ty(f)) => {
5555
for arg in args {

clippy_lints/src/implicit_return.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use clippy_utils::diagnostics::span_lint_hir_and_then;
22
use clippy_utils::source::{snippet_with_applicability, snippet_with_context, walk_span_to_context};
3-
use clippy_utils::visitors::for_each_expr;
3+
use clippy_utils::visitors::for_each_expr_without_closures;
44
use clippy_utils::{get_async_fn_body, is_async_fn};
55
use core::ops::ControlFlow;
66
use rustc_errors::Applicability;
@@ -153,7 +153,7 @@ fn lint_implicit_returns(
153153

154154
ExprKind::Loop(block, ..) => {
155155
let mut add_return = false;
156-
let _: Option<!> = for_each_expr(block, |e| {
156+
let _: Option<!> = for_each_expr_without_closures(block, |e| {
157157
if let ExprKind::Break(dest, sub_expr) = e.kind {
158158
if dest.target_id.ok() == Some(expr.hir_id) {
159159
if call_site_span.is_none() && e.span.ctxt() == ctxt {

clippy_lints/src/matches/redundant_guards.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use clippy_config::msrvs::Msrv;
22
use clippy_utils::diagnostics::span_lint_and_then;
33
use clippy_utils::macros::matching_root_macro_call;
44
use clippy_utils::source::snippet;
5-
use clippy_utils::visitors::{for_each_expr, is_local_used};
5+
use clippy_utils::visitors::{for_each_expr_without_closures, is_local_used};
66
use clippy_utils::{in_constant, path_to_local};
77
use rustc_ast::{BorrowKind, LitKind};
88
use rustc_errors::Applicability;
@@ -249,7 +249,7 @@ fn emit_redundant_guards<'tcx>(
249249
/// an error in the future, and rustc already actively warns against this (see rust#41620),
250250
/// so we don't consider those as usable within patterns for linting purposes.
251251
fn expr_can_be_pat(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool {
252-
for_each_expr(expr, |expr| {
252+
for_each_expr_without_closures(expr, |expr| {
253253
if match expr.kind {
254254
ExprKind::ConstBlock(..) => cx.tcx.features().inline_const_pat,
255255
ExprKind::Call(c, ..) if let ExprKind::Path(qpath) = c.kind => {

clippy_lints/src/matches/redundant_pattern_match.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use clippy_utils::diagnostics::{span_lint_and_sugg, span_lint_and_then};
33
use clippy_utils::source::{snippet, walk_span_to_context};
44
use clippy_utils::sugg::{make_unop, Sugg};
55
use clippy_utils::ty::{is_type_diagnostic_item, needs_ordered_drop};
6-
use clippy_utils::visitors::{any_temporaries_need_ordered_drop, for_each_expr};
6+
use clippy_utils::visitors::{any_temporaries_need_ordered_drop, for_each_expr_without_closures};
77
use clippy_utils::{higher, is_expn_of, is_trait_method};
88
use rustc_ast::ast::LitKind;
99
use rustc_errors::Applicability;
@@ -283,7 +283,7 @@ pub(super) fn check_match<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, op
283283
// to see that there aren't any let chains anywhere in the guard, as that would break
284284
// if we suggest `t.is_none() && (let X = y && z)` for:
285285
// `match t { None if let X = y && z => true, _ => false }`
286-
let has_nested_let_chain = for_each_expr(guard, |expr| {
286+
let has_nested_let_chain = for_each_expr_without_closures(guard, |expr| {
287287
if matches!(expr.kind, ExprKind::Let(..)) {
288288
ControlFlow::Break(())
289289
} else {

clippy_lints/src/methods/collapsible_str_replace.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use clippy_utils::diagnostics::span_lint_and_sugg;
22
use clippy_utils::source::snippet;
3-
use clippy_utils::visitors::for_each_expr;
3+
use clippy_utils::visitors::for_each_expr_without_closures;
44
use clippy_utils::{eq_expr_value, get_parent_expr};
55
use core::ops::ControlFlow;
66
use rustc_errors::Applicability;
@@ -46,7 +46,7 @@ fn collect_replace_calls<'tcx>(
4646
let mut methods = VecDeque::new();
4747
let mut from_args = VecDeque::new();
4848

49-
let _: Option<()> = for_each_expr(expr, |e| {
49+
let _: Option<()> = for_each_expr_without_closures(expr, |e| {
5050
if let Some(("replace", _, [from, to], _, _)) = method_call(e) {
5151
if eq_expr_value(cx, to_arg, to) && cx.typeck_results().expr_ty(from).peel_refs().is_char() {
5252
methods.push_front(e);

clippy_lints/src/methods/str_splitn.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use clippy_utils::consts::{constant, Constant};
33
use clippy_utils::diagnostics::{span_lint_and_sugg, span_lint_and_then};
44
use clippy_utils::source::snippet_with_context;
55
use clippy_utils::usage::local_used_after_expr;
6-
use clippy_utils::visitors::{for_each_expr_with_closures, Descend};
6+
use clippy_utils::visitors::{for_each_expr, Descend};
77
use clippy_utils::{is_diag_item_method, match_def_path, path_to_local_id, paths};
88
use core::ops::ControlFlow;
99
use rustc_errors::Applicability;
@@ -209,7 +209,7 @@ fn indirect_usage<'tcx>(
209209
}) = stmt.kind
210210
{
211211
let mut path_to_binding = None;
212-
let _: Option<!> = for_each_expr_with_closures(cx, init_expr, |e| {
212+
let _: Option<!> = for_each_expr(cx, init_expr, |e| {
213213
if path_to_local_id(e, binding) {
214214
path_to_binding = Some(e);
215215
}

clippy_lints/src/methods/unnecessary_filter_map.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use super::utils::clone_or_copy_needed;
22
use clippy_utils::diagnostics::span_lint;
33
use clippy_utils::ty::is_copy;
44
use clippy_utils::usage::mutated_variables;
5-
use clippy_utils::visitors::{for_each_expr, Descend};
5+
use clippy_utils::visitors::{for_each_expr_without_closures, Descend};
66
use clippy_utils::{is_res_lang_ctor, is_trait_method, path_res, path_to_local_id};
77
use core::ops::ControlFlow;
88
use rustc_hir as hir;
@@ -26,7 +26,7 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'tcx>, a
2626

2727
let (mut found_mapping, mut found_filtering) = check_expression(cx, arg_id, body.value);
2828

29-
let _: Option<!> = for_each_expr(body.value, |e| {
29+
let _: Option<!> = for_each_expr_without_closures(body.value, |e| {
3030
if let hir::ExprKind::Ret(Some(e)) = &e.kind {
3131
let (found_mapping_res, found_filtering_res) = check_expression(cx, arg_id, e);
3232
found_mapping |= found_mapping_res;

clippy_lints/src/methods/unnecessary_iter_cloned.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use clippy_utils::diagnostics::span_lint_and_then;
33
use clippy_utils::higher::ForLoop;
44
use clippy_utils::source::snippet_opt;
55
use clippy_utils::ty::{get_iterator_item_ty, implements_trait};
6-
use clippy_utils::visitors::for_each_expr;
6+
use clippy_utils::visitors::for_each_expr_without_closures;
77
use clippy_utils::{can_mut_borrow_both, fn_def_id, get_parent_expr, path_to_local};
88
use core::ops::ControlFlow;
99
use rustc_errors::Applicability;
@@ -61,7 +61,7 @@ pub fn check_for_loop_iter(
6161
fn is_caller_or_fields_change(cx: &LateContext<'_>, body: &Expr<'_>, caller: &Expr<'_>) -> bool {
6262
let mut change = false;
6363
if let ExprKind::Block(block, ..) = body.kind {
64-
for_each_expr(block, |e| {
64+
for_each_expr_without_closures(block, |e| {
6565
match e.kind {
6666
ExprKind::Assign(assignee, _, _) | ExprKind::AssignOp(_, assignee, _) => {
6767
change |= !can_mut_borrow_both(cx, caller, assignee);

clippy_lints/src/missing_asserts_for_indexing.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use std::ops::ControlFlow;
44
use clippy_utils::comparisons::{normalize_comparison, Rel};
55
use clippy_utils::diagnostics::span_lint_and_then;
66
use clippy_utils::source::snippet;
7-
use clippy_utils::visitors::for_each_expr;
7+
use clippy_utils::visitors::for_each_expr_without_closures;
88
use clippy_utils::{eq_expr_value, hash_expr, higher};
99
use rustc_ast::{LitKind, RangeLimits};
1010
use rustc_data_structures::packed::Pu128;
@@ -405,7 +405,7 @@ impl LateLintPass<'_> for MissingAssertsForIndexing {
405405
fn check_body(&mut self, cx: &LateContext<'_>, body: &Body<'_>) {
406406
let mut map = UnhashMap::default();
407407

408-
for_each_expr(body.value, |expr| {
408+
for_each_expr_without_closures(body.value, |expr| {
409409
check_index(cx, expr, &mut map);
410410
check_assert(cx, expr, &mut map);
411411
ControlFlow::<!, ()>::Continue(())

clippy_lints/src/missing_fields_in_debug.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ fn should_lint<'tcx>(
110110
// Is there a call to `DebugStruct::debug_struct`? Do lint if there is.
111111
let mut has_debug_struct = false;
112112

113-
for_each_expr(block, |expr| {
113+
for_each_expr(cx, block, |expr| {
114114
if let ExprKind::MethodCall(path, recv, ..) = &expr.kind {
115115
let recv_ty = typeck_results.expr_ty(recv).peel_refs();
116116

@@ -165,7 +165,7 @@ fn check_struct<'tcx>(
165165
let mut has_direct_field_access = false;
166166
let mut field_accesses = FxHashSet::default();
167167

168-
for_each_expr(block, |expr| {
168+
for_each_expr(cx, block, |expr| {
169169
if let ExprKind::Field(target, ident) = expr.kind
170170
&& let target_ty = typeck_results.expr_ty_adjusted(target).peel_refs()
171171
&& target_ty == self_ty

clippy_lints/src/multiple_unsafe_ops_per_block.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use clippy_utils::diagnostics::span_lint_and_then;
2-
use clippy_utils::visitors::{for_each_expr_with_closures, Descend, Visitable};
2+
use clippy_utils::visitors::{for_each_expr, Descend, Visitable};
33
use core::ops::ControlFlow::Continue;
44
use hir::def::{DefKind, Res};
55
use hir::{BlockCheckMode, ExprKind, QPath, Safety, UnOp};
@@ -96,7 +96,7 @@ fn collect_unsafe_exprs<'tcx>(
9696
node: impl Visitable<'tcx>,
9797
unsafe_ops: &mut Vec<(&'static str, Span)>,
9898
) {
99-
for_each_expr_with_closures(cx, node, |expr| {
99+
for_each_expr(cx, node, |expr| {
100100
match expr.kind {
101101
ExprKind::InlineAsm(_) => unsafe_ops.push(("inline assembly used here", expr.span)),
102102

clippy_lints/src/needless_late_init.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use clippy_utils::diagnostics::span_lint_and_then;
22
use clippy_utils::path_to_local;
33
use clippy_utils::source::snippet_opt;
44
use clippy_utils::ty::needs_ordered_drop;
5-
use clippy_utils::visitors::{for_each_expr, for_each_expr_with_closures, is_local_used};
5+
use clippy_utils::visitors::{for_each_expr, for_each_expr_without_closures, is_local_used};
66
use core::ops::ControlFlow;
77
use rustc_errors::{Applicability, MultiSpan};
88
use rustc_hir::{
@@ -63,7 +63,7 @@ declare_clippy_lint! {
6363
declare_lint_pass!(NeedlessLateInit => [NEEDLESS_LATE_INIT]);
6464

6565
fn contains_assign_expr<'tcx>(cx: &LateContext<'tcx>, stmt: &'tcx Stmt<'tcx>) -> bool {
66-
for_each_expr_with_closures(cx, stmt, |e| {
66+
for_each_expr(cx, stmt, |e| {
6767
if matches!(e.kind, ExprKind::Assign(..)) {
6868
ControlFlow::Break(())
6969
} else {
@@ -74,7 +74,7 @@ fn contains_assign_expr<'tcx>(cx: &LateContext<'tcx>, stmt: &'tcx Stmt<'tcx>) ->
7474
}
7575

7676
fn contains_let(cond: &Expr<'_>) -> bool {
77-
for_each_expr(cond, |e| {
77+
for_each_expr_without_closures(cond, |e| {
7878
if matches!(e.kind, ExprKind::Let(_)) {
7979
ControlFlow::Break(())
8080
} else {

clippy_lints/src/needless_pass_by_ref_mut.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use super::needless_pass_by_value::requires_exact_signature;
22
use clippy_utils::diagnostics::span_lint_hir_and_then;
33
use clippy_utils::source::snippet;
4-
use clippy_utils::visitors::for_each_expr_with_closures;
4+
use clippy_utils::visitors::for_each_expr;
55
use clippy_utils::{inherits_cfg, is_from_proc_macro, is_self};
66
use rustc_data_structures::fx::{FxHashSet, FxIndexMap};
77
use rustc_errors::Applicability;
@@ -205,7 +205,7 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessPassByRefMut<'tcx> {
205205
// We retrieve all the closures declared in the function because they will not be found
206206
// by `euv::Delegate`.
207207
let mut closures: FxHashSet<LocalDefId> = FxHashSet::default();
208-
for_each_expr_with_closures(cx, body, |expr| {
208+
for_each_expr(cx, body, |expr| {
209209
if let ExprKind::Closure(closure) = expr.kind {
210210
closures.insert(closure.def_id);
211211
}

clippy_lints/src/operators/assign_op_pattern.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use clippy_utils::diagnostics::span_lint_and_then;
22
use clippy_utils::source::snippet_opt;
33
use clippy_utils::ty::implements_trait;
4-
use clippy_utils::visitors::for_each_expr;
4+
use clippy_utils::visitors::for_each_expr_without_closures;
55
use clippy_utils::{binop_traits, eq_expr_value, trait_ref_of_method};
66
use core::ops::ControlFlow;
77
use rustc_errors::Applicability;
@@ -62,7 +62,7 @@ pub(super) fn check<'tcx>(
6262
};
6363

6464
let mut found = false;
65-
let found_multiple = for_each_expr(e, |e| {
65+
let found_multiple = for_each_expr_without_closures(e, |e| {
6666
if eq_expr_value(cx, assignee, e) {
6767
if found {
6868
return ControlFlow::Break(());

0 commit comments

Comments
 (0)