@@ -1131,6 +1131,10 @@ fn detect_same_item_push<'tcx>(
11311131 body : & ' tcx Expr < ' _ > ,
11321132 _: & ' tcx Expr < ' _ > ,
11331133) {
1134+ if !matches ! ( pat. kind, PatKind :: Wild ) {
1135+ return ;
1136+ }
1137+
11341138 // Determine whether it is safe to lint the body
11351139 let mut same_item_push_visitor = SameItemPushVisitor {
11361140 should_lint : true ,
@@ -1149,8 +1153,8 @@ fn detect_same_item_push<'tcx>(
11491153 . map_or ( false , |id| implements_trait ( cx, ty, id, & [ ] ) )
11501154 {
11511155 // Make sure that the push does not involve possibly mutating values
1152- if let PatKind :: Wild = pat . kind {
1153- if let ExprKind :: Path ( ref qpath) = pushed_item . kind {
1156+ match pushed_item . kind {
1157+ ExprKind :: Path ( ref qpath) => {
11541158 match qpath_res ( cx, qpath, pushed_item. hir_id ) {
11551159 // immutable bindings that are initialized with literal or constant
11561160 Res :: Local ( hir_id) => {
@@ -1161,7 +1165,7 @@ fn detect_same_item_push<'tcx>(
11611165 if !matches!( bind_ann, BindingAnnotation :: RefMut | BindingAnnotation :: Mutable ) ;
11621166 let parent_node = cx. tcx. hir( ) . get_parent_node( hir_id) ;
11631167 if let Some ( Node :: Local ( parent_let_expr) ) = cx. tcx. hir( ) . find( parent_node) ;
1164- if let rustc_hir :: Local { init : Some ( init) , .. } = parent_let_expr;
1168+ if let Some ( init) = parent_let_expr. init ;
11651169 then {
11661170 match init. kind {
11671171 // immutable bindings that are initialized with literal
@@ -1181,10 +1185,9 @@ fn detect_same_item_push<'tcx>(
11811185 Res :: Def ( DefKind :: Const , ..) => emit_lint ( cx, vec, pushed_item) ,
11821186 _ => { } ,
11831187 }
1184- } else if let ExprKind :: Lit ( ..) = pushed_item. kind {
1185- // literal
1186- emit_lint ( cx, vec, pushed_item) ;
1187- }
1188+ } ,
1189+ ExprKind :: Lit ( ..) => emit_lint ( cx, vec, pushed_item) ,
1190+ _ => { } ,
11881191 }
11891192 }
11901193 }
0 commit comments