@@ -2263,6 +2263,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
22632263 current : usize ,
22642264 found : usize ,
22652265 prop_expr : Option < & ' tcx hir:: Expr < ' tcx > > ,
2266+ call : Option < & ' tcx hir:: Expr < ' tcx > > ,
22662267 }
22672268
22682269 impl < ' tcx > Visitor < ' tcx > for NestedStatementVisitor < ' tcx > {
@@ -2272,6 +2273,11 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
22722273 self . current -= 1 ;
22732274 }
22742275 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+ }
22752281 if self . span == expr. span . source_callsite ( ) {
22762282 self . found = self . current ;
22772283 if self . prop_expr . is_none ( ) {
@@ -2295,6 +2301,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
22952301 current : 0 ,
22962302 found : 0 ,
22972303 prop_expr : None ,
2304+ call : None ,
22982305 } ;
22992306 visitor. visit_stmt ( stmt) ;
23002307
@@ -2316,6 +2323,21 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
23162323 && let Some ( p) = sm. span_to_margin ( stmt. span )
23172324 && let Ok ( s) = sm. span_to_snippet ( proper_span)
23182325 {
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+ }
23192341 if !is_format_arguments_item {
23202342 let addition = format ! ( "let binding = {};\n {}" , s, " " . repeat( p) ) ;
23212343 err. multipart_suggestion_verbose (
0 commit comments