]> git.lizzy.rs Git - rust.git/commitdiff
Make `ExprKind::Closure` a struct variant.
authorCamille GILLOT <gillot.camille@gmail.com>
Sat, 11 Jun 2022 19:25:25 +0000 (21:25 +0200)
committerCamille GILLOT <gillot.camille@gmail.com>
Sat, 11 Jun 2022 22:16:27 +0000 (00:16 +0200)
36 files changed:
clippy_lints/src/blocks_in_if_conditions.rs
clippy_lints/src/bytecount.rs
clippy_lints/src/dereference.rs
clippy_lints/src/eta_reduction.rs
clippy_lints/src/infinite_iter.rs
clippy_lints/src/loops/needless_range_loop.rs
clippy_lints/src/loops/never_loop.rs
clippy_lints/src/loops/while_let_on_iterator.rs
clippy_lints/src/manual_async_fn.rs
clippy_lints/src/manual_ok_or.rs
clippy_lints/src/map_clone.rs
clippy_lints/src/map_err_ignore.rs
clippy_lints/src/map_unit_fn.rs
clippy_lints/src/matches/match_single_binding.rs
clippy_lints/src/matches/significant_drop_in_scrutinee.rs
clippy_lints/src/methods/bind_instead_of_map.rs
clippy_lints/src/methods/filter_map.rs
clippy_lints/src/methods/option_as_ref_deref.rs
clippy_lints/src/methods/option_map_or_none.rs
clippy_lints/src/methods/search_is_some.rs
clippy_lints/src/methods/unnecessary_filter_map.rs
clippy_lints/src/methods/unnecessary_fold.rs
clippy_lints/src/methods/unnecessary_lazy_eval.rs
clippy_lints/src/mixed_read_write_in_expression.rs
clippy_lints/src/needless_for_each.rs
clippy_lints/src/no_effect.rs
clippy_lints/src/only_used_in_recursion.rs
clippy_lints/src/redundant_closure_call.rs
clippy_lints/src/unit_return_expecting_ord.rs
clippy_lints/src/unnecessary_sort_by.rs
clippy_lints/src/utils/author.rs
clippy_utils/src/eager_or_lazy.rs
clippy_utils/src/hir_utils.rs
clippy_utils/src/lib.rs
clippy_utils/src/sugg.rs
clippy_utils/src/usage.rs

index 5bd7a342389fe50216553f483b4e3c236b35e969..4b3a04f1255b99465e041ebe27e87bf7538e0b85 100644 (file)
@@ -51,7 +51,7 @@ struct ExVisitor<'a, 'tcx> {
 
 impl<'a, 'tcx> Visitor<'tcx> for ExVisitor<'a, 'tcx> {
     fn visit_expr(&mut self, expr: &'tcx Expr<'tcx>) {
-        if let ExprKind::Closure(_, _, eid, _, _) = expr.kind {
+        if let ExprKind::Closure { body, .. } = expr.kind {
             // do not lint if the closure is called using an iterator (see #1141)
             if_chain! {
                 if let Some(parent) = get_parent_expr(self.cx, expr);
@@ -64,7 +64,7 @@ fn visit_expr(&mut self, expr: &'tcx Expr<'tcx>) {
                 }
             }
 
-            let body = self.cx.tcx.hir().body(eid);
+            let body = self.cx.tcx.hir().body(body);
             let ex = &body.value;
             if let ExprKind::Block(block, _) = ex.kind {
                 if !body.value.span.from_expansion() && !block.stmts.is_empty() {
index bfdbaf2413a2502030f6357a1b9c97f7ff3ae8b8..4e530256321ccbf764449f59c8202dff46210a59 100644 (file)
@@ -51,8 +51,8 @@ fn check_expr(&mut self, cx: &LateContext<'_>, expr: &Expr<'_>) {
             if count.ident.name == sym::count;
             if let ExprKind::MethodCall(filter, [filter_recv, filter_arg], _) = count_recv.kind;
             if filter.ident.name == sym!(filter);
-            if let ExprKind::Closure(_, _, body_id, _, _) = filter_arg.kind;
-            let body = cx.tcx.hir().body(body_id);
+            if let ExprKind::Closure { body, .. } = filter_arg.kind;
+            let body = cx.tcx.hir().body(body);
             if let [param] = body.params;
             if let PatKind::Binding(_, arg_id, _, _) = strip_pat_refs(param.pat).kind;
             if let ExprKind::Binary(ref op, l, r) = body.value.kind;
index 8288f7a8b9b623732e98f401f0f1bf1c2e82886c..527529965a96fc4d8f43df63cc7cfa634fd6e15c 100644 (file)
@@ -498,7 +498,7 @@ fn is_linted_explicit_deref_position(parent: Option<Node<'_>>, child_id: HirId,
         | ExprKind::Loop(..)
         | ExprKind::Match(..)
         | ExprKind::Let(..)
-        | ExprKind::Closure(..)
+        | ExprKind::Closure{..}
         | ExprKind::Block(..)
         | ExprKind::Assign(..)
         | ExprKind::AssignOp(..)
index 530d6d4de35f1c2bceb58e92c6b8624c9db23c75..197cac86a57d6d1772c2f44ef50d4cc4dcc2924a 100644 (file)
@@ -78,7 +78,7 @@ fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) {
             return;
         }
         let body = match expr.kind {
-            ExprKind::Closure(_, _, id, _, _) => cx.tcx.hir().body(id),
+            ExprKind::Closure { body, .. } => cx.tcx.hir().body(body),
             _ => return,
         };
         if body.value.span.from_expansion() {
index b2b9889f5dc74c21431c6bac8c98d842849044b7..41e1fc4e3c209e6ae15dd4aee4ccedd0f966b885 100644 (file)
@@ -158,8 +158,8 @@ fn is_infinite(cx: &LateContext<'_>, expr: &Expr<'_>) -> Finiteness {
                 }
             }
             if method.ident.name == sym!(flat_map) && args.len() == 2 {
-                if let ExprKind::Closure(_, _, body_id, _, _) = args[1].kind {
-                    let body = cx.tcx.hir().body(body_id);
+                if let ExprKind::Closure { body, .. } = args[1].kind {
+                    let body = cx.tcx.hir().body(body);
                     return is_infinite(cx, &body.value);
                 }
             }
index a348bb465c8844f32a8164759f594ff16616051f..0b6d9adb553e48f0baa6594fc3c0256ad3b43b6c 100644 (file)
@@ -369,8 +369,8 @@ fn visit_expr(&mut self, expr: &'tcx Expr<'_>) {
                     self.visit_expr(expr);
                 }
             },
-            ExprKind::Closure(_, _, body_id, ..) => {
-                let body = self.cx.tcx.hir().body(body_id);
+            ExprKind::Closure { body, .. } => {
+                let body = self.cx.tcx.hir().body(body);
                 self.visit_expr(&body.value);
             },
             _ => walk_expr(self, expr),
index c025f5972d5195ff67ea0f6e2c47c7ee65759a55..99d214669359532d83c2e4bc56c42d8c34082f60 100644 (file)
@@ -182,7 +182,7 @@ fn never_loop_expr(expr: &Expr<'_>, main_loop_id: HirId) -> NeverLoopResult {
             .fold(NeverLoopResult::Otherwise, combine_both),
         ExprKind::Struct(_, _, None)
         | ExprKind::Yield(_, _)
-        | ExprKind::Closure(_, _, _, _, _)
+        | ExprKind::Closure { .. }
         | ExprKind::Path(_)
         | ExprKind::ConstBlock(_)
         | ExprKind::Lit(_)
index 82760607ba295e5e11ee219b28346fd54927e469..a57159750664fc0eafe052a1fc21724049d4bd0e 100644 (file)
@@ -220,7 +220,7 @@ fn visit_expr(&mut self, e: &'tcx Expr<'_>) {
                 if let Some(e) = e {
                     self.visit_expr(e);
                 }
-            } else if let ExprKind::Closure(_, _, id, _, _) = e.kind {
+            } else if let ExprKind::Closure { body: id, .. } = e.kind {
                 if is_res_used(self.cx, self.iter_expr.path, id) {
                     self.uses_iter = true;
                 }
@@ -260,7 +260,7 @@ fn visit_expr(&mut self, e: &'tcx Expr<'_>) {
                     if let Some(e) = e {
                         self.visit_expr(e);
                     }
-                } else if let ExprKind::Closure(_, _, id, _, _) = e.kind {
+                } else if let ExprKind::Closure { body: id, .. } = e.kind {
                     self.used_iter = is_res_used(self.cx, self.iter_expr.path, id);
                 } else {
                     walk_expr(self, e);
@@ -307,7 +307,7 @@ fn visit_expr(&mut self, e: &'tcx Expr<'_>) {
                     if let Some(e) = e {
                         self.visit_expr(e);
                     }
-                } else if let ExprKind::Closure(_, _, id, _, _) = e.kind {
+                } else if let ExprKind::Closure { body: id, .. } = e.kind {
                     self.used_after = is_res_used(self.cx, self.iter_expr.path, id);
                 } else {
                     walk_expr(self, e);
index babc6fab3c0fb03d5c617c001001bdb80df97fe2..818410d2793737740064c6a1b09efe4f6cd6f67b 100644 (file)
@@ -177,8 +177,8 @@ fn desugared_async_block<'tcx>(cx: &LateContext<'tcx>, block: &'tcx Block<'tcx>)
         if let Some(block_expr) = block.expr;
         if let Some(args) = match_function_call(cx, block_expr, &FUTURE_FROM_GENERATOR);
         if args.len() == 1;
-        if let Expr{kind: ExprKind::Closure(_, _, body_id, ..), ..} = args[0];
-        let closure_body = cx.tcx.hir().body(body_id);
+        if let Expr{kind: ExprKind::Closure { body, .. }, ..} = args[0];
+        let closure_body = cx.tcx.hir().body(body);
         if closure_body.generator_kind == Some(GeneratorKind::Async(AsyncGeneratorKind::Block));
         then {
             return Some(closure_body);
index bf4ab29d90876aa66c393904942f6ff87983dde1..18cfd00376784448e76e91e9272be76f931fbb33 100644 (file)
@@ -88,8 +88,8 @@ fn is_ok_wrapping(cx: &LateContext<'_>, map_expr: &Expr<'_>) -> bool {
         }
     }
     if_chain! {
-        if let ExprKind::Closure(_, _, body_id, ..) = map_expr.kind;
-        let body = cx.tcx.hir().body(body_id);
+        if let ExprKind::Closure { body, .. } = map_expr.kind;
+        let body = cx.tcx.hir().body(body);
         if let PatKind::Binding(_, param_id, ..) = body.params[0].pat.kind;
         if let ExprKind::Call(Expr { kind: ExprKind::Path(ok_path), .. }, &[ref ok_arg]) = body.value.kind;
         if is_lang_ctor(cx, ok_path, ResultOk);
index a13d191375bfa02ad4df4afaf56dbb107da67f46..3533de54a1e3d4e140caa0ddcaaba159f0a14d30 100644 (file)
@@ -67,9 +67,9 @@ fn check_expr(&mut self, cx: &LateContext<'_>, e: &hir::Expr<'_>) {
             if method.ident.name == sym::map;
             let ty = cx.typeck_results().expr_ty(&args[0]);
             if is_type_diagnostic_item(cx, ty, sym::Option) || is_trait_method(cx, e, sym::Iterator);
-            if let hir::ExprKind::Closure(_, _, body_id, _, _) = args[1].kind;
+            if let hir::ExprKind::Closure { body, .. } = args[1].kind;
             then {
-                let closure_body = cx.tcx.hir().body(body_id);
+                let closure_body = cx.tcx.hir().body(body);
                 let closure_expr = peel_blocks(&closure_body.value);
                 match closure_body.params[0].pat.kind {
                     hir::PatKind::Ref(inner, hir::Mutability::Not) => if let hir::PatKind::Binding(
index e3a42de0b7c10c183299aaa5b18de8efc6b1c6ab..0c22144104872bd345b4f567cc483d4efb98e356 100644 (file)
@@ -117,12 +117,19 @@ fn check_expr(&mut self, cx: &LateContext<'_>, e: &Expr<'_>) {
             // only work if the method name is `map_err` and there are only 2 arguments (e.g. x.map_err(|_|[1]
             // Enum::Variant[2]))
             if method.ident.as_str() == "map_err" && args.len() == 2 {
-                // make sure the first argument is a closure, and grab the CaptureRef, body_id, and body_span fields
-                if let ExprKind::Closure(capture, _, body_id, body_span, _) = args[1].kind {
+                // make sure the first argument is a closure, and grab the CaptureRef, BodyId, and fn_decl_span
+                // fields
+                if let ExprKind::Closure {
+                    capture_clause,
+                    body,
+                    fn_decl_span,
+                    ..
+                } = args[1].kind
+                {
                     // check if this is by Reference (meaning there's no move statement)
-                    if capture == CaptureBy::Ref {
+                    if capture_clause == CaptureBy::Ref {
                         // Get the closure body to check the parameters and values
-                        let closure_body = cx.tcx.hir().body(body_id);
+                        let closure_body = cx.tcx.hir().body(body);
                         // make sure there's only one parameter (`|_|`)
                         if closure_body.params.len() == 1 {
                             // make sure that parameter is the wild token (`_`)
@@ -132,7 +139,7 @@ fn check_expr(&mut self, cx: &LateContext<'_>, e: &Expr<'_>) {
                                 span_lint_and_help(
                                     cx,
                                     MAP_ERR_IGNORE,
-                                    body_span,
+                                    fn_decl_span,
                                     "`map_err(|_|...` wildcard pattern discards the original error",
                                     None,
                                     "consider storing the original error as a source in the new error, or silence this warning using an ignored identifier (`.map_err(|_foo| ...`)",
index f552d5c1afab9268f4448af24acbd7e881cd2a84..663246b4c8622f69a9ff4f4399eed77b31215d24 100644 (file)
@@ -169,12 +169,12 @@ fn unit_closure<'tcx>(
     expr: &hir::Expr<'_>,
 ) -> Option<(&'tcx hir::Param<'tcx>, &'tcx hir::Expr<'tcx>)> {
     if_chain! {
-        if let hir::ExprKind::Closure(_, decl, inner_expr_id, _, _) = expr.kind;
-        let body = cx.tcx.hir().body(inner_expr_id);
+        if let hir::ExprKind::Closure { fn_decl, body, .. } = expr.kind;
+        let body = cx.tcx.hir().body(body);
         let body_expr = &body.value;
-        if decl.inputs.len() == 1;
+        if fn_decl.inputs.len() == 1;
         if is_unit_expression(cx, body_expr);
-        if let Some(binding) = iter_input_pats(decl, body).next();
+        if let Some(binding) = iter_input_pats(fn_decl, body).next();
         then {
             return Some((binding, body_expr));
         }
index a59711d4cace5f7b17b0a4f3bf8675cfb9ca4c80..9df2db45dcf834eb5c6a3a186c8c9c6026286c4e 100644 (file)
@@ -177,7 +177,7 @@ fn sugg_with_curlies<'a>(
 
     let (mut cbrace_start, mut cbrace_end) = (String::new(), String::new());
     if let Some(parent_expr) = get_parent_expr(cx, match_expr) {
-        if let ExprKind::Closure(..) = parent_expr.kind {
+        if let ExprKind::Closure { .. } = parent_expr.kind {
             cbrace_end = format!("\n{}}}", indent);
             // Fix body indent due to the closure
             indent = " ".repeat(indent_of(cx, bind_names).unwrap_or(0));
index a211dc18f9e1e75c2676fcc371ec21694de5f9b0..dcaf6f865de3677d78bb18a2164863f8c178650d 100644 (file)
@@ -305,7 +305,7 @@ fn visit_expr(&mut self, ex: &'tcx Expr<'_>) {
             ExprKind::Break(_, _) |
             ExprKind::Cast(_, _) |
             // Don't want to check the closure itself, only invocation, which is covered by MethodCall
-            ExprKind::Closure(_, _, _, _, _) |
+            ExprKind::Closure { .. } |
             ExprKind::ConstBlock(_) |
             ExprKind::Continue(_) |
             ExprKind::DropTemps(_) |
index b88ec0963f2b55da8cd2f4567e8b91d9f3f58e45..d31b736982b34715f308e2d9f6d72f8f0d6ca1cb 100644 (file)
@@ -150,11 +150,11 @@ fn check(cx: &LateContext<'_>, expr: &hir::Expr<'_>, recv: &hir::Expr<'_>, arg:
         }
 
         match arg.kind {
-            hir::ExprKind::Closure(_, _, body_id, closure_args_span, _) => {
-                let closure_body = cx.tcx.hir().body(body_id);
+            hir::ExprKind::Closure { body, fn_decl_span, .. } => {
+                let closure_body = cx.tcx.hir().body(body);
                 let closure_expr = peel_blocks(&closure_body.value);
 
-                if Self::lint_closure_autofixable(cx, expr, recv, closure_expr, closure_args_span) {
+                if Self::lint_closure_autofixable(cx, expr, recv, closure_expr, fn_decl_span) {
                     true
                 } else {
                     Self::lint_closure(cx, expr, closure_expr)
index 558cb6bd64e7275a04e2ba49e27acb706eef8049..3efccd703a651e874f39303271f290347bb70a10 100644 (file)
@@ -22,8 +22,8 @@ fn is_method<'tcx>(cx: &LateContext<'tcx>, expr: &hir::Expr<'_>, method_name: Sy
         hir::ExprKind::Path(QPath::Resolved(_, segments)) => {
             segments.segments.last().unwrap().ident.name == method_name
         },
-        hir::ExprKind::Closure(_, _, c, _, _) => {
-            let body = cx.tcx.hir().body(*c);
+        hir::ExprKind::Closure { body, .. } => {
+            let body = cx.tcx.hir().body(*body);
             let closure_expr = peel_blocks(&body.value);
             let arg_id = body.params[0].pat.hir_id;
             match closure_expr.kind {
@@ -106,7 +106,7 @@ pub(super) fn check<'tcx>(
             if is_trait_method(cx, map_recv, sym::Iterator);
 
             // filter(|x| ...is_some())...
-            if let ExprKind::Closure(_, _, filter_body_id, ..) = filter_arg.kind;
+            if let ExprKind::Closure { body: filter_body_id, .. } = filter_arg.kind;
             let filter_body = cx.tcx.hir().body(filter_body_id);
             if let [filter_param] = filter_body.params;
             // optional ref pattern: `filter(|&x| ..)`
@@ -129,7 +129,7 @@ pub(super) fn check<'tcx>(
             if path.ident.name.as_str() == if is_result { "is_ok" } else { "is_some" };
 
             // ...map(|x| ...unwrap())
-            if let ExprKind::Closure(_, _, map_body_id, ..) = map_arg.kind;
+            if let ExprKind::Closure { body: map_body_id, .. } = map_arg.kind;
             let map_body = cx.tcx.hir().body(map_body_id);
             if let [map_param] = map_body.params;
             if let PatKind::Binding(_, map_param_id, map_param_ident, None) = map_param.pat.kind;
index b50a173d8359b83ab361506f2737be370bc432af..912499bf96b94457d603aff4131c8791f22a2b0d 100644 (file)
@@ -51,8 +51,8 @@ pub(super) fn check<'tcx>(
             .map_or(false, |fun_def_id| {
                 deref_aliases.iter().any(|path| match_def_path(cx, fun_def_id, path))
             }),
-        hir::ExprKind::Closure(_, _, body_id, _, _) => {
-            let closure_body = cx.tcx.hir().body(body_id);
+        hir::ExprKind::Closure { body, .. } => {
+            let closure_body = cx.tcx.hir().body(body);
             let closure_expr = peel_blocks(&closure_body.value);
 
             match &closure_expr.kind {
index 8989db54f6c5fb20bb19c3c3a1ef9540c32320d6..2d71bd6f240fc14bd9ccced4d3f2162d749b1635 100644 (file)
@@ -71,27 +71,26 @@ pub(super) fn check<'tcx>(
     if is_option {
         let self_snippet = snippet(cx, recv.span, "..");
         if_chain! {
-        if let hir::ExprKind::Closure(_, _, id, span, _) = map_arg.kind;
-            let arg_snippet = snippet(cx, span, "..");
-            let body = cx.tcx.hir().body(id);
-                if let Some((func, [arg_char])) = reduce_unit_expression(&body.value);
-                if let Some(id) = path_def_id(cx, func).map(|ctor_id| cx.tcx.parent(ctor_id));
-                if Some(id) == cx.tcx.lang_items().option_some_variant();
-                then {
-                    let func_snippet = snippet(cx, arg_char.span, "..");
-                    let msg = "called `map_or(None, ..)` on an `Option` value. This can be done more directly by calling \
-                       `map(..)` instead";
-                    return span_lint_and_sugg(
-                        cx,
-                        OPTION_MAP_OR_NONE,
-                        expr.span,
-                        msg,
-                        "try using `map` instead",
-                        format!("{0}.map({1} {2})", self_snippet, arg_snippet,func_snippet),
-                        Applicability::MachineApplicable,
-                    );
-                }
-
+            if let hir::ExprKind::Closure { body, fn_decl_span, .. } = map_arg.kind;
+            let arg_snippet = snippet(cx, fn_decl_span, "..");
+            let body = cx.tcx.hir().body(body);
+            if let Some((func, [arg_char])) = reduce_unit_expression(&body.value);
+            if let Some(id) = path_def_id(cx, func).map(|ctor_id| cx.tcx.parent(ctor_id));
+            if Some(id) == cx.tcx.lang_items().option_some_variant();
+            then {
+                let func_snippet = snippet(cx, arg_char.span, "..");
+                let msg = "called `map_or(None, ..)` on an `Option` value. This can be done more directly by calling \
+                   `map(..)` instead";
+                return span_lint_and_sugg(
+                    cx,
+                    OPTION_MAP_OR_NONE,
+                    expr.span,
+                    msg,
+                    "try using `map` instead",
+                    format!("{0}.map({1} {2})", self_snippet, arg_snippet,func_snippet),
+                    Applicability::MachineApplicable,
+                );
+            }
         }
 
         let func_snippet = snippet(cx, map_arg.span, "..");
index 5ed4ba94884e26b627874b7253608150eca9a0a9..b11f4531a912c006c27e04bd2bf7d6bdd6155a26 100644 (file)
@@ -41,8 +41,8 @@ pub(super) fn check<'tcx>(
             let mut applicability = Applicability::MachineApplicable;
             let any_search_snippet = if_chain! {
                 if search_method == "find";
-                if let hir::ExprKind::Closure(_, _, body_id, ..) = search_arg.kind;
-                let closure_body = cx.tcx.hir().body(body_id);
+                if let hir::ExprKind::Closure { body, .. } = search_arg.kind;
+                let closure_body = cx.tcx.hir().body(body);
                 if let Some(closure_arg) = closure_body.params.get(0);
                 then {
                     if let hir::PatKind::Ref(..) = closure_arg.pat.kind {
index 2fda254ca98e99ddf1820a790842ab0af2163a16..a405467f5e8af3e55f3b9a4209ec559f2615c163 100644 (file)
@@ -18,8 +18,8 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &hir::Expr<'_>, arg: &hir::Expr<
         return;
     }
 
-    if let hir::ExprKind::Closure(_, _, body_id, ..) = arg.kind {
-        let body = cx.tcx.hir().body(body_id);
+    if let hir::ExprKind::Closure { body, .. } = arg.kind {
+        let body = cx.tcx.hir().body(body);
         let arg_id = body.params[0].pat.hir_id;
         let mutates_arg =
             mutated_variables(&body.value, cx).map_or(true, |used_mutably| used_mutably.contains(&arg_id));
index 47a811996085e59d95fa98475a33a0a367a9f1d8..913c4dbedc30113a2d193798954df144ca7d271c 100644 (file)
@@ -29,8 +29,8 @@ fn check_fold_with_op(
     ) {
         if_chain! {
             // Extract the body of the closure passed to fold
-            if let hir::ExprKind::Closure(_, _, body_id, _, _) = acc.kind;
-            let closure_body = cx.tcx.hir().body(body_id);
+            if let hir::ExprKind::Closure { body, .. } = acc.kind;
+            let closure_body = cx.tcx.hir().body(body);
             let closure_expr = peel_blocks(&closure_body.value);
 
             // Check if the closure body is of the form `acc <op> some_expr(x)`
index 2369be708129403f242fcdbfd55204d1295cf47b..865f6d0318eb9451c95b0e3bd40b9f667d419c14 100644 (file)
@@ -22,8 +22,8 @@ pub(super) fn check<'tcx>(
     let is_result = is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(recv), sym::Result);
 
     if is_option || is_result {
-        if let hir::ExprKind::Closure(_, _, eid, _, _) = arg.kind {
-            let body = cx.tcx.hir().body(eid);
+        if let hir::ExprKind::Closure { body, .. } = arg.kind {
+            let body = cx.tcx.hir().body(body);
             let body_expr = &body.value;
 
             if usage::BindingUsageFinder::are_params_used(cx, body) {
index 024bd0760715e449fffa03f4bcb77f2cae98a79b..c3b850fbb9dcc6823201c6dead09d7ae4a545103 100644 (file)
@@ -112,7 +112,7 @@ struct DivergenceVisitor<'a, 'tcx> {
 impl<'a, 'tcx> DivergenceVisitor<'a, 'tcx> {
     fn maybe_walk_expr(&mut self, e: &'tcx Expr<'_>) {
         match e.kind {
-            ExprKind::Closure(..) => {},
+            ExprKind::Closure { .. } => {},
             ExprKind::Match(e, arms, _) => {
                 self.visit_expr(e);
                 for arm in arms {
@@ -243,7 +243,7 @@ fn check_expr<'a, 'tcx>(vis: &mut ReadVisitor<'a, 'tcx>, expr: &'tcx Expr<'_>) -
                 walk_expr(vis, expr);
             }
         },
-        ExprKind::Closure(_, _, _, _, _) => {
+        ExprKind::Closure { .. } => {
             // Either
             //
             // * `var` is defined in the closure body, in which case we've reached the top of the enclosing
@@ -315,7 +315,7 @@ fn visit_expr(&mut self, expr: &'tcx Expr<'_>) {
             // We're about to descend a closure. Since we don't know when (or
             // if) the closure will be evaluated, any reads in it might not
             // occur here (or ever). Like above, bail to avoid false positives.
-            ExprKind::Closure(_, _, _, _, _) |
+            ExprKind::Closure{..} |
 
             // We want to avoid a false positive when a variable name occurs
             // only to have its address taken, so we stop here. Technically,
index 6cf513b214e6dd14559216f4e49aefb4cd0c2992..48ac695f2acfb67813675b217eb17ea08cba4d33 100644 (file)
@@ -72,8 +72,8 @@ fn check_stmt(&mut self, cx: &LateContext<'tcx>, stmt: &'tcx Stmt<'_>) {
             if has_iter_method(cx, cx.typeck_results().expr_ty(iter_recv)).is_some();
             // Skip the lint if the body is not block because this is simpler than `for` loop.
             // e.g. `v.iter().for_each(f)` is simpler and clearer than using `for` loop.
-            if let ExprKind::Closure(_, _, body_id, ..) = for_each_arg.kind;
-            let body = cx.tcx.hir().body(body_id);
+            if let ExprKind::Closure { body, .. } = for_each_arg.kind;
+            let body = cx.tcx.hir().body(body);
             if let ExprKind::Block(..) = body.value.kind;
             then {
                 let mut ret_collector = RetCollector::default();
index 5bf8a1ba1ca3010258ed4d12afe881b5cf88ea7d..6598413c77eccc7733f1b21c6649943c5ffa1391 100644 (file)
@@ -116,7 +116,7 @@ fn has_no_effect(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool {
         return false;
     }
     match peel_blocks(expr).kind {
-        ExprKind::Lit(..) | ExprKind::Closure(..) => true,
+        ExprKind::Lit(..) | ExprKind::Closure { .. } => true,
         ExprKind::Path(..) => !has_drop(cx, cx.typeck_results().expr_ty(expr)),
         ExprKind::Index(a, b) | ExprKind::Binary(_, a, b) => has_no_effect(cx, a) && has_no_effect(cx, b),
         ExprKind::Array(v) | ExprKind::Tup(v) => v.iter().all(|val| has_no_effect(cx, val)),
index d66698f8adc6927e1546214232364e2a3c7bfc97..de5f77f3ad976c025f8bdcf1ec2f1e25842ac71a 100644 (file)
@@ -298,8 +298,8 @@ fn visit_expr(&mut self, ex: &'tcx Expr<'tcx>) {
             },
             ExprKind::Match(expr, arms, _) => self.visit_match(expr, arms),
             // since analysing the closure is not easy, just set all variables in it to side-effect
-            ExprKind::Closure(_, _, body_id, _, _) => {
-                let body = self.tcx.hir().body(body_id);
+            ExprKind::Closure { body, .. } => {
+                let body = self.tcx.hir().body(body);
                 self.visit_body(body);
                 let vars = std::mem::take(&mut self.ret_vars);
                 self.add_side_effect(vars);
index 5a25008e95e5bceae5bc16f9311c8b9bc87b78f4..4c2016fe3f723c83233b88850a969ef0afa7389a 100644 (file)
@@ -134,7 +134,7 @@ fn nested_visit_map(&mut self) -> Self::Map {
             if_chain! {
                 if let hir::StmtKind::Local(local) = w[0].kind;
                 if let Option::Some(t) = local.init;
-                if let hir::ExprKind::Closure(..) = t.kind;
+                if let hir::ExprKind::Closure { .. } = t.kind;
                 if let hir::PatKind::Binding(_, _, ident, _) = local.pat.kind;
                 if let hir::StmtKind::Semi(second) = w[1].kind;
                 if let hir::ExprKind::Assign(_, call, _) = second.kind;
index 7c39a08a336b6565c984e7cfb37c07d35a94e343..f58da7ce9b42078b9d48ef7e3dd524db3bf8bcad 100644 (file)
@@ -116,13 +116,13 @@ fn get_args_to_check<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) -> Ve
 
 fn check_arg<'tcx>(cx: &LateContext<'tcx>, arg: &'tcx Expr<'tcx>) -> Option<(Span, Option<Span>)> {
     if_chain! {
-        if let ExprKind::Closure(_, _fn_decl, body_id, span, _) = arg.kind;
+        if let ExprKind::Closure { body, fn_decl_span, .. } = arg.kind;
         if let ty::Closure(_def_id, substs) = &cx.typeck_results().node_type(arg.hir_id).kind();
         let ret_ty = substs.as_closure().sig().output();
         let ty = cx.tcx.erase_late_bound_regions(ret_ty);
         if ty.is_unit();
         then {
-            let body = cx.tcx.hir().body(body_id);
+            let body = cx.tcx.hir().body(body);
             if_chain! {
                 if let ExprKind::Block(block, _) = body.value.kind;
                 if block.expr.is_none();
@@ -131,9 +131,9 @@ fn check_arg<'tcx>(cx: &LateContext<'tcx>, arg: &'tcx Expr<'tcx>) -> Option<(Spa
                 then {
                     let data = stmt.span.data();
                     // Make a span out of the semicolon for the help message
-                    Some((span, Some(data.with_lo(data.hi-BytePos(1)))))
+                    Some((fn_decl_span, Some(data.with_lo(data.hi-BytePos(1)))))
                 } else {
-                    Some((span, None))
+                    Some((fn_decl_span, None))
                 }
             }
         } else {
index d371cafb16b13e017d8cdf7b160193753543636c..7d4373b2a57bcfcc6a651d5209c3f89a86c59cee 100644 (file)
@@ -155,7 +155,7 @@ fn detect_lint(cx: &LateContext<'_>, expr: &Expr<'_>) -> Option<LintTrigger> {
         if let ExprKind::MethodCall(name_ident, args, _) = &expr.kind;
         if let name = name_ident.ident.name.to_ident_string();
         if name == "sort_by" || name == "sort_unstable_by";
-        if let [vec, Expr { kind: ExprKind::Closure(_, _, closure_body_id, _, _), .. }] = args;
+        if let [vec, Expr { kind: ExprKind::Closure{ body: closure_body_id, .. }, .. }] = args;
         if is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(vec), sym::Vec);
         if let closure_body = cx.tcx.hir().body(*closure_body_id);
         if let &[
index 3f4d0fd199d0814cd712d285571c48a83d615379..2c8820eb7e1a1faed0639c47926992c5e8136d2d 100644 (file)
@@ -466,7 +466,13 @@ macro_rules! kind {
                 self.expr(scrutinee);
                 self.slice(arms, |arm| self.arm(arm));
             },
-            ExprKind::Closure(capture_by, fn_decl, body_id, _, movability) => {
+            ExprKind::Closure {
+                capture_clause,
+                fn_decl,
+                body: body_id,
+                movability,
+                ..
+            } => {
                 let movability = OptionPat::new(movability.map(|m| format!("Movability::{m:?}")));
 
                 let ret_ty = match fn_decl.output {
@@ -475,7 +481,7 @@ macro_rules! kind {
                 };
 
                 bind!(self, fn_decl, body_id);
-                kind!("Closure(CaptureBy::{capture_by:?}, {fn_decl}, {body_id}, _, {movability})");
+                kind!("Closure(CaptureBy::{capture_clause:?}, {fn_decl}, {body_id}, _, {movability})");
                 out!("if let {ret_ty} = {fn_decl}.output;");
                 self.body(body_id);
             },
index 1a784b6cdda4c5934441a7f3b85378b6c7183087..730724b95b968277082b2f72c5fed88cc6645b1d 100644 (file)
@@ -198,7 +198,7 @@ fn visit_expr(&mut self, e: &'tcx Expr<'_>) {
                 | ExprKind::Let(..)
                 | ExprKind::If(..)
                 | ExprKind::Match(..)
-                | ExprKind::Closure(..)
+                | ExprKind::Closure { .. }
                 | ExprKind::Field(..)
                 | ExprKind::Path(_)
                 | ExprKind::AddrOf(..)
index 0603471c3431be2750b086d459c9b3a24dadce20..12931c56df619d332a501b2e4f27c288d820fadb 100644 (file)
@@ -622,10 +622,12 @@ pub fn hash_expr(&mut self, e: &Expr<'_>) {
                 self.hash_expr(e);
                 self.hash_ty(ty);
             },
-            ExprKind::Closure(cap, _, eid, _, _) => {
-                std::mem::discriminant(&cap).hash(&mut self.s);
+            ExprKind::Closure {
+                capture_clause, body, ..
+            } => {
+                std::mem::discriminant(&capture_clause).hash(&mut self.s);
                 // closures inherit TypeckResults
-                self.hash_expr(&self.cx.tcx.hir().body(eid).value);
+                self.hash_expr(&self.cx.tcx.hir().body(body).value);
             },
             ExprKind::Field(e, ref f) => {
                 self.hash_expr(e);
index 5f051e3f444c0eac2906760ae8729241c6e47f94..0cf23ca626c7542186c26b55e7e9fc171f8b8eb6 100644 (file)
@@ -962,7 +962,7 @@ fn visit_expr(&mut self, e: &'tcx Expr<'_>) {
                         self.captures.entry(l).and_modify(|e| *e |= cap).or_insert(cap);
                     }
                 },
-                ExprKind::Closure(..) => {
+                ExprKind::Closure { .. } => {
                     let closure_id = self.cx.tcx.hir().local_def_id(e.hir_id).to_def_id();
                     for capture in self.cx.typeck_results().closure_min_captures_flattened(closure_id) {
                         let local_id = match capture.place.base {
@@ -1200,7 +1200,7 @@ pub fn get_enclosing_loop_or_closure<'tcx>(tcx: TyCtxt<'tcx>, expr: &Expr<'_>) -
         match node {
             Node::Expr(
                 e @ Expr {
-                    kind: ExprKind::Loop(..) | ExprKind::Closure(..),
+                    kind: ExprKind::Loop(..) | ExprKind::Closure { .. },
                     ..
                 },
             ) => return Some(e),
@@ -1693,7 +1693,7 @@ pub fn get_async_fn_body<'tcx>(tcx: TyCtxt<'tcx>, body: &Body<'_>) -> Option<&'t
         _,
         &[
             Expr {
-                kind: ExprKind::Closure(_, _, body, _, _),
+                kind: ExprKind::Closure { body, .. },
                 ..
             },
         ],
@@ -1780,7 +1780,7 @@ fn is_body_identity_function(cx: &LateContext<'_>, func: &Body<'_>) -> bool {
     }
 
     match expr.kind {
-        ExprKind::Closure(_, _, body_id, _, _) => is_body_identity_function(cx, cx.tcx.hir().body(body_id)),
+        ExprKind::Closure { body, .. } => is_body_identity_function(cx, cx.tcx.hir().body(body)),
         _ => path_def_id(cx, expr).map_or(false, |id| match_def_path(cx, id, &paths::CONVERT_IDENTITY)),
     }
 }
index 4f3757f1ec673ad1410614325cf6f1c0f262c0b3..4d21ba8bd1d16b2a38081c816e38eb5679862095 100644 (file)
@@ -134,7 +134,7 @@ fn hir_from_snippet(expr: &hir::Expr<'_>, get_snippet: impl Fn(Span) -> Cow<'a,
             | hir::ExprKind::Box(..)
             | hir::ExprKind::If(..)
             | hir::ExprKind::Let(..)
-            | hir::ExprKind::Closure(..)
+            | hir::ExprKind::Closure { .. }
             | hir::ExprKind::Unary(..)
             | hir::ExprKind::Match(..) => Sugg::MaybeParen(get_snippet(expr.span)),
             hir::ExprKind::Continue(..)
@@ -188,7 +188,7 @@ pub fn ast(cx: &EarlyContext<'_>, expr: &ast::Expr, default: &'a str) -> Self {
         match expr.kind {
             ast::ExprKind::AddrOf(..)
             | ast::ExprKind::Box(..)
-            | ast::ExprKind::Closure(..)
+            | ast::ExprKind::Closure { .. }
             | ast::ExprKind::If(..)
             | ast::ExprKind::Let(..)
             | ast::ExprKind::Unary(..)
@@ -790,8 +790,8 @@ pub struct DerefClosure {
 ///
 /// note: this only works on single line immutable closures with exactly one input parameter.
 pub fn deref_closure_args<'tcx>(cx: &LateContext<'_>, closure: &'tcx hir::Expr<'_>) -> Option<DerefClosure> {
-    if let hir::ExprKind::Closure(_, fn_decl, body_id, ..) = closure.kind {
-        let closure_body = cx.tcx.hir().body(body_id);
+    if let hir::ExprKind::Closure { fn_decl, body, .. } = closure.kind {
+        let closure_body = cx.tcx.hir().body(body);
         // is closure arg a type annotated double reference (i.e.: `|x: &&i32| ...`)
         // a type annotation is present if param `kind` is different from `TyKind::Infer`
         let closure_arg_is_type_annotated_double_ref = if let TyKind::Rptr(_, MutTy { ty, .. }) = fn_decl.inputs[0].kind
index 9819778540cc942002c994c9b2e6a8dfa4c8fefb..3af5dfb62f97e112fb6b8268f3e9f3b263375a78 100644 (file)
@@ -185,7 +185,7 @@ pub fn local_used_after_expr(cx: &LateContext<'_>, local_id: HirId, after: &Expr
             matches!(
                 node,
                 Node::Expr(Expr {
-                    kind: ExprKind::Loop(..) | ExprKind::Closure(..),
+                    kind: ExprKind::Loop(..) | ExprKind::Closure { .. },
                     ..
                 })
             )