@@ -13,7 +13,6 @@ use crate::middle::mem_categorization as mc;
1313use crate :: ty:: { self , TyCtxt , adjustment} ;
1414
1515use crate :: hir:: { self , PatKind } ;
16- use std:: rc:: Rc ;
1716use syntax_pos:: Span ;
1817
1918///////////////////////////////////////////////////////////////////////////
@@ -136,12 +135,9 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> {
136135 let param_ty = return_if_err ! ( self . mc. pat_ty_adjusted( & param. pat) ) ;
137136 debug ! ( "consume_body: param_ty = {:?}" , param_ty) ;
138137
139- let param_cmt = Rc :: new ( self . mc . cat_rvalue (
140- param. hir_id ,
141- param. pat . span ,
142- param_ty) ) ;
138+ let param_place = self . mc . cat_rvalue ( param. hir_id , param. pat . span , param_ty) ;
143139
144- self . walk_irrefutable_pat ( param_cmt , & param. pat ) ;
140+ self . walk_irrefutable_pat ( & param_place , & param. pat ) ;
145141 }
146142
147143 self . consume_expr ( & body. value ) ;
@@ -234,12 +230,12 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> {
234230 }
235231
236232 hir:: ExprKind :: Match ( ref discr, ref arms, _) => {
237- let discr_cmt = Rc :: new ( return_if_err ! ( self . mc. cat_expr( & discr) ) ) ;
233+ let discr_cmt = return_if_err ! ( self . mc. cat_expr( & discr) ) ;
238234 self . borrow_expr ( & discr, ty:: ImmBorrow ) ;
239235
240236 // treatment of the discriminant is handled while walking the arms.
241237 for arm in arms {
242- self . walk_arm ( discr_cmt. clone ( ) , arm) ;
238+ self . walk_arm ( & discr_cmt, arm) ;
243239 }
244240 }
245241
@@ -385,8 +381,8 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> {
385381 // "assigns", which is handled by
386382 // `walk_pat`:
387383 self . walk_expr ( & expr) ;
388- let init_cmt = Rc :: new ( return_if_err ! ( self . mc. cat_expr( & expr) ) ) ;
389- self . walk_irrefutable_pat ( init_cmt, & local. pat ) ;
384+ let init_cmt = return_if_err ! ( self . mc. cat_expr( & expr) ) ;
385+ self . walk_irrefutable_pat ( & init_cmt, & local. pat ) ;
390386 }
391387 }
392388
@@ -417,26 +413,24 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> {
417413 None => { return ; }
418414 } ;
419415
420- let with_cmt = Rc :: new ( return_if_err ! ( self . mc. cat_expr( & with_expr) ) ) ;
416+ let with_place = return_if_err ! ( self . mc. cat_expr( & with_expr) ) ;
421417
422418 // Select just those fields of the `with`
423419 // expression that will actually be used
424- match with_cmt . ty . kind {
420+ match with_place . ty . kind {
425421 ty:: Adt ( adt, substs) if adt. is_struct ( ) => {
426422 // Consume those fields of the with expression that are needed.
427423 for ( f_index, with_field) in adt. non_enum_variant ( ) . fields . iter ( ) . enumerate ( ) {
428424 let is_mentioned = fields. iter ( ) . any ( |f| {
429425 self . tcx ( ) . field_index ( f. hir_id , self . mc . tables ) == f_index
430426 } ) ;
431427 if !is_mentioned {
432- let cmt_field = self . mc . cat_field (
428+ let field_place = self . mc . cat_projection (
433429 & * with_expr,
434- with_cmt. clone ( ) ,
435- f_index,
436- with_field. ident ,
437- with_field. ty ( self . tcx ( ) , substs)
430+ with_place. clone ( ) ,
431+ with_field. ty ( self . tcx ( ) , substs) ,
438432 ) ;
439- self . delegate_consume ( & cmt_field ) ;
433+ self . delegate_consume ( & field_place ) ;
440434 }
441435 }
442436 }
@@ -522,8 +516,8 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> {
522516 }
523517 }
524518
525- fn walk_arm ( & mut self , discr_cmt : mc:: cmt < ' tcx > , arm : & hir:: Arm ) {
526- self . walk_pat ( discr_cmt . clone ( ) , & arm. pat ) ;
519+ fn walk_arm ( & mut self , discr_place : & mc:: Place < ' tcx > , arm : & hir:: Arm ) {
520+ self . walk_pat ( discr_place , & arm. pat ) ;
527521
528522 if let Some ( hir:: Guard :: If ( ref e) ) = arm. guard {
529523 self . consume_expr ( e)
@@ -534,22 +528,22 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> {
534528
535529 /// Walks a pat that occurs in isolation (i.e., top-level of fn argument or
536530 /// let binding, and *not* a match arm or nested pat.)
537- fn walk_irrefutable_pat ( & mut self , cmt_discr : mc:: cmt < ' tcx > , pat : & hir:: Pat ) {
538- self . walk_pat ( cmt_discr , pat) ;
531+ fn walk_irrefutable_pat ( & mut self , discr_place : & mc:: Place < ' tcx > , pat : & hir:: Pat ) {
532+ self . walk_pat ( discr_place , pat) ;
539533 }
540534
541535
542536 /// The core driver for walking a pattern
543- fn walk_pat ( & mut self , cmt_discr : mc:: cmt < ' tcx > , pat : & hir:: Pat ) {
544- debug ! ( "walk_pat(cmt_discr ={:?}, pat={:?})" , cmt_discr , pat) ;
537+ fn walk_pat ( & mut self , discr_place : & mc:: Place < ' tcx > , pat : & hir:: Pat ) {
538+ debug ! ( "walk_pat(discr_place ={:?}, pat={:?})" , discr_place , pat) ;
545539
546540 let tcx = self . tcx ( ) ;
547541 let ExprUseVisitor { ref mc, ref mut delegate } = * self ;
548- return_if_err ! ( mc. cat_pattern( cmt_discr . clone( ) , pat, |cmt_pat , pat| {
542+ return_if_err ! ( mc. cat_pattern( discr_place . clone( ) , pat, |place , pat| {
549543 if let PatKind :: Binding ( _, canonical_id, ..) = pat. kind {
550544 debug!(
551- "walk_pat: binding cmt_pat ={:?} pat={:?}" ,
552- cmt_pat ,
545+ "walk_pat: binding place ={:?} pat={:?}" ,
546+ place ,
553547 pat,
554548 ) ;
555549 if let Some ( & bm) = mc. tables. pat_binding_modes( ) . get( pat. hir_id) {
@@ -570,12 +564,12 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> {
570564 match bm {
571565 ty:: BindByReference ( m) => {
572566 let bk = ty:: BorrowKind :: from_mutbl( m) ;
573- delegate. borrow( & cmt_pat , bk) ;
567+ delegate. borrow( place , bk) ;
574568 }
575569 ty:: BindByValue ( ..) => {
576- let mode = copy_or_move( mc, & cmt_pat ) ;
570+ let mode = copy_or_move( mc, place ) ;
577571 debug!( "walk_pat binding consuming pat" ) ;
578- delegate. consume( & cmt_pat , mode) ;
572+ delegate. consume( place , mode) ;
579573 }
580574 }
581575 } else {
0 commit comments