@@ -78,25 +78,15 @@ impl<'tcx> LateLintPass<'tcx> for RedundantLocal {
7878
7979/// Find the annotation of a binding introduced by a pattern, or `None` if it's not introduced.
8080fn find_binding ( pat : & Pat < ' _ > , name : Ident ) -> Option < BindingAnnotation > {
81- match pat. kind {
82- PatKind :: Binding ( annotation, _, ident, _) if ident == name => Some ( annotation) ,
83- PatKind :: Binding ( _, _, _, Some ( subpat) ) => find_binding ( subpat, name) ,
84- PatKind :: Struct ( _, fields, _) => fields. iter ( ) . find_map ( |field| find_binding ( field. pat , name) ) ,
85- PatKind :: TupleStruct ( _, fields, _) | PatKind :: Or ( fields) | PatKind :: Tuple ( fields, _) => {
86- fields. iter ( ) . find_map ( |field| find_binding ( field, name) )
87- } ,
88- PatKind :: Slice ( before, middle, after) => before
89- . iter ( )
90- . chain ( middle)
91- . chain ( after. iter ( ) )
92- . find_map ( |field| find_binding ( field, name) ) ,
93- PatKind :: Box ( inner) | PatKind :: Ref ( inner, _) => find_binding ( inner, name) ,
94- PatKind :: Wild
95- | PatKind :: Binding ( _, _, _, None )
96- | PatKind :: Path ( _)
97- | PatKind :: Lit ( _)
98- | PatKind :: Range ( _, _, _) => None ,
99- }
81+ let mut ret = None ;
82+
83+ pat. each_binding_or_first ( & mut |annotation, _, _, ident| {
84+ if ident == name {
85+ ret = Some ( annotation) ;
86+ }
87+ } ) ;
88+
89+ ret
10090}
10191
10292/// Check if a rebinding of a local affects the code's drop behavior.
0 commit comments