@@ -1131,6 +1131,23 @@ fn detect_same_item_push<'tcx>(
11311131 body : & ' tcx Expr < ' _ > ,
11321132 _: & ' tcx Expr < ' _ > ,
11331133) {
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+
11341151 if !matches ! ( pat. kind, PatKind :: Wild ) {
11351152 return ;
11361153 }
@@ -1192,23 +1209,6 @@ fn detect_same_item_push<'tcx>(
11921209 }
11931210 }
11941211 }
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- }
12121212}
12131213
12141214/// Checks for looping over a range and then indexing a sequence with it.
0 commit comments