@@ -2263,6 +2263,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
2263
2263
current : usize ,
2264
2264
found : usize ,
2265
2265
prop_expr : Option < & ' tcx hir:: Expr < ' tcx > > ,
2266
+ call : Option < & ' tcx hir:: Expr < ' tcx > > ,
2266
2267
}
2267
2268
2268
2269
impl < ' tcx > Visitor < ' tcx > for NestedStatementVisitor < ' tcx > {
@@ -2272,6 +2273,11 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
2272
2273
self . current -= 1 ;
2273
2274
}
2274
2275
fn visit_expr ( & mut self , expr : & ' tcx hir:: Expr < ' tcx > ) {
2276
+ if let hir:: ExprKind :: MethodCall ( _, rcvr, _, _) = expr. kind {
2277
+ if self . span == rcvr. span . source_callsite ( ) {
2278
+ self . call = Some ( expr) ;
2279
+ }
2280
+ }
2275
2281
if self . span == expr. span . source_callsite ( ) {
2276
2282
self . found = self . current ;
2277
2283
if self . prop_expr . is_none ( ) {
@@ -2295,6 +2301,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
2295
2301
current : 0 ,
2296
2302
found : 0 ,
2297
2303
prop_expr : None ,
2304
+ call : None ,
2298
2305
} ;
2299
2306
visitor. visit_stmt ( stmt) ;
2300
2307
@@ -2316,6 +2323,21 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
2316
2323
&& let Some ( p) = sm. span_to_margin ( stmt. span )
2317
2324
&& let Ok ( s) = sm. span_to_snippet ( proper_span)
2318
2325
{
2326
+ if let Some ( call) = visitor. call
2327
+ && let hir:: ExprKind :: MethodCall ( path, _, [ ] , _) = call. kind
2328
+ && path. ident . name == sym:: iter
2329
+ && let Some ( ty) = expr_ty
2330
+ {
2331
+ err. span_suggestion_verbose (
2332
+ path. ident . span ,
2333
+ format ! (
2334
+ "consider consuming the `{ty}` when turning it into an \
2335
+ `Iterator`",
2336
+ ) ,
2337
+ "into_iter" . to_string ( ) ,
2338
+ Applicability :: MaybeIncorrect ,
2339
+ ) ;
2340
+ }
2319
2341
if !is_format_arguments_item {
2320
2342
let addition = format ! ( "let binding = {};\n {}" , s, " " . repeat( p) ) ;
2321
2343
err. multipart_suggestion_verbose (
0 commit comments