@@ -1131,6 +1131,10 @@ fn detect_same_item_push<'tcx>(
1131
1131
body : & ' tcx Expr < ' _ > ,
1132
1132
_: & ' tcx Expr < ' _ > ,
1133
1133
) {
1134
+ if !matches ! ( pat. kind, PatKind :: Wild ) {
1135
+ return ;
1136
+ }
1137
+
1134
1138
// Determine whether it is safe to lint the body
1135
1139
let mut same_item_push_visitor = SameItemPushVisitor {
1136
1140
should_lint : true ,
@@ -1149,8 +1153,8 @@ fn detect_same_item_push<'tcx>(
1149
1153
. map_or ( false , |id| implements_trait ( cx, ty, id, & [ ] ) )
1150
1154
{
1151
1155
// 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) => {
1154
1158
match qpath_res ( cx, qpath, pushed_item. hir_id ) {
1155
1159
// immutable bindings that are initialized with literal or constant
1156
1160
Res :: Local ( hir_id) => {
@@ -1161,7 +1165,7 @@ fn detect_same_item_push<'tcx>(
1161
1165
if !matches!( bind_ann, BindingAnnotation :: RefMut | BindingAnnotation :: Mutable ) ;
1162
1166
let parent_node = cx. tcx. hir( ) . get_parent_node( hir_id) ;
1163
1167
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 ;
1165
1169
then {
1166
1170
match init. kind {
1167
1171
// immutable bindings that are initialized with literal
@@ -1181,10 +1185,9 @@ fn detect_same_item_push<'tcx>(
1181
1185
Res :: Def ( DefKind :: Const , ..) => emit_lint ( cx, vec, pushed_item) ,
1182
1186
_ => { } ,
1183
1187
}
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
+ _ => { } ,
1188
1191
}
1189
1192
}
1190
1193
}
0 commit comments