@@ -1131,6 +1131,23 @@ fn detect_same_item_push<'tcx>(
1131
1131
body : & ' tcx Expr < ' _ > ,
1132
1132
_: & ' tcx Expr < ' _ > ,
1133
1133
) {
1134
+ fn emit_lint ( cx : & LateContext < ' _ > , vec : & Expr < ' _ > , pushed_item : & Expr < ' _ > ) {
1135
+ let vec_str = snippet_with_macro_callsite ( cx, vec. span , "" ) ;
1136
+ let item_str = snippet_with_macro_callsite ( cx, pushed_item. span , "" ) ;
1137
+
1138
+ span_lint_and_help (
1139
+ cx,
1140
+ SAME_ITEM_PUSH ,
1141
+ vec. span ,
1142
+ "it looks like the same item is being pushed into this Vec" ,
1143
+ None ,
1144
+ & format ! (
1145
+ "try using vec![{};SIZE] or {}.resize(NEW_SIZE, {})" ,
1146
+ item_str, vec_str, item_str
1147
+ ) ,
1148
+ )
1149
+ }
1150
+
1134
1151
if !matches ! ( pat. kind, PatKind :: Wild ) {
1135
1152
return ;
1136
1153
}
@@ -1192,23 +1209,6 @@ fn detect_same_item_push<'tcx>(
1192
1209
}
1193
1210
}
1194
1211
}
1195
-
1196
- fn emit_lint ( cx : & LateContext < ' _ > , vec : & Expr < ' _ > , pushed_item : & Expr < ' _ > ) {
1197
- let vec_str = snippet_with_macro_callsite ( cx, vec. span , "" ) ;
1198
- let item_str = snippet_with_macro_callsite ( cx, pushed_item. span , "" ) ;
1199
-
1200
- span_lint_and_help (
1201
- cx,
1202
- SAME_ITEM_PUSH ,
1203
- vec. span ,
1204
- "it looks like the same item is being pushed into this Vec" ,
1205
- None ,
1206
- & format ! (
1207
- "try using vec![{};SIZE] or {}.resize(NEW_SIZE, {})" ,
1208
- item_str, vec_str, item_str
1209
- ) ,
1210
- )
1211
- }
1212
1212
}
1213
1213
1214
1214
/// Checks for looping over a range and then indexing a sequence with it.
0 commit comments