@@ -134,18 +134,10 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NeedlessPassByValue {
134134            spans_need_deref, 
135135            ..
136136        }  = { 
137-             let  mut  ctx = MovedVariablesCtxt :: new ( cx ) ; 
137+             let  mut  ctx = MovedVariablesCtxt :: default ( ) ; 
138138            let  region_scope_tree = & cx. tcx . region_scope_tree ( fn_def_id) ; 
139-             euv:: ExprUseVisitor :: new ( 
140-                 & mut  ctx, 
141-                 cx. tcx , 
142-                 fn_def_id, 
143-                 cx. param_env , 
144-                 region_scope_tree, 
145-                 cx. tables , 
146-                 None , 
147-             ) 
148-             . consume_body ( body) ; 
139+             euv:: ExprUseVisitor :: new ( & mut  ctx,  cx. tcx ,  fn_def_id,  cx. param_env ,  region_scope_tree,  cx. tables ) 
140+                 . consume_body ( body) ; 
149141            ctx
150142        } ; 
151143
@@ -325,115 +317,34 @@ fn requires_exact_signature(attrs: &[Attribute]) -> bool {
325317    } ) 
326318} 
327319
328- struct   MovedVariablesCtxt < ' a ,   ' tcx >   { 
329-      cx :   & ' a   LateContext < ' a ,   ' tcx > , 
320+ # [ derive ( Default ) ] 
321+ struct   MovedVariablesCtxt   { 
330322    moved_vars :  FxHashSet < HirId > , 
331323    /// Spans which need to be prefixed with `*` for dereferencing the 
332324/// suggested additional reference. 
333325spans_need_deref :  FxHashMap < HirId ,  FxHashSet < Span > > , 
334326} 
335327
336- impl < ' a ,  ' tcx >  MovedVariablesCtxt < ' a ,  ' tcx >  { 
337-     fn  new ( cx :  & ' a  LateContext < ' a ,  ' tcx > )  -> Self  { 
338-         Self  { 
339-             cx, 
340-             moved_vars :  FxHashSet :: default ( ) , 
341-             spans_need_deref :  FxHashMap :: default ( ) , 
342-         } 
343-     } 
344- 
345-     fn  move_common ( & mut  self ,  _consume_id :  HirId ,  _span :  Span ,  cmt :  & mc:: cmt_ < ' tcx > )  { 
328+ impl  MovedVariablesCtxt  { 
329+     fn  move_common ( & mut  self ,  cmt :  & mc:: cmt_ < ' _ > )  { 
346330        let  cmt = unwrap_downcast_or_interior ( cmt) ; 
347331
348332        if  let  mc:: Categorization :: Local ( vid)  = cmt. cat  { 
349333            self . moved_vars . insert ( vid) ; 
350334        } 
351335    } 
352- 
353-     fn  non_moving_pat ( & mut  self ,  matched_pat :  & Pat ,  cmt :  & mc:: cmt_ < ' tcx > )  { 
354-         let  cmt = unwrap_downcast_or_interior ( cmt) ; 
355- 
356-         if  let  mc:: Categorization :: Local ( vid)  = cmt. cat  { 
357-             let  mut  id = matched_pat. hir_id ; 
358-             loop  { 
359-                 let  parent = self . cx . tcx . hir ( ) . get_parent_node ( id) ; 
360-                 if  id == parent { 
361-                     // no parent 
362-                     return ; 
363-                 } 
364-                 id = parent; 
365- 
366-                 if  let  Some ( node)  = self . cx . tcx . hir ( ) . find ( id)  { 
367-                     match  node { 
368-                         Node :: Expr ( e)  => { 
369-                             // `match` and `if let` 
370-                             if  let  ExprKind :: Match ( ref  c,  ..)  = e. kind  { 
371-                                 self . spans_need_deref 
372-                                     . entry ( vid) 
373-                                     . or_insert_with ( FxHashSet :: default) 
374-                                     . insert ( c. span ) ; 
375-                             } 
376-                         } , 
377- 
378-                         Node :: Stmt ( s)  => { 
379-                             // `let <pat> = x;` 
380-                             if_chain !  { 
381-                                 if  let  StmtKind :: Local ( ref local)  = s. kind; 
382-                                 then { 
383-                                     self . spans_need_deref
384-                                         . entry( vid) 
385-                                         . or_insert_with( FxHashSet :: default ) 
386-                                         . insert( local. init
387-                                             . as_ref( ) 
388-                                             . map( |e| e. span) 
389-                                             . expect( "`let` stmt without init aren't caught by match_pat" ) ) ; 
390-                                 } 
391-                             } 
392-                         } , 
393- 
394-                         _ => { } , 
395-                     } 
396-                 } 
397-             } 
398-         } 
399-     } 
400336} 
401337
402- impl < ' a ,  ' tcx >  euv:: Delegate < ' tcx >  for  MovedVariablesCtxt < ' a ,  ' tcx >  { 
403-     fn  consume ( & mut  self ,  consume_id :  HirId ,  consume_span :  Span ,  cmt :  & mc:: cmt_ < ' tcx > ,  mode :  euv:: ConsumeMode )  { 
404-         if  let  euv:: ConsumeMode :: Move ( _)  = mode { 
405-             self . move_common ( consume_id,  consume_span,  cmt) ; 
406-         } 
407-     } 
408- 
409-     fn  matched_pat ( & mut  self ,  matched_pat :  & Pat ,  cmt :  & mc:: cmt_ < ' tcx > ,  mode :  euv:: MatchMode )  { 
410-         if  let  euv:: MatchMode :: MovingMatch  = mode { 
411-             self . move_common ( matched_pat. hir_id ,  matched_pat. span ,  cmt) ; 
412-         }  else  { 
413-             self . non_moving_pat ( matched_pat,  cmt) ; 
414-         } 
415-     } 
416- 
417-     fn  consume_pat ( & mut  self ,  consume_pat :  & Pat ,  cmt :  & mc:: cmt_ < ' tcx > ,  mode :  euv:: ConsumeMode )  { 
418-         if  let  euv:: ConsumeMode :: Move ( _)  = mode { 
419-             self . move_common ( consume_pat. hir_id ,  consume_pat. span ,  cmt) ; 
338+ impl < ' tcx >  euv:: Delegate < ' tcx >  for  MovedVariablesCtxt  { 
339+     fn  consume ( & mut  self ,  cmt :  & mc:: cmt_ < ' tcx > ,  mode :  euv:: ConsumeMode )  { 
340+         if  let  euv:: ConsumeMode :: Move  = mode { 
341+             self . move_common ( cmt) ; 
420342        } 
421343    } 
422344
423-     fn  borrow ( 
424-         & mut  self , 
425-         _:  HirId , 
426-         _:  Span , 
427-         _:  & mc:: cmt_ < ' tcx > , 
428-         _:  ty:: Region < ' _ > , 
429-         _:  ty:: BorrowKind , 
430-         _:  euv:: LoanCause , 
431-     )  { 
432-     } 
433- 
434-     fn  mutate ( & mut  self ,  _:  HirId ,  _:  Span ,  _:  & mc:: cmt_ < ' tcx > ,  _:  euv:: MutateMode )  { } 
345+     fn  borrow ( & mut  self ,  _:  & mc:: cmt_ < ' tcx > ,  _:  ty:: BorrowKind )  { } 
435346
436-     fn  decl_without_init ( & mut  self ,  _:  HirId ,  _ :   Span )  { } 
347+     fn  mutate ( & mut  self ,  _:  & mc :: cmt_ < ' tcx > )  { } 
437348} 
438349
439350fn  unwrap_downcast_or_interior < ' a ,  ' tcx > ( mut  cmt :  & ' a  mc:: cmt_ < ' tcx > )  -> mc:: cmt_ < ' tcx >  { 
0 commit comments