Skip to content

Commit f0444d7

Browse files
committed
Use each_binding_or_first in capture_local_usage
1 parent 10c0460 commit f0444d7

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

clippy_utils/src/lib.rs

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -733,16 +733,18 @@ impl std::ops::BitOrAssign for CaptureKind {
733733
pub fn capture_local_usage(cx: &LateContext<'tcx>, e: &Expr<'_>) -> CaptureKind {
734734
fn pat_capture_kind(cx: &LateContext<'_>, pat: &Pat<'_>) -> CaptureKind {
735735
let mut capture = CaptureKind::Ref(Mutability::Not);
736-
pat.each_binding(|_, id, span, _| {
737-
match cx.typeck_results().extract_binding_mode(cx.sess(), id, span).unwrap() {
738-
BindingMode::BindByValue(_) if !is_copy(cx, cx.typeck_results().node_type(id)) => {
739-
capture = CaptureKind::Value;
740-
},
741-
BindingMode::BindByReference(Mutability::Mut) if capture != CaptureKind::Value => {
742-
capture = CaptureKind::Ref(Mutability::Mut);
743-
},
744-
_ => (),
745-
}
736+
pat.each_binding_or_first(&mut |_, id, span, _| match cx
737+
.typeck_results()
738+
.extract_binding_mode(cx.sess(), id, span)
739+
.unwrap()
740+
{
741+
BindingMode::BindByValue(_) if !is_copy(cx, cx.typeck_results().node_type(id)) => {
742+
capture = CaptureKind::Value;
743+
},
744+
BindingMode::BindByReference(Mutability::Mut) if capture != CaptureKind::Value => {
745+
capture = CaptureKind::Ref(Mutability::Mut);
746+
},
747+
_ => (),
746748
});
747749
capture
748750
}

0 commit comments

Comments
 (0)