@@ -7,8 +7,7 @@ use smallvec::{smallvec, SmallVec};
7
7
use std:: mem;
8
8
9
9
use super :: abs_domain:: Lift ;
10
- use super :: IllegalMoveOriginKind :: * ;
11
- use super :: { Init , InitIndex , InitKind , InitLocation , LookupResult , MoveError } ;
10
+ use super :: { Init , InitIndex , InitKind , InitLocation , LookupResult } ;
12
11
use super :: {
13
12
LocationMap , MoveData , MoveOut , MoveOutIndex , MovePath , MovePathIndex , MovePathLookup ,
14
13
} ;
@@ -39,15 +38,15 @@ impl<'a, 'tcx> MoveDataBuilder<'a, 'tcx> {
39
38
. iter_enumerated ( )
40
39
. map ( |( i, l) | {
41
40
if l. is_deref_temp ( ) {
42
- MovePathIndex :: MAX
41
+ None
43
42
} else {
44
- Self :: new_move_path (
43
+ Some ( Self :: new_move_path (
45
44
& mut move_paths,
46
45
& mut path_map,
47
46
& mut init_path_map,
48
47
None ,
49
48
Place :: from ( i) ,
50
- )
49
+ ) )
51
50
}
52
51
} )
53
52
. collect ( ) ,
@@ -88,6 +87,12 @@ impl<'a, 'tcx> MoveDataBuilder<'a, 'tcx> {
88
87
}
89
88
}
90
89
90
+ enum MovePathResult {
91
+ Path ( MovePathIndex ) ,
92
+ Union ( MovePathIndex ) ,
93
+ Error ,
94
+ }
95
+
91
96
impl < ' b , ' a , ' tcx > Gatherer < ' b , ' a , ' tcx > {
92
97
/// This creates a MovePath for a given place, returning an `MovePathError`
93
98
/// if that place can't be moved from.
@@ -96,11 +101,13 @@ impl<'b, 'a, 'tcx> Gatherer<'b, 'a, 'tcx> {
96
101
/// problematic for borrowck.
97
102
///
98
103
/// Maybe we should have separate "borrowck" and "moveck" modes.
99
- fn move_path_for ( & mut self , place : Place < ' tcx > ) -> Result < MovePathIndex , MoveError < ' tcx > > {
104
+ fn move_path_for ( & mut self , place : Place < ' tcx > ) -> MovePathResult {
100
105
let data = & mut self . builder . data ;
101
106
102
107
debug ! ( "lookup({:?})" , place) ;
103
- let mut base = data. rev_lookup . find_local ( place. local ) ;
108
+ let Some ( mut base) = data. rev_lookup . find_local ( place. local ) else {
109
+ return MovePathResult :: Error ;
110
+ } ;
104
111
105
112
// The move path index of the first union that we find. Once this is
106
113
// some we stop creating child move paths, since moves from unions
@@ -116,12 +123,7 @@ impl<'b, 'a, 'tcx> Gatherer<'b, 'a, 'tcx> {
116
123
match elem {
117
124
ProjectionElem :: Deref => match place_ty. kind ( ) {
118
125
ty:: Ref ( ..) | ty:: RawPtr ( ..) => {
119
- return Err ( MoveError :: cannot_move_out_of (
120
- self . loc ,
121
- BorrowedContent {
122
- target_place : place_ref. project_deeper ( & [ elem] , tcx) ,
123
- } ,
124
- ) ) ;
126
+ return MovePathResult :: Error ;
125
127
}
126
128
ty:: Adt ( adt, _) => {
127
129
if !adt. is_box ( ) {
@@ -157,10 +159,7 @@ impl<'b, 'a, 'tcx> Gatherer<'b, 'a, 'tcx> {
157
159
ProjectionElem :: Field ( _, _) => match place_ty. kind ( ) {
158
160
ty:: Adt ( adt, _) => {
159
161
if adt. has_dtor ( tcx) {
160
- return Err ( MoveError :: cannot_move_out_of (
161
- self . loc ,
162
- InteriorOfTypeWithDestructor { container_ty : place_ty } ,
163
- ) ) ;
162
+ return MovePathResult :: Error ;
164
163
}
165
164
if adt. is_union ( ) {
166
165
union_path. get_or_insert ( base) ;
@@ -195,33 +194,15 @@ impl<'b, 'a, 'tcx> Gatherer<'b, 'a, 'tcx> {
195
194
ProjectionElem :: ConstantIndex { .. } | ProjectionElem :: Subslice { .. } => {
196
195
match place_ty. kind ( ) {
197
196
ty:: Slice ( _) => {
198
- return Err ( MoveError :: cannot_move_out_of (
199
- self . loc ,
200
- InteriorOfSliceOrArray {
201
- ty : place_ty,
202
- is_index : matches ! ( elem, ProjectionElem :: Index ( ..) ) ,
203
- } ,
204
- ) ) ;
197
+ return MovePathResult :: Error ;
205
198
}
206
199
ty:: Array ( _, _) => ( ) ,
207
200
_ => bug ! ( "Unexpected type {:#?}" , place_ty. is_array( ) ) ,
208
201
}
209
202
}
210
203
ProjectionElem :: Index ( _) => match place_ty. kind ( ) {
211
- ty:: Array ( ..) => {
212
- return Err ( MoveError :: cannot_move_out_of (
213
- self . loc ,
214
- InteriorOfSliceOrArray { ty : place_ty, is_index : true } ,
215
- ) ) ;
216
- }
217
- ty:: Slice ( _) => {
218
- return Err ( MoveError :: cannot_move_out_of (
219
- self . loc ,
220
- InteriorOfSliceOrArray {
221
- ty : place_ty,
222
- is_index : matches ! ( elem, ProjectionElem :: Index ( ..) ) ,
223
- } ,
224
- ) ) ;
204
+ ty:: Array ( ..) | ty:: Slice ( _) => {
205
+ return MovePathResult :: Error ;
225
206
}
226
207
_ => bug ! ( "Unexpected type {place_ty:#?}" ) ,
227
208
} ,
@@ -247,9 +228,9 @@ impl<'b, 'a, 'tcx> Gatherer<'b, 'a, 'tcx> {
247
228
248
229
if let Some ( base) = union_path {
249
230
// Move out of union - always move the entire union.
250
- Err ( MoveError :: UnionMove { path : base } )
231
+ MovePathResult :: Union ( base)
251
232
} else {
252
- Ok ( base)
233
+ MovePathResult :: Path ( base)
253
234
}
254
235
}
255
236
@@ -325,17 +306,17 @@ pub(super) fn gather_moves<'tcx>(
325
306
impl < ' a , ' tcx > MoveDataBuilder < ' a , ' tcx > {
326
307
fn gather_args ( & mut self ) {
327
308
for arg in self . body . args_iter ( ) {
328
- let path = self . data . rev_lookup . find_local ( arg) ;
329
-
330
- let init = self . data . inits . push ( Init {
331
- path,
332
- kind : InitKind :: Deep ,
333
- location : InitLocation :: Argument ( arg) ,
334
- } ) ;
309
+ if let Some ( path) = self . data . rev_lookup . find_local ( arg) {
310
+ let init = self . data . inits . push ( Init {
311
+ path,
312
+ kind : InitKind :: Deep ,
313
+ location : InitLocation :: Argument ( arg) ,
314
+ } ) ;
335
315
336
- debug ! ( "gather_args: adding init {:?} of {:?} for argument {:?}" , init, path, arg) ;
316
+ debug ! ( "gather_args: adding init {:?} of {:?} for argument {:?}" , init, path, arg) ;
337
317
338
- self . data . init_path_map [ path] . push ( init) ;
318
+ self . data . init_path_map [ path] . push ( init) ;
319
+ }
339
320
}
340
321
}
341
322
@@ -538,12 +519,12 @@ impl<'b, 'a, 'tcx> Gatherer<'b, 'a, 'tcx> {
538
519
let base_place =
539
520
Place { local : place. local , projection : self . builder . tcx . mk_place_elems ( base) } ;
540
521
let base_path = match self . move_path_for ( base_place) {
541
- Ok ( path) => path,
542
- Err ( MoveError :: UnionMove { path } ) => {
522
+ MovePathResult :: Path ( path) => path,
523
+ MovePathResult :: Union ( path) => {
543
524
self . record_move ( place, path) ;
544
525
return ;
545
526
}
546
- Err ( MoveError :: IllegalMove { .. } ) => {
527
+ MovePathResult :: Error => {
547
528
return ;
548
529
}
549
530
} ;
@@ -563,8 +544,10 @@ impl<'b, 'a, 'tcx> Gatherer<'b, 'a, 'tcx> {
563
544
}
564
545
} else {
565
546
match self . move_path_for ( place) {
566
- Ok ( path) | Err ( MoveError :: UnionMove { path } ) => self . record_move ( place, path) ,
567
- Err ( MoveError :: IllegalMove { .. } ) => { }
547
+ MovePathResult :: Path ( path) | MovePathResult :: Union ( path) => {
548
+ self . record_move ( place, path)
549
+ }
550
+ MovePathResult :: Error => { }
568
551
} ;
569
552
}
570
553
}
0 commit comments