From f0444d73def161f7f0fda7b3f5a13e9908e9c550 Mon Sep 17 00:00:00 2001
From: Jason Newcomb <jsnewcomb@pm.me>
Date: Sun, 15 Aug 2021 20:25:10 -0400
Subject: [PATCH] Use `each_binding_or_first` in `capture_local_usage`

---
 clippy_utils/src/lib.rs | 22 ++++++++++++----------
 1 file changed, 12 insertions(+), 10 deletions(-)

diff --git a/clippy_utils/src/lib.rs b/clippy_utils/src/lib.rs
index b40b42fa6d3..bd229402f41 100644
--- a/clippy_utils/src/lib.rs
+++ b/clippy_utils/src/lib.rs
@@ -733,16 +733,18 @@ impl std::ops::BitOrAssign for CaptureKind {
 pub fn capture_local_usage(cx: &LateContext<'tcx>, e: &Expr<'_>) -> CaptureKind {
     fn pat_capture_kind(cx: &LateContext<'_>, pat: &Pat<'_>) -> CaptureKind {
         let mut capture = CaptureKind::Ref(Mutability::Not);
-        pat.each_binding(|_, id, span, _| {
-            match cx.typeck_results().extract_binding_mode(cx.sess(), id, span).unwrap() {
-                BindingMode::BindByValue(_) if !is_copy(cx, cx.typeck_results().node_type(id)) => {
-                    capture = CaptureKind::Value;
-                },
-                BindingMode::BindByReference(Mutability::Mut) if capture != CaptureKind::Value => {
-                    capture = CaptureKind::Ref(Mutability::Mut);
-                },
-                _ => (),
-            }
+        pat.each_binding_or_first(&mut |_, id, span, _| match cx
+            .typeck_results()
+            .extract_binding_mode(cx.sess(), id, span)
+            .unwrap()
+        {
+            BindingMode::BindByValue(_) if !is_copy(cx, cx.typeck_results().node_type(id)) => {
+                capture = CaptureKind::Value;
+            },
+            BindingMode::BindByReference(Mutability::Mut) if capture != CaptureKind::Value => {
+                capture = CaptureKind::Ref(Mutability::Mut);
+            },
+            _ => (),
         });
         capture
     }