@@ -13,7 +13,6 @@ use crate::middle::mem_categorization as mc;
13
13
use crate :: ty:: { self , TyCtxt , adjustment} ;
14
14
15
15
use crate :: hir:: { self , PatKind } ;
16
- use std:: rc:: Rc ;
17
16
use syntax_pos:: Span ;
18
17
19
18
///////////////////////////////////////////////////////////////////////////
@@ -136,12 +135,9 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> {
136
135
let param_ty = return_if_err ! ( self . mc. pat_ty_adjusted( & param. pat) ) ;
137
136
debug ! ( "consume_body: param_ty = {:?}" , param_ty) ;
138
137
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) ;
143
139
144
- self . walk_irrefutable_pat ( param_cmt , & param. pat ) ;
140
+ self . walk_irrefutable_pat ( & param_place , & param. pat ) ;
145
141
}
146
142
147
143
self . consume_expr ( & body. value ) ;
@@ -234,12 +230,12 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> {
234
230
}
235
231
236
232
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) ) ;
238
234
self . borrow_expr ( & discr, ty:: ImmBorrow ) ;
239
235
240
236
// treatment of the discriminant is handled while walking the arms.
241
237
for arm in arms {
242
- self . walk_arm ( discr_cmt. clone ( ) , arm) ;
238
+ self . walk_arm ( & discr_cmt, arm) ;
243
239
}
244
240
}
245
241
@@ -385,8 +381,8 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> {
385
381
// "assigns", which is handled by
386
382
// `walk_pat`:
387
383
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 ) ;
390
386
}
391
387
}
392
388
@@ -417,26 +413,24 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> {
417
413
None => { return ; }
418
414
} ;
419
415
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) ) ;
421
417
422
418
// Select just those fields of the `with`
423
419
// expression that will actually be used
424
- match with_cmt . ty . kind {
420
+ match with_place . ty . kind {
425
421
ty:: Adt ( adt, substs) if adt. is_struct ( ) => {
426
422
// Consume those fields of the with expression that are needed.
427
423
for ( f_index, with_field) in adt. non_enum_variant ( ) . fields . iter ( ) . enumerate ( ) {
428
424
let is_mentioned = fields. iter ( ) . any ( |f| {
429
425
self . tcx ( ) . field_index ( f. hir_id , self . mc . tables ) == f_index
430
426
} ) ;
431
427
if !is_mentioned {
432
- let cmt_field = self . mc . cat_field (
428
+ let field_place = self . mc . cat_projection (
433
429
& * 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) ,
438
432
) ;
439
- self . delegate_consume ( & cmt_field ) ;
433
+ self . delegate_consume ( & field_place ) ;
440
434
}
441
435
}
442
436
}
@@ -522,8 +516,8 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> {
522
516
}
523
517
}
524
518
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 ) ;
527
521
528
522
if let Some ( hir:: Guard :: If ( ref e) ) = arm. guard {
529
523
self . consume_expr ( e)
@@ -534,22 +528,22 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> {
534
528
535
529
/// Walks a pat that occurs in isolation (i.e., top-level of fn argument or
536
530
/// 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) ;
539
533
}
540
534
541
535
542
536
/// 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) ;
545
539
546
540
let tcx = self . tcx ( ) ;
547
541
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| {
549
543
if let PatKind :: Binding ( _, canonical_id, ..) = pat. kind {
550
544
debug!(
551
- "walk_pat: binding cmt_pat ={:?} pat={:?}" ,
552
- cmt_pat ,
545
+ "walk_pat: binding place ={:?} pat={:?}" ,
546
+ place ,
553
547
pat,
554
548
) ;
555
549
if let Some ( & bm) = mc. tables. pat_binding_modes( ) . get( pat. hir_id) {
@@ -570,12 +564,12 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> {
570
564
match bm {
571
565
ty:: BindByReference ( m) => {
572
566
let bk = ty:: BorrowKind :: from_mutbl( m) ;
573
- delegate. borrow( & cmt_pat , bk) ;
567
+ delegate. borrow( place , bk) ;
574
568
}
575
569
ty:: BindByValue ( ..) => {
576
- let mode = copy_or_move( mc, & cmt_pat ) ;
570
+ let mode = copy_or_move( mc, place ) ;
577
571
debug!( "walk_pat binding consuming pat" ) ;
578
- delegate. consume( & cmt_pat , mode) ;
572
+ delegate. consume( place , mode) ;
579
573
}
580
574
}
581
575
} else {
0 commit comments