Skip to content

Commit c9a78ee

Browse files
committed
Auto merge of rust-lang#99231 - Dylan-DPC:rollup-0tl8c0o, r=Dylan-DPC
Rollup of 5 pull requests Successful merges: - rust-lang#97720 (Always create elided lifetime parameters for functions) - rust-lang#98315 (Stabilize `core::ffi:c_*` and rexport in `std::ffi`) - rust-lang#98705 (Implement `for<>` lifetime binder for closures) - rust-lang#99126 (remove allow(rustc::potential_query_instability) in rustc_span) - rust-lang#99139 (Give a better error when `x dist` fails for an optional tool) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 44f25ba + e275abf commit c9a78ee

35 files changed

+83
-69
lines changed

clippy_lints/src/blocks_in_if_conditions.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use clippy_utils::ty::implements_trait;
66
use if_chain::if_chain;
77
use rustc_errors::Applicability;
88
use rustc_hir::intravisit::{walk_expr, Visitor};
9-
use rustc_hir::{BlockCheckMode, Expr, ExprKind};
9+
use rustc_hir::{BlockCheckMode, Closure, Expr, ExprKind};
1010
use rustc_lint::{LateContext, LateLintPass, LintContext};
1111
use rustc_middle::lint::in_external_macro;
1212
use rustc_session::{declare_lint_pass, declare_tool_lint};
@@ -51,7 +51,7 @@ struct ExVisitor<'a, 'tcx> {
5151

5252
impl<'a, 'tcx> Visitor<'tcx> for ExVisitor<'a, 'tcx> {
5353
fn visit_expr(&mut self, expr: &'tcx Expr<'tcx>) {
54-
if let ExprKind::Closure { body, .. } = expr.kind {
54+
if let ExprKind::Closure(&Closure { body, .. }) = expr.kind {
5555
// do not lint if the closure is called using an iterator (see #1141)
5656
if_chain! {
5757
if let Some(parent) = get_parent_expr(self.cx, expr);

clippy_lints/src/bytecount.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use clippy_utils::visitors::is_local_used;
55
use clippy_utils::{path_to_local_id, paths, peel_blocks, peel_ref_operators, strip_pat_refs};
66
use if_chain::if_chain;
77
use rustc_errors::Applicability;
8-
use rustc_hir::{BinOpKind, Expr, ExprKind, PatKind};
8+
use rustc_hir::{BinOpKind, Closure, Expr, ExprKind, PatKind};
99
use rustc_lint::{LateContext, LateLintPass};
1010
use rustc_middle::ty::{self, UintTy};
1111
use rustc_session::{declare_lint_pass, declare_tool_lint};
@@ -51,7 +51,7 @@ impl<'tcx> LateLintPass<'tcx> for ByteCount {
5151
if count.ident.name == sym::count;
5252
if let ExprKind::MethodCall(filter, [filter_recv, filter_arg], _) = count_recv.kind;
5353
if filter.ident.name == sym!(filter);
54-
if let ExprKind::Closure { body, .. } = filter_arg.kind;
54+
if let ExprKind::Closure(&Closure { body, .. }) = filter_arg.kind;
5555
let body = cx.tcx.hir().body(body);
5656
if let [param] = body.params;
5757
if let PatKind::Binding(_, arg_id, _, _) = strip_pat_refs(param.pat).kind;

clippy_lints/src/eta_reduction.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use clippy_utils::{higher, is_adjusted, path_to_local, path_to_local_id};
77
use if_chain::if_chain;
88
use rustc_errors::Applicability;
99
use rustc_hir::def_id::DefId;
10-
use rustc_hir::{Expr, ExprKind, Param, PatKind, Unsafety};
10+
use rustc_hir::{Closure, Expr, ExprKind, Param, PatKind, Unsafety};
1111
use rustc_lint::{LateContext, LateLintPass};
1212
use rustc_middle::ty::adjustment::{Adjust, Adjustment, AutoBorrow};
1313
use rustc_middle::ty::binding::BindingMode;
@@ -78,7 +78,7 @@ impl<'tcx> LateLintPass<'tcx> for EtaReduction {
7878
return;
7979
}
8080
let body = match expr.kind {
81-
ExprKind::Closure { body, .. } => cx.tcx.hir().body(body),
81+
ExprKind::Closure(&Closure { body, .. }) => cx.tcx.hir().body(body),
8282
_ => return,
8383
};
8484
if body.value.span.from_expansion() {

clippy_lints/src/infinite_iter.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use clippy_utils::diagnostics::span_lint;
22
use clippy_utils::ty::{implements_trait, is_type_diagnostic_item};
33
use clippy_utils::{higher, match_def_path, path_def_id, paths};
4-
use rustc_hir::{BorrowKind, Expr, ExprKind};
4+
use rustc_hir::{BorrowKind, Closure, Expr, ExprKind};
55
use rustc_lint::{LateContext, LateLintPass};
66
use rustc_session::{declare_lint_pass, declare_tool_lint};
77
use rustc_span::symbol::{sym, Symbol};
@@ -159,7 +159,7 @@ fn is_infinite(cx: &LateContext<'_>, expr: &Expr<'_>) -> Finiteness {
159159
}
160160
}
161161
if method.ident.name == sym!(flat_map) && args.len() == 2 {
162-
if let ExprKind::Closure { body, .. } = args[1].kind {
162+
if let ExprKind::Closure(&Closure { body, .. }) = args[1].kind {
163163
let body = cx.tcx.hir().body(body);
164164
return is_infinite(cx, &body.value);
165165
}

clippy_lints/src/inherent_to_string.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use clippy_utils::diagnostics::span_lint_and_help;
22
use clippy_utils::ty::{implements_trait, is_type_diagnostic_item};
33
use clippy_utils::{get_trait_def_id, paths, return_ty, trait_ref_of_method};
44
use if_chain::if_chain;
5-
use rustc_hir::{ImplItem, ImplItemKind};
5+
use rustc_hir::{GenericParamKind, ImplItem, ImplItemKind};
66
use rustc_lint::{LateContext, LateLintPass};
77
use rustc_session::{declare_lint_pass, declare_tool_lint};
88
use rustc_span::sym;
@@ -102,7 +102,7 @@ impl<'tcx> LateLintPass<'tcx> for InherentToString {
102102
let decl = &signature.decl;
103103
if decl.implicit_self.has_implicit_self();
104104
if decl.inputs.len() == 1;
105-
if impl_item.generics.params.is_empty();
105+
if impl_item.generics.params.iter().all(|p| matches!(p.kind, GenericParamKind::Lifetime { .. }));
106106

107107
// Check if return type is String
108108
if is_type_diagnostic_item(cx, return_ty(cx, impl_item.hir_id()), sym::String);

clippy_lints/src/lifetimes.rs

+7-3
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ use rustc_hir::intravisit::{
99
use rustc_hir::FnRetTy::Return;
1010
use rustc_hir::{
1111
BareFnTy, BodyId, FnDecl, GenericArg, GenericBound, GenericParam, GenericParamKind, Generics, Impl, ImplItem,
12-
ImplItemKind, Item, ItemKind, LangItem, Lifetime, LifetimeName, ParamName, PolyTraitRef, PredicateOrigin,
13-
TraitBoundModifier, TraitFn, TraitItem, TraitItemKind, Ty, TyKind, WherePredicate,
12+
ImplItemKind, Item, ItemKind, LangItem, Lifetime, LifetimeName, LifetimeParamKind, ParamName, PolyTraitRef,
13+
PredicateOrigin, TraitBoundModifier, TraitFn, TraitItem, TraitItemKind, Ty, TyKind, WherePredicate,
1414
};
1515
use rustc_lint::{LateContext, LateLintPass};
1616
use rustc_middle::hir::nested_filter as middle_nested_filter;
@@ -338,7 +338,10 @@ fn could_use_elision<'tcx>(
338338
fn allowed_lts_from(named_generics: &[GenericParam<'_>]) -> FxHashSet<RefLt> {
339339
let mut allowed_lts = FxHashSet::default();
340340
for par in named_generics.iter() {
341-
if let GenericParamKind::Lifetime { .. } = par.kind {
341+
if let GenericParamKind::Lifetime {
342+
kind: LifetimeParamKind::Explicit,
343+
} = par.kind
344+
{
342345
allowed_lts.insert(RefLt::Named(par.name.ident().name));
343346
}
344347
}
@@ -379,6 +382,7 @@ impl<'a, 'tcx> RefVisitor<'a, 'tcx> {
379382
self.lts.push(RefLt::Static);
380383
} else if let LifetimeName::Param(_, ParamName::Fresh) = lt.name {
381384
// Fresh lifetimes generated should be ignored.
385+
self.lts.push(RefLt::Unnamed);
382386
} else if lt.is_elided() {
383387
self.lts.push(RefLt::Unnamed);
384388
} else {

clippy_lints/src/loops/needless_range_loop.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use rustc_ast::ast;
99
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
1010
use rustc_hir::def::{DefKind, Res};
1111
use rustc_hir::intravisit::{walk_expr, Visitor};
12-
use rustc_hir::{BinOpKind, BorrowKind, Expr, ExprKind, HirId, Mutability, Pat, PatKind, QPath};
12+
use rustc_hir::{BinOpKind, BorrowKind, Closure, Expr, ExprKind, HirId, Mutability, Pat, PatKind, QPath};
1313
use rustc_lint::LateContext;
1414
use rustc_middle::middle::region;
1515
use rustc_middle::ty::{self, Ty};
@@ -369,7 +369,7 @@ impl<'a, 'tcx> Visitor<'tcx> for VarVisitor<'a, 'tcx> {
369369
self.visit_expr(expr);
370370
}
371371
},
372-
ExprKind::Closure { body, .. } => {
372+
ExprKind::Closure(&Closure { body, .. }) => {
373373
let body = self.cx.tcx.hir().body(body);
374374
self.visit_expr(&body.value);
375375
},

clippy_lints/src/loops/while_let_on_iterator.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use clippy_utils::{
88
use if_chain::if_chain;
99
use rustc_errors::Applicability;
1010
use rustc_hir::intravisit::{walk_expr, Visitor};
11-
use rustc_hir::{def::Res, Expr, ExprKind, HirId, Local, Mutability, PatKind, QPath, UnOp};
11+
use rustc_hir::{Closure, def::Res, Expr, ExprKind, HirId, Local, Mutability, PatKind, QPath, UnOp};
1212
use rustc_lint::LateContext;
1313
use rustc_middle::ty::adjustment::Adjust;
1414
use rustc_span::{symbol::sym, Symbol};
@@ -220,7 +220,7 @@ fn uses_iter<'tcx>(cx: &LateContext<'tcx>, iter_expr: &IterExpr, container: &'tc
220220
if let Some(e) = e {
221221
self.visit_expr(e);
222222
}
223-
} else if let ExprKind::Closure { body: id, .. } = e.kind {
223+
} else if let ExprKind::Closure(&Closure { body: id, .. }) = e.kind {
224224
if is_res_used(self.cx, self.iter_expr.path, id) {
225225
self.uses_iter = true;
226226
}
@@ -260,7 +260,7 @@ fn needs_mutable_borrow(cx: &LateContext<'_>, iter_expr: &IterExpr, loop_expr: &
260260
if let Some(e) = e {
261261
self.visit_expr(e);
262262
}
263-
} else if let ExprKind::Closure { body: id, .. } = e.kind {
263+
} else if let ExprKind::Closure(&Closure { body: id, .. }) = e.kind {
264264
self.used_iter = is_res_used(self.cx, self.iter_expr.path, id);
265265
} else {
266266
walk_expr(self, e);
@@ -307,7 +307,7 @@ fn needs_mutable_borrow(cx: &LateContext<'_>, iter_expr: &IterExpr, loop_expr: &
307307
if let Some(e) = e {
308308
self.visit_expr(e);
309309
}
310-
} else if let ExprKind::Closure { body: id, .. } = e.kind {
310+
} else if let ExprKind::Closure(&Closure { body: id, .. }) = e.kind {
311311
self.used_after = is_res_used(self.cx, self.iter_expr.path, id);
312312
} else {
313313
walk_expr(self, e);

clippy_lints/src/manual_async_fn.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use if_chain::if_chain;
66
use rustc_errors::Applicability;
77
use rustc_hir::intravisit::FnKind;
88
use rustc_hir::{
9-
AsyncGeneratorKind, Block, Body, Expr, ExprKind, FnDecl, FnRetTy, GeneratorKind, GenericArg, GenericBound, HirId,
9+
AsyncGeneratorKind, Block, Body, Closure, Expr, ExprKind, FnDecl, FnRetTy, GeneratorKind, GenericArg, GenericBound, HirId,
1010
IsAsync, ItemKind, LifetimeName, Term, TraitRef, Ty, TyKind, TypeBindingKind,
1111
};
1212
use rustc_lint::{LateContext, LateLintPass};
@@ -177,7 +177,7 @@ fn desugared_async_block<'tcx>(cx: &LateContext<'tcx>, block: &'tcx Block<'tcx>)
177177
if let Some(block_expr) = block.expr;
178178
if let Some(args) = match_function_call(cx, block_expr, &FUTURE_FROM_GENERATOR);
179179
if args.len() == 1;
180-
if let Expr{kind: ExprKind::Closure { body, .. }, ..} = args[0];
180+
if let Expr{kind: ExprKind::Closure(&Closure { body, .. }), ..} = args[0];
181181
let closure_body = cx.tcx.hir().body(body);
182182
if closure_body.generator_kind == Some(GeneratorKind::Async(AsyncGeneratorKind::Block));
183183
then {

clippy_lints/src/manual_ok_or.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use clippy_utils::{is_lang_ctor, path_to_local_id};
55
use if_chain::if_chain;
66
use rustc_errors::Applicability;
77
use rustc_hir::LangItem::{ResultErr, ResultOk};
8-
use rustc_hir::{Expr, ExprKind, PatKind};
8+
use rustc_hir::{Closure, Expr, ExprKind, PatKind};
99
use rustc_lint::LintContext;
1010
use rustc_lint::{LateContext, LateLintPass};
1111
use rustc_middle::lint::in_external_macro;
@@ -88,7 +88,7 @@ fn is_ok_wrapping(cx: &LateContext<'_>, map_expr: &Expr<'_>) -> bool {
8888
}
8989
}
9090
if_chain! {
91-
if let ExprKind::Closure { body, .. } = map_expr.kind;
91+
if let ExprKind::Closure(&Closure { body, .. }) = map_expr.kind;
9292
let body = cx.tcx.hir().body(body);
9393
if let PatKind::Binding(_, param_id, ..) = body.params[0].pat.kind;
9494
if let ExprKind::Call(Expr { kind: ExprKind::Path(ok_path), .. }, &[ref ok_arg]) = body.value.kind;

clippy_lints/src/manual_retain.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ fn check_to_owned(
148148

149149
fn suggest(cx: &LateContext<'_>, parent_expr: &hir::Expr<'_>, left_expr: &hir::Expr<'_>, filter_expr: &hir::Expr<'_>) {
150150
if let hir::ExprKind::MethodCall(_, [_, closure], _) = filter_expr.kind
151-
&& let hir::ExprKind::Closure{ body, ..} = closure.kind
151+
&& let hir::ExprKind::Closure(&hir::Closure { body, ..}) = closure.kind
152152
&& let filter_body = cx.tcx.hir().body(body)
153153
&& let [filter_params] = filter_body.params
154154
&& let Some(sugg) = match filter_params.pat.kind {

clippy_lints/src/map_clone.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ impl<'tcx> LateLintPass<'tcx> for MapClone {
6767
if method.ident.name == sym::map;
6868
let ty = cx.typeck_results().expr_ty(&args[0]);
6969
if is_type_diagnostic_item(cx, ty, sym::Option) || is_trait_method(cx, e, sym::Iterator);
70-
if let hir::ExprKind::Closure { body, .. } = args[1].kind;
70+
if let hir::ExprKind::Closure(&hir::Closure { body, .. }) = args[1].kind;
7171
then {
7272
let closure_body = cx.tcx.hir().body(body);
7373
let closure_expr = peel_blocks(&closure_body.value);

clippy_lints/src/map_err_ignore.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use clippy_utils::diagnostics::span_lint_and_help;
2-
use rustc_hir::{CaptureBy, Expr, ExprKind, PatKind};
2+
use rustc_hir::{CaptureBy, Closure, Expr, ExprKind, PatKind};
33
use rustc_lint::{LateContext, LateLintPass};
44
use rustc_session::{declare_lint_pass, declare_tool_lint};
55

@@ -119,12 +119,12 @@ impl<'tcx> LateLintPass<'tcx> for MapErrIgnore {
119119
if method.ident.as_str() == "map_err" && args.len() == 2 {
120120
// make sure the first argument is a closure, and grab the CaptureRef, BodyId, and fn_decl_span
121121
// fields
122-
if let ExprKind::Closure {
122+
if let ExprKind::Closure(&Closure {
123123
capture_clause,
124124
body,
125125
fn_decl_span,
126126
..
127-
} = args[1].kind
127+
}) = args[1].kind
128128
{
129129
// check if this is by Reference (meaning there's no move statement)
130130
if capture_clause == CaptureBy::Ref {

clippy_lints/src/map_unit_fn.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ fn unit_closure<'tcx>(
169169
expr: &hir::Expr<'_>,
170170
) -> Option<(&'tcx hir::Param<'tcx>, &'tcx hir::Expr<'tcx>)> {
171171
if_chain! {
172-
if let hir::ExprKind::Closure { fn_decl, body, .. } = expr.kind;
172+
if let hir::ExprKind::Closure(&hir::Closure { fn_decl, body, .. }) = expr.kind;
173173
let body = cx.tcx.hir().body(body);
174174
let body_expr = &body.value;
175175
if fn_decl.inputs.len() == 1;

clippy_lints/src/methods/bind_instead_of_map.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ pub(crate) trait BindInsteadOfMap {
150150
}
151151

152152
match arg.kind {
153-
hir::ExprKind::Closure { body, fn_decl_span, .. } => {
153+
hir::ExprKind::Closure(&hir::Closure { body, fn_decl_span, .. }) => {
154154
let closure_body = cx.tcx.hir().body(body);
155155
let closure_expr = peel_blocks(&closure_body.value);
156156

clippy_lints/src/methods/filter_map.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use if_chain::if_chain;
66
use rustc_errors::Applicability;
77
use rustc_hir as hir;
88
use rustc_hir::def::Res;
9-
use rustc_hir::{Expr, ExprKind, PatKind, PathSegment, QPath, UnOp};
9+
use rustc_hir::{Closure, Expr, ExprKind, PatKind, PathSegment, QPath, UnOp};
1010
use rustc_lint::LateContext;
1111
use rustc_span::source_map::Span;
1212
use rustc_span::symbol::{sym, Symbol};
@@ -22,8 +22,8 @@ fn is_method<'tcx>(cx: &LateContext<'tcx>, expr: &hir::Expr<'_>, method_name: Sy
2222
hir::ExprKind::Path(QPath::Resolved(_, segments)) => {
2323
segments.segments.last().unwrap().ident.name == method_name
2424
},
25-
hir::ExprKind::Closure { body, .. } => {
26-
let body = cx.tcx.hir().body(*body);
25+
hir::ExprKind::Closure(&hir::Closure { body, .. }) => {
26+
let body = cx.tcx.hir().body(body);
2727
let closure_expr = peel_blocks(&body.value);
2828
let arg_id = body.params[0].pat.hir_id;
2929
match closure_expr.kind {
@@ -106,7 +106,7 @@ pub(super) fn check<'tcx>(
106106
if is_trait_method(cx, map_recv, sym::Iterator);
107107

108108
// filter(|x| ...is_some())...
109-
if let ExprKind::Closure { body: filter_body_id, .. } = filter_arg.kind;
109+
if let ExprKind::Closure(&Closure { body: filter_body_id, .. }) = filter_arg.kind;
110110
let filter_body = cx.tcx.hir().body(filter_body_id);
111111
if let [filter_param] = filter_body.params;
112112
// optional ref pattern: `filter(|&x| ..)`
@@ -129,7 +129,7 @@ pub(super) fn check<'tcx>(
129129
if path.ident.name.as_str() == if is_result { "is_ok" } else { "is_some" };
130130

131131
// ...map(|x| ...unwrap())
132-
if let ExprKind::Closure { body: map_body_id, .. } = map_arg.kind;
132+
if let ExprKind::Closure(&Closure { body: map_body_id, .. }) = map_arg.kind;
133133
let map_body = cx.tcx.hir().body(map_body_id);
134134
if let [map_param] = map_body.params;
135135
if let PatKind::Binding(_, map_param_id, map_param_ident, None) = map_param.pat.kind;

clippy_lints/src/methods/option_as_ref_deref.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ pub(super) fn check<'tcx>(
5151
.map_or(false, |fun_def_id| {
5252
deref_aliases.iter().any(|path| match_def_path(cx, fun_def_id, path))
5353
}),
54-
hir::ExprKind::Closure { body, .. } => {
54+
hir::ExprKind::Closure(&hir::Closure { body, .. }) => {
5555
let closure_body = cx.tcx.hir().body(body);
5656
let closure_expr = peel_blocks(&closure_body.value);
5757

clippy_lints/src/methods/option_map_or_none.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ pub(super) fn check<'tcx>(
7171
if is_option {
7272
let self_snippet = snippet(cx, recv.span, "..");
7373
if_chain! {
74-
if let hir::ExprKind::Closure { body, fn_decl_span, .. } = map_arg.kind;
74+
if let hir::ExprKind::Closure(&hir::Closure { body, fn_decl_span, .. }) = map_arg.kind;
7575
let arg_snippet = snippet(cx, fn_decl_span, "..");
7676
let body = cx.tcx.hir().body(body);
7777
if let Some((func, [arg_char])) = reduce_unit_expression(&body.value);

clippy_lints/src/methods/search_is_some.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ pub(super) fn check<'tcx>(
4141
let mut applicability = Applicability::MachineApplicable;
4242
let any_search_snippet = if_chain! {
4343
if search_method == "find";
44-
if let hir::ExprKind::Closure { body, .. } = search_arg.kind;
44+
if let hir::ExprKind::Closure(&hir::Closure { body, .. }) = search_arg.kind;
4545
let closure_body = cx.tcx.hir().body(body);
4646
if let Some(closure_arg) = closure_body.params.get(0);
4747
then {

clippy_lints/src/methods/unnecessary_filter_map.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &hir::Expr<'_>, arg: &hir::Expr<
1818
return;
1919
}
2020

21-
if let hir::ExprKind::Closure { body, .. } = arg.kind {
21+
if let hir::ExprKind::Closure(&hir::Closure { body, .. }) = arg.kind {
2222
let body = cx.tcx.hir().body(body);
2323
let arg_id = body.params[0].pat.hir_id;
2424
let mutates_arg =

clippy_lints/src/methods/unnecessary_fold.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ pub(super) fn check(
2929
) {
3030
if_chain! {
3131
// Extract the body of the closure passed to fold
32-
if let hir::ExprKind::Closure { body, .. } = acc.kind;
32+
if let hir::ExprKind::Closure(&hir::Closure { body, .. }) = acc.kind;
3333
let closure_body = cx.tcx.hir().body(body);
3434
let closure_expr = peel_blocks(&closure_body.value);
3535

clippy_lints/src/methods/unnecessary_lazy_eval.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ pub(super) fn check<'tcx>(
2222
let is_result = is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(recv), sym::Result);
2323

2424
if is_option || is_result {
25-
if let hir::ExprKind::Closure { body, .. } = arg.kind {
25+
if let hir::ExprKind::Closure(&hir::Closure { body, .. }) = arg.kind {
2626
let body = cx.tcx.hir().body(body);
2727
let body_expr = &body.value;
2828

clippy_lints/src/needless_for_each.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use rustc_errors::Applicability;
22
use rustc_hir::{
33
intravisit::{walk_expr, Visitor},
4-
Expr, ExprKind, Stmt, StmtKind,
4+
Closure, Expr, ExprKind, Stmt, StmtKind,
55
};
66
use rustc_lint::{LateContext, LateLintPass};
77
use rustc_session::{declare_lint_pass, declare_tool_lint};
@@ -72,7 +72,7 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessForEach {
7272
if has_iter_method(cx, cx.typeck_results().expr_ty(iter_recv)).is_some();
7373
// Skip the lint if the body is not block because this is simpler than `for` loop.
7474
// e.g. `v.iter().for_each(f)` is simpler and clearer than using `for` loop.
75-
if let ExprKind::Closure { body, .. } = for_each_arg.kind;
75+
if let ExprKind::Closure(&Closure { body, .. }) = for_each_arg.kind;
7676
let body = cx.tcx.hir().body(body);
7777
if let ExprKind::Block(..) = body.value.kind;
7878
then {

0 commit comments

Comments
 (0)