@@ -134,7 +134,7 @@ 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) ;
139139 euv:: ExprUseVisitor :: new (
140140 & mut ctx,
@@ -324,101 +324,31 @@ fn requires_exact_signature(attrs: &[Attribute]) -> bool {
324324 } )
325325}
326326
327- struct MovedVariablesCtxt < ' a , ' tcx > {
328- cx : & ' a LateContext < ' a , ' tcx > ,
327+ # [ derive ( Default ) ]
328+ struct MovedVariablesCtxt {
329329 moved_vars : FxHashSet < HirId > ,
330330 /// Spans which need to be prefixed with `*` for dereferencing the
331331 /// suggested additional reference.
332332 spans_need_deref : FxHashMap < HirId , FxHashSet < Span > > ,
333333}
334334
335- impl < ' a , ' tcx > MovedVariablesCtxt < ' a , ' tcx > {
336- fn new ( cx : & ' a LateContext < ' a , ' tcx > ) -> Self {
337- Self {
338- cx,
339- moved_vars : FxHashSet :: default ( ) ,
340- spans_need_deref : FxHashMap :: default ( ) ,
341- }
342- }
343-
344- fn move_common ( & mut self , _consume_id : HirId , _span : Span , cmt : & mc:: cmt_ < ' tcx > ) {
335+ impl MovedVariablesCtxt {
336+ fn move_common ( & mut self , _consume_id : HirId , _span : Span , cmt : & mc:: cmt_ < ' _ > ) {
345337 let cmt = unwrap_downcast_or_interior ( cmt) ;
346338
347339 if let mc:: Categorization :: Local ( vid) = cmt. cat {
348340 self . moved_vars . insert ( vid) ;
349341 }
350342 }
351-
352- fn non_moving_pat ( & mut self , matched_pat : & Pat , cmt : & mc:: cmt_ < ' tcx > ) {
353- let cmt = unwrap_downcast_or_interior ( cmt) ;
354-
355- if let mc:: Categorization :: Local ( vid) = cmt. cat {
356- let mut id = matched_pat. hir_id ;
357- loop {
358- let parent = self . cx . tcx . hir ( ) . get_parent_node ( id) ;
359- if id == parent {
360- // no parent
361- return ;
362- }
363- id = parent;
364-
365- if let Some ( node) = self . cx . tcx . hir ( ) . find ( id) {
366- match node {
367- Node :: Expr ( e) => {
368- // `match` and `if let`
369- if let ExprKind :: Match ( ref c, ..) = e. kind {
370- self . spans_need_deref
371- . entry ( vid)
372- . or_insert_with ( FxHashSet :: default)
373- . insert ( c. span ) ;
374- }
375- } ,
376-
377- Node :: Stmt ( s) => {
378- // `let <pat> = x;`
379- if_chain ! {
380- if let StmtKind :: Local ( ref local) = s. kind;
381- then {
382- self . spans_need_deref
383- . entry( vid)
384- . or_insert_with( FxHashSet :: default )
385- . insert( local. init
386- . as_ref( )
387- . map( |e| e. span)
388- . expect( "`let` stmt without init aren't caught by match_pat" ) ) ;
389- }
390- }
391- } ,
392-
393- _ => { } ,
394- }
395- }
396- }
397- }
398- }
399343}
400344
401- impl < ' a , ' tcx > euv:: Delegate < ' tcx > for MovedVariablesCtxt < ' a , ' tcx > {
345+ impl < ' tcx > euv:: Delegate < ' tcx > for MovedVariablesCtxt {
402346 fn consume ( & mut self , cmt : & mc:: cmt_ < ' tcx > , mode : euv:: ConsumeMode ) {
403347 if let euv:: ConsumeMode :: Move = mode {
404348 self . move_common ( cmt. hir_id , cmt. span , cmt) ;
405349 }
406350 }
407351
408- fn matched_pat ( & mut self , matched_pat : & Pat , cmt : & mc:: cmt_ < ' tcx > , mode : euv:: MatchMode ) {
409- if let euv:: MatchMode :: MovingMatch = mode {
410- self . move_common ( matched_pat. hir_id , matched_pat. span , cmt) ;
411- } else {
412- self . non_moving_pat ( matched_pat, cmt) ;
413- }
414- }
415-
416- fn consume_pat ( & mut self , consume_pat : & Pat , cmt : & mc:: cmt_ < ' tcx > , mode : euv:: ConsumeMode ) {
417- if let euv:: ConsumeMode :: Move ( _) = mode {
418- self . move_common ( consume_pat. hir_id , consume_pat. span , cmt) ;
419- }
420- }
421-
422352 fn borrow (
423353 & mut self ,
424354 _: & mc:: cmt_ < ' tcx > ,
0 commit comments