@@ -2,7 +2,7 @@ use rustc::hir;
2
2
use rustc:: hir:: def_id:: DefId ;
3
3
use rustc:: mir:: {
4
4
self , AggregateKind , BindingForm , BorrowKind , ClearCrossCrate , ConstraintCategory , Local ,
5
- LocalDecl , LocalKind , Location , Operand , Place , PlaceBase , Projection ,
5
+ LocalDecl , LocalKind , Location , Operand , Place , PlaceBase , Projection , PlaceRef ,
6
6
ProjectionElem , Rvalue , Statement , StatementKind , TerminatorKind , VarBindingForm ,
7
7
} ;
8
8
use rustc:: ty:: { self , Ty } ;
@@ -48,7 +48,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
48
48
& mut self ,
49
49
location : Location ,
50
50
desired_action : InitializationRequiringAction ,
51
- ( moved_place, used_place, span) : ( & Place < ' tcx > , & Place < ' tcx > , Span ) ,
51
+ ( moved_place, used_place, span) : ( PlaceRef < ' cx , ' tcx > , PlaceRef < ' cx , ' tcx > , Span ) ,
52
52
mpi : MovePathIndex ,
53
53
) {
54
54
debug ! (
@@ -73,25 +73,19 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
73
73
74
74
if move_out_indices. is_empty ( ) {
75
75
let root_place = self
76
- . prefixes ( & used_place. base , & used_place . projection , PrefixSet :: All )
76
+ . prefixes ( used_place, PrefixSet :: All )
77
77
. last ( )
78
78
. unwrap ( ) ;
79
79
80
- if self . uninitialized_error_reported . contains ( & Place {
81
- base : root_place. 0 . clone ( ) ,
82
- projection : root_place. 1 . clone ( ) ,
83
- } ) {
80
+ if self . uninitialized_error_reported . contains ( & root_place) {
84
81
debug ! (
85
82
"report_use_of_moved_or_uninitialized place: error about {:?} suppressed" ,
86
83
root_place
87
84
) ;
88
85
return ;
89
86
}
90
87
91
- self . uninitialized_error_reported . insert ( Place {
92
- base : root_place. 0 . clone ( ) ,
93
- projection : root_place. 1 . clone ( ) ,
94
- } ) ;
88
+ self . uninitialized_error_reported . insert ( root_place) ;
95
89
96
90
let item_msg = match self . describe_place_with_options ( used_place,
97
91
IncludingDowncast ( true ) ) {
@@ -114,8 +108,8 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
114
108
err. buffer ( & mut self . errors_buffer ) ;
115
109
} else {
116
110
if let Some ( ( reported_place, _) ) = self . move_error_reported . get ( & move_out_indices) {
117
- if self . prefixes ( & reported_place. base , & reported_place . projection , PrefixSet :: All )
118
- . any ( |p| * p . 0 == used_place. base && * p . 1 == used_place . projection )
111
+ if self . prefixes ( * reported_place, PrefixSet :: All )
112
+ . any ( |p| p == used_place)
119
113
{
120
114
debug ! (
121
115
"report_use_of_moved_or_uninitialized place: error suppressed \
@@ -132,7 +126,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
132
126
span,
133
127
desired_action. as_noun ( ) ,
134
128
msg,
135
- self . describe_place_with_options ( & moved_place, IncludingDowncast ( true ) ) ,
129
+ self . describe_place_with_options ( moved_place, IncludingDowncast ( true ) ) ,
136
130
) ;
137
131
138
132
self . add_moved_or_invoked_closure_note (
@@ -145,13 +139,14 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
145
139
let is_partial_move = move_site_vec. iter ( ) . any ( |move_site| {
146
140
let move_out = self . move_data . moves [ ( * move_site) . moi ] ;
147
141
let moved_place = & self . move_data . move_paths [ move_out. path ] . place ;
148
- used_place != moved_place && used_place. is_prefix_of ( moved_place)
142
+ used_place != moved_place. as_place_ref ( )
143
+ && used_place. is_prefix_of ( moved_place. as_place_ref ( ) )
149
144
} ) ;
150
145
for move_site in & move_site_vec {
151
146
let move_out = self . move_data . moves [ ( * move_site) . moi ] ;
152
147
let moved_place = & self . move_data . move_paths [ move_out. path ] . place ;
153
148
154
- let move_spans = self . move_spans ( moved_place, move_out. source ) ;
149
+ let move_spans = self . move_spans ( moved_place. as_place_ref ( ) , move_out. source ) ;
155
150
let move_span = move_spans. args_or_use ( ) ;
156
151
157
152
let move_msg = if move_spans. for_closure ( ) {
@@ -209,7 +204,9 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
209
204
) ;
210
205
}
211
206
212
- let ty = used_place. ty ( self . body , self . infcx . tcx ) . ty ;
207
+ let ty =
208
+ Place :: ty_from ( used_place. base , used_place. projection , self . body , self . infcx . tcx )
209
+ . ty ;
213
210
let needs_note = match ty. sty {
214
211
ty:: Closure ( id, _) => {
215
212
let tables = self . infcx . tcx . typeck_tables_of ( id) ;
@@ -225,7 +222,8 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
225
222
let place = & self . move_data . move_paths [ mpi] . place ;
226
223
227
224
let ty = place. ty ( self . body , self . infcx . tcx ) . ty ;
228
- let opt_name = self . describe_place_with_options ( place, IncludingDowncast ( true ) ) ;
225
+ let opt_name =
226
+ self . describe_place_with_options ( place. as_place_ref ( ) , IncludingDowncast ( true ) ) ;
229
227
let note_msg = match opt_name {
230
228
Some ( ref name) => format ! ( "`{}`" , name) ,
231
229
None => "value" . to_owned ( ) ,
@@ -259,7 +257,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
259
257
}
260
258
261
259
if let Some ( ( _, mut old_err) ) = self . move_error_reported
262
- . insert ( move_out_indices, ( used_place. clone ( ) , err) )
260
+ . insert ( move_out_indices, ( used_place, err) )
263
261
{
264
262
// Cancel the old error so it doesn't ICE.
265
263
old_err. cancel ( ) ;
@@ -289,7 +287,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
289
287
let borrow_spans = self . retrieve_borrow_spans ( borrow) ;
290
288
let borrow_span = borrow_spans. args_or_use ( ) ;
291
289
292
- let move_spans = self . move_spans ( place, location) ;
290
+ let move_spans = self . move_spans ( place. as_place_ref ( ) , location) ;
293
291
let span = move_spans. args_or_use ( ) ;
294
292
295
293
let mut err = self . cannot_move_when_borrowed (
@@ -328,7 +326,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
328
326
329
327
// Conflicting borrows are reported separately, so only check for move
330
328
// captures.
331
- let use_spans = self . move_spans ( place, location) ;
329
+ let use_spans = self . move_spans ( place. as_place_ref ( ) , location) ;
332
330
let span = use_spans. var_or_use ( ) ;
333
331
334
332
let mut err = self . cannot_use_when_mutably_borrowed (
@@ -698,25 +696,23 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
698
696
) ;
699
697
700
698
let drop_span = place_span. 1 ;
701
- let root_place = self . prefixes ( & borrow. borrowed_place . base ,
702
- & borrow. borrowed_place . projection ,
703
- PrefixSet :: All )
699
+ let root_place = self . prefixes ( borrow. borrowed_place . as_place_ref ( ) , PrefixSet :: All )
704
700
. last ( )
705
701
. unwrap ( ) ;
706
702
707
703
let borrow_spans = self . retrieve_borrow_spans ( borrow) ;
708
704
let borrow_span = borrow_spans. var_or_use ( ) ;
709
705
710
- assert ! ( root_place. 1 . is_none( ) ) ;
711
- let proper_span = match root_place. 0 {
706
+ assert ! ( root_place. projection . is_none( ) ) ;
707
+ let proper_span = match root_place. base {
712
708
PlaceBase :: Local ( local) => self . body . local_decls [ * local] . source_info . span ,
713
709
_ => drop_span,
714
710
} ;
715
711
716
712
if self . access_place_error_reported
717
713
. contains ( & ( Place {
718
- base : root_place. 0 . clone ( ) ,
719
- projection : root_place. 1 . clone ( ) ,
714
+ base : root_place. base . clone ( ) ,
715
+ projection : root_place. projection . clone ( ) ,
720
716
} , borrow_span) )
721
717
{
722
718
debug ! (
@@ -728,8 +724,8 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
728
724
729
725
self . access_place_error_reported
730
726
. insert ( ( Place {
731
- base : root_place. 0 . clone ( ) ,
732
- projection : root_place. 1 . clone ( ) ,
727
+ base : root_place. base . clone ( ) ,
728
+ projection : root_place. projection . clone ( ) ,
733
729
} , borrow_span) ) ;
734
730
735
731
if let StorageDeadOrDrop :: Destructor ( dropped_ty) =
@@ -739,7 +735,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
739
735
// we're not in the uninteresting case where `B` is a
740
736
// prefix of `D`), then report this as a more interesting
741
737
// destructor conflict.
742
- if !borrow. borrowed_place . is_prefix_of ( place_span. 0 ) {
738
+ if !borrow. borrowed_place . as_place_ref ( ) . is_prefix_of ( place_span. 0 . as_place_ref ( ) ) {
743
739
self . report_borrow_conflicts_with_destructor (
744
740
location, borrow, place_span, kind, dropped_ty,
745
741
) ;
@@ -753,10 +749,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
753
749
let explanation = self . explain_why_borrow_contains_point ( location, & borrow, kind_place) ;
754
750
755
751
let err = match ( place_desc, explanation) {
756
- ( Some ( _) , _) if self . is_place_thread_local ( & Place {
757
- base : root_place. 0 . clone ( ) ,
758
- projection : root_place. 1 . clone ( ) ,
759
- } ) => {
752
+ ( Some ( _) , _) if self . is_place_thread_local ( root_place) => {
760
753
self . report_thread_local_value_does_not_live_long_enough ( drop_span, borrow_span)
761
754
}
762
755
// If the outlives constraint comes from inside the closure,
@@ -1133,12 +1126,14 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
1133
1126
format ! ( "`{}` is borrowed here" , place_desc) ,
1134
1127
)
1135
1128
} else {
1136
- let root_place = self . prefixes ( & borrow. borrowed_place . base ,
1137
- & borrow. borrowed_place . projection ,
1129
+ let root_place = self . prefixes ( borrow. borrowed_place . as_place_ref ( ) ,
1138
1130
PrefixSet :: All )
1139
1131
. last ( )
1140
1132
. unwrap ( ) ;
1141
- let local = if let ( PlaceBase :: Local ( local) , None ) = root_place {
1133
+ let local = if let PlaceRef {
1134
+ base : PlaceBase :: Local ( local) ,
1135
+ projection : None ,
1136
+ } = root_place {
1142
1137
local
1143
1138
} else {
1144
1139
bug ! ( "try_report_cannot_return_reference_to_local: not a local" )
0 commit comments