@@ -334,35 +334,7 @@ fn do_mir_borrowck<'tcx>(
334334    mbcx. gather_used_muts ( temporary_used_locals,  unused_mut_locals) ; 
335335
336336    debug ! ( "mbcx.used_mut: {:?}" ,  mbcx. used_mut) ; 
337-     let  used_mut = std:: mem:: take ( & mut  mbcx. used_mut ) ; 
338-     for  local in  mbcx. body . mut_vars_and_args_iter ( ) . filter ( |local| !used_mut. contains ( local) )  { 
339-         let  local_decl = & mbcx. body . local_decls [ local] ; 
340-         let  lint_root = match  & mbcx. body . source_scopes [ local_decl. source_info . scope ] . local_data  { 
341-             ClearCrossCrate :: Set ( data)  => data. lint_root , 
342-             _ => continue , 
343-         } ; 
344- 
345-         // Skip over locals that begin with an underscore or have no name 
346-         match  mbcx. local_names [ local]  { 
347-             Some ( name)  => { 
348-                 if  name. as_str ( ) . starts_with ( '_' )  { 
349-                     continue ; 
350-                 } 
351-             } 
352-             None  => continue , 
353-         } 
354- 
355-         let  span = local_decl. source_info . span ; 
356-         if  span. desugaring_kind ( ) . is_some ( )  { 
357-             // If the `mut` arises as part of a desugaring, we should ignore it. 
358-             continue ; 
359-         } 
360- 
361-         let  mut_span = tcx. sess . source_map ( ) . span_until_non_whitespace ( span) ; 
362- 
363-         tcx. emit_node_span_lint ( UNUSED_MUT ,  lint_root,  span,  VarNeedNotMut  {  span :  mut_span } ) 
364-     } 
365- 
337+     mbcx. lint_unused_mut ( ) ; 
366338    let  tainted_by_errors = mbcx. emit_errors ( ) ; 
367339
368340    let  result = BorrowCheckResult  { 
@@ -2390,6 +2362,38 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, '_, 'tcx> {
23902362        // `BasicBlocks` computes dominators on-demand and caches them. 
23912363        self . body . basic_blocks . dominators ( ) 
23922364    } 
2365+ 
2366+     fn  lint_unused_mut ( & self )  { 
2367+         let  tcx = self . infcx . tcx ; 
2368+         let  body = self . body ; 
2369+         for  local in  body. mut_vars_and_args_iter ( ) . filter ( |local| !self . used_mut . contains ( local) )  { 
2370+             let  local_decl = & body. local_decls [ local] ; 
2371+             let  lint_root = match  & body. source_scopes [ local_decl. source_info . scope ] . local_data  { 
2372+                 ClearCrossCrate :: Set ( data)  => data. lint_root , 
2373+                 _ => continue , 
2374+             } ; 
2375+ 
2376+             // Skip over locals that begin with an underscore or have no name 
2377+             match  self . local_names [ local]  { 
2378+                 Some ( name)  => { 
2379+                     if  name. as_str ( ) . starts_with ( '_' )  { 
2380+                         continue ; 
2381+                     } 
2382+                 } 
2383+                 None  => continue , 
2384+             } 
2385+ 
2386+             let  span = local_decl. source_info . span ; 
2387+             if  span. desugaring_kind ( ) . is_some ( )  { 
2388+                 // If the `mut` arises as part of a desugaring, we should ignore it. 
2389+                 continue ; 
2390+             } 
2391+ 
2392+             let  mut_span = tcx. sess . source_map ( ) . span_until_non_whitespace ( span) ; 
2393+ 
2394+             tcx. emit_node_span_lint ( UNUSED_MUT ,  lint_root,  span,  VarNeedNotMut  {  span :  mut_span } ) 
2395+         } 
2396+     } 
23932397} 
23942398
23952399mod  diags { 
0 commit comments