5
5
pub use self :: ConsumeMode :: * ;
6
6
7
7
// Export these here so that Clippy can use them.
8
- pub use mc:: { Place , PlaceBase , Projection } ;
8
+ pub use mc:: { PlaceBase , PlaceWithHirId , Projection } ;
9
9
10
10
use rustc_hir as hir;
11
11
use rustc_hir:: def:: Res ;
@@ -25,13 +25,13 @@ use rustc_span::Span;
25
25
pub trait Delegate < ' tcx > {
26
26
// The value found at `place` is either copied or moved, depending
27
27
// 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 ) ;
29
29
30
30
// 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 ) ;
32
32
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 > ) ;
35
35
}
36
36
37
37
#[ derive( Copy , Clone , PartialEq , Debug ) ]
@@ -113,11 +113,11 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> {
113
113
self . mc . tcx ( )
114
114
}
115
115
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 ) ;
118
118
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) ;
121
121
}
122
122
123
123
fn consume_exprs ( & mut self , exprs : & [ hir:: Expr < ' _ > ] ) {
@@ -129,22 +129,22 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> {
129
129
pub fn consume_expr ( & mut self , expr : & hir:: Expr < ' _ > ) {
130
130
debug ! ( "consume_expr(expr={:?})" , expr) ;
131
131
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 ) ;
134
134
self . walk_expr ( expr) ;
135
135
}
136
136
137
137
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 ) ;
140
140
self . walk_expr ( expr) ;
141
141
}
142
142
143
143
fn borrow_expr ( & mut self , expr : & hir:: Expr < ' _ > , bk : ty:: BorrowKind ) {
144
144
debug ! ( "borrow_expr(expr={:?}, bk={:?})" , expr, bk) ;
145
145
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) ;
148
148
149
149
self . walk_expr ( expr)
150
150
}
@@ -384,7 +384,7 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> {
384
384
385
385
// Select just those fields of the `with`
386
386
// expression that will actually be used
387
- match with_place. ty . kind {
387
+ match with_place. place . ty . kind {
388
388
ty:: Adt ( adt, substs) if adt. is_struct ( ) => {
389
389
// Consume those fields of the with expression that are needed.
390
390
for ( f_index, with_field) in adt. non_enum_variant ( ) . fields . iter ( ) . enumerate ( ) {
@@ -422,14 +422,14 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> {
422
422
// process.
423
423
fn walk_adjustment ( & mut self , expr : & hir:: Expr < ' _ > ) {
424
424
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) ) ;
426
426
for adjustment in adjustments {
427
427
debug ! ( "walk_adjustment expr={:?} adj={:?}" , expr, adjustment) ;
428
428
match adjustment. kind {
429
429
adjustment:: Adjust :: NeverToAny | adjustment:: Adjust :: Pointer ( _) => {
430
430
// Creating a closure/fn-pointer or unsizing consumes
431
431
// the input and stores it into the resulting rvalue.
432
- self . delegate_consume ( & place ) ;
432
+ self . delegate_consume ( & place_with_id ) ;
433
433
}
434
434
435
435
adjustment:: Adjust :: Deref ( None ) => { }
@@ -441,14 +441,15 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> {
441
441
// this is an autoref of `x`.
442
442
adjustment:: Adjust :: Deref ( Some ( ref deref) ) => {
443
443
let bk = ty:: BorrowKind :: from_mutbl ( deref. mutbl ) ;
444
- self . delegate . borrow ( & place , bk) ;
444
+ self . delegate . borrow ( & place_with_id , bk) ;
445
445
}
446
446
447
447
adjustment:: Adjust :: Borrow ( ref autoref) => {
448
- self . walk_autoref ( expr, & place , autoref) ;
448
+ self . walk_autoref ( expr, & place_with_id , autoref) ;
449
449
}
450
450
}
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) ) ;
452
453
}
453
454
}
454
455
@@ -458,7 +459,7 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> {
458
459
fn walk_autoref (
459
460
& mut self ,
460
461
expr : & hir:: Expr < ' _ > ,
461
- base_place : & mc:: Place < ' tcx > ,
462
+ base_place : & mc:: PlaceWithHirId < ' tcx > ,
462
463
autoref : & adjustment:: AutoBorrow < ' tcx > ,
463
464
) {
464
465
debug ! (
@@ -479,7 +480,7 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> {
479
480
}
480
481
}
481
482
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 < ' _ > ) {
483
484
self . walk_pat ( discr_place, & arm. pat ) ;
484
485
485
486
if let Some ( hir:: Guard :: If ( ref e) ) = arm. guard {
@@ -491,12 +492,12 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> {
491
492
492
493
/// Walks a pat that occurs in isolation (i.e., top-level of fn argument or
493
494
/// 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 < ' _ > ) {
495
496
self . walk_pat ( discr_place, pat) ;
496
497
}
497
498
498
499
/// 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 < ' _ > ) {
500
501
debug ! ( "walk_pat(discr_place={:?}, pat={:?})" , discr_place, pat) ;
501
502
502
503
let tcx = self . tcx ( ) ;
@@ -569,7 +570,7 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> {
569
570
closure_hir_id : hir:: HirId ,
570
571
closure_span : Span ,
571
572
var_id : hir:: HirId ,
572
- ) -> mc:: McResult < mc:: Place < ' tcx > > {
573
+ ) -> mc:: McResult < mc:: PlaceWithHirId < ' tcx > > {
573
574
// Create the place for the variable being borrowed, from the
574
575
// perspective of the creator (parent) of the closure.
575
576
let var_ty = self . mc . node_ty ( var_id) ?;
@@ -579,7 +580,14 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> {
579
580
580
581
fn copy_or_move < ' a , ' tcx > (
581
582
mc : & mc:: MemCategorizationContext < ' a , ' tcx > ,
582
- place : & Place < ' tcx > ,
583
+ place_with_id : & PlaceWithHirId < ' tcx > ,
583
584
) -> 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
+ }
585
593
}
0 commit comments