55pub use self :: ConsumeMode :: * ;
66
77// Export these here so that Clippy can use them.
8- pub use mc:: { Place , PlaceBase , Projection } ;
8+ pub use mc:: { PlaceBase , PlaceWithHirId , Projection } ;
99
1010use rustc_hir as hir;
1111use rustc_hir:: def:: Res ;
@@ -25,13 +25,13 @@ use rustc_span::Span;
2525pub trait Delegate < ' tcx > {
2626 // The value found at `place` is either copied or moved, depending
2727 // on mode.
28- fn consume ( & mut self , place : & mc:: Place < ' tcx > , mode : ConsumeMode ) ;
28+ fn consume ( & mut self , place_with_id : & mc:: PlaceWithHirId < ' tcx > , mode : ConsumeMode ) ;
2929
3030 // The value found at `place` is being borrowed with kind `bk`.
31- fn borrow ( & mut self , place : & mc:: Place < ' tcx > , bk : ty:: BorrowKind ) ;
31+ fn borrow ( & mut self , place_with_id : & mc:: PlaceWithHirId < ' tcx > , bk : ty:: BorrowKind ) ;
3232
33- // The path at `place ` is being assigned to.
34- fn mutate ( & mut self , assignee_place : & mc:: Place < ' tcx > ) ;
33+ // The path at `place_with_id ` is being assigned to.
34+ fn mutate ( & mut self , assignee_place : & mc:: PlaceWithHirId < ' tcx > ) ;
3535}
3636
3737#[ derive( Copy , Clone , PartialEq , Debug ) ]
@@ -113,11 +113,11 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> {
113113 self . mc . tcx ( )
114114 }
115115
116- fn delegate_consume ( & mut self , place : & Place < ' tcx > ) {
117- debug ! ( "delegate_consume(place ={:?})" , place ) ;
116+ fn delegate_consume ( & mut self , place_with_id : & PlaceWithHirId < ' tcx > ) {
117+ debug ! ( "delegate_consume(place_with_id ={:?})" , place_with_id ) ;
118118
119- let mode = copy_or_move ( & self . mc , place ) ;
120- self . delegate . consume ( place , mode) ;
119+ let mode = copy_or_move ( & self . mc , place_with_id ) ;
120+ self . delegate . consume ( place_with_id , mode) ;
121121 }
122122
123123 fn consume_exprs ( & mut self , exprs : & [ hir:: Expr < ' _ > ] ) {
@@ -129,22 +129,22 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> {
129129 pub fn consume_expr ( & mut self , expr : & hir:: Expr < ' _ > ) {
130130 debug ! ( "consume_expr(expr={:?})" , expr) ;
131131
132- let place = return_if_err ! ( self . mc. cat_expr( expr) ) ;
133- self . delegate_consume ( & place ) ;
132+ let place_with_id = return_if_err ! ( self . mc. cat_expr( expr) ) ;
133+ self . delegate_consume ( & place_with_id ) ;
134134 self . walk_expr ( expr) ;
135135 }
136136
137137 fn mutate_expr ( & mut self , expr : & hir:: Expr < ' _ > ) {
138- let place = return_if_err ! ( self . mc. cat_expr( expr) ) ;
139- self . delegate . mutate ( & place ) ;
138+ let place_with_id = return_if_err ! ( self . mc. cat_expr( expr) ) ;
139+ self . delegate . mutate ( & place_with_id ) ;
140140 self . walk_expr ( expr) ;
141141 }
142142
143143 fn borrow_expr ( & mut self , expr : & hir:: Expr < ' _ > , bk : ty:: BorrowKind ) {
144144 debug ! ( "borrow_expr(expr={:?}, bk={:?})" , expr, bk) ;
145145
146- let place = return_if_err ! ( self . mc. cat_expr( expr) ) ;
147- self . delegate . borrow ( & place , bk) ;
146+ let place_with_id = return_if_err ! ( self . mc. cat_expr( expr) ) ;
147+ self . delegate . borrow ( & place_with_id , bk) ;
148148
149149 self . walk_expr ( expr)
150150 }
@@ -384,7 +384,7 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> {
384384
385385 // Select just those fields of the `with`
386386 // expression that will actually be used
387- match with_place. ty . kind {
387+ match with_place. place . ty . kind {
388388 ty:: Adt ( adt, substs) if adt. is_struct ( ) => {
389389 // Consume those fields of the with expression that are needed.
390390 for ( f_index, with_field) in adt. non_enum_variant ( ) . fields . iter ( ) . enumerate ( ) {
@@ -422,14 +422,14 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> {
422422 // process.
423423 fn walk_adjustment ( & mut self , expr : & hir:: Expr < ' _ > ) {
424424 let adjustments = self . mc . tables . expr_adjustments ( expr) ;
425- let mut place = return_if_err ! ( self . mc. cat_expr_unadjusted( expr) ) ;
425+ let mut place_with_id = return_if_err ! ( self . mc. cat_expr_unadjusted( expr) ) ;
426426 for adjustment in adjustments {
427427 debug ! ( "walk_adjustment expr={:?} adj={:?}" , expr, adjustment) ;
428428 match adjustment. kind {
429429 adjustment:: Adjust :: NeverToAny | adjustment:: Adjust :: Pointer ( _) => {
430430 // Creating a closure/fn-pointer or unsizing consumes
431431 // the input and stores it into the resulting rvalue.
432- self . delegate_consume ( & place ) ;
432+ self . delegate_consume ( & place_with_id ) ;
433433 }
434434
435435 adjustment:: Adjust :: Deref ( None ) => { }
@@ -441,14 +441,15 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> {
441441 // this is an autoref of `x`.
442442 adjustment:: Adjust :: Deref ( Some ( ref deref) ) => {
443443 let bk = ty:: BorrowKind :: from_mutbl ( deref. mutbl ) ;
444- self . delegate . borrow ( & place , bk) ;
444+ self . delegate . borrow ( & place_with_id , bk) ;
445445 }
446446
447447 adjustment:: Adjust :: Borrow ( ref autoref) => {
448- self . walk_autoref ( expr, & place , autoref) ;
448+ self . walk_autoref ( expr, & place_with_id , autoref) ;
449449 }
450450 }
451- place = return_if_err ! ( self . mc. cat_expr_adjusted( expr, place, & adjustment) ) ;
451+ place_with_id =
452+ return_if_err ! ( self . mc. cat_expr_adjusted( expr, place_with_id, & adjustment) ) ;
452453 }
453454 }
454455
@@ -458,7 +459,7 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> {
458459 fn walk_autoref (
459460 & mut self ,
460461 expr : & hir:: Expr < ' _ > ,
461- base_place : & mc:: Place < ' tcx > ,
462+ base_place : & mc:: PlaceWithHirId < ' tcx > ,
462463 autoref : & adjustment:: AutoBorrow < ' tcx > ,
463464 ) {
464465 debug ! (
@@ -479,7 +480,7 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> {
479480 }
480481 }
481482
482- fn walk_arm ( & mut self , discr_place : & Place < ' tcx > , arm : & hir:: Arm < ' _ > ) {
483+ fn walk_arm ( & mut self , discr_place : & PlaceWithHirId < ' tcx > , arm : & hir:: Arm < ' _ > ) {
483484 self . walk_pat ( discr_place, & arm. pat ) ;
484485
485486 if let Some ( hir:: Guard :: If ( ref e) ) = arm. guard {
@@ -491,12 +492,12 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> {
491492
492493 /// Walks a pat that occurs in isolation (i.e., top-level of fn argument or
493494 /// let binding, and *not* a match arm or nested pat.)
494- fn walk_irrefutable_pat ( & mut self , discr_place : & Place < ' tcx > , pat : & hir:: Pat < ' _ > ) {
495+ fn walk_irrefutable_pat ( & mut self , discr_place : & PlaceWithHirId < ' tcx > , pat : & hir:: Pat < ' _ > ) {
495496 self . walk_pat ( discr_place, pat) ;
496497 }
497498
498499 /// The core driver for walking a pattern
499- fn walk_pat ( & mut self , discr_place : & Place < ' tcx > , pat : & hir:: Pat < ' _ > ) {
500+ fn walk_pat ( & mut self , discr_place : & PlaceWithHirId < ' tcx > , pat : & hir:: Pat < ' _ > ) {
500501 debug ! ( "walk_pat(discr_place={:?}, pat={:?})" , discr_place, pat) ;
501502
502503 let tcx = self . tcx ( ) ;
@@ -569,7 +570,7 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> {
569570 closure_hir_id : hir:: HirId ,
570571 closure_span : Span ,
571572 var_id : hir:: HirId ,
572- ) -> mc:: McResult < mc:: Place < ' tcx > > {
573+ ) -> mc:: McResult < mc:: PlaceWithHirId < ' tcx > > {
573574 // Create the place for the variable being borrowed, from the
574575 // perspective of the creator (parent) of the closure.
575576 let var_ty = self . mc . node_ty ( var_id) ?;
@@ -579,7 +580,14 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> {
579580
580581fn copy_or_move < ' a , ' tcx > (
581582 mc : & mc:: MemCategorizationContext < ' a , ' tcx > ,
582- place : & Place < ' tcx > ,
583+ place_with_id : & PlaceWithHirId < ' tcx > ,
583584) -> ConsumeMode {
584- if !mc. type_is_copy_modulo_regions ( place. ty , place. span ) { Move } else { Copy }
585+ if !mc. type_is_copy_modulo_regions (
586+ place_with_id. place . ty ,
587+ mc. tcx ( ) . hir ( ) . span ( place_with_id. hir_id ) ,
588+ ) {
589+ Move
590+ } else {
591+ Copy
592+ }
585593}
0 commit comments