@@ -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
} ;
@@ -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,12 +101,12 @@ 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
108
let Some ( mut base) = data. rev_lookup . find_local ( place. local ) else {
104
- return Err ( MoveError :: UntrackedLocal ) ;
109
+ return MovePathResult :: Error ;
105
110
} ;
106
111
107
112
// The move path index of the first union that we find. Once this is
@@ -118,12 +123,7 @@ impl<'b, 'a, 'tcx> Gatherer<'b, 'a, 'tcx> {
118
123
match elem {
119
124
ProjectionElem :: Deref => match place_ty. kind ( ) {
120
125
ty:: Ref ( ..) | ty:: RawPtr ( ..) => {
121
- return Err ( MoveError :: cannot_move_out_of (
122
- self . loc ,
123
- BorrowedContent {
124
- target_place : place_ref. project_deeper ( & [ elem] , tcx) ,
125
- } ,
126
- ) ) ;
126
+ return MovePathResult :: Error ;
127
127
}
128
128
ty:: Adt ( adt, _) => {
129
129
if !adt. is_box ( ) {
@@ -159,10 +159,7 @@ impl<'b, 'a, 'tcx> Gatherer<'b, 'a, 'tcx> {
159
159
ProjectionElem :: Field ( _, _) => match place_ty. kind ( ) {
160
160
ty:: Adt ( adt, _) => {
161
161
if adt. has_dtor ( tcx) {
162
- return Err ( MoveError :: cannot_move_out_of (
163
- self . loc ,
164
- InteriorOfTypeWithDestructor { container_ty : place_ty } ,
165
- ) ) ;
162
+ return MovePathResult :: Error ;
166
163
}
167
164
if adt. is_union ( ) {
168
165
union_path. get_or_insert ( base) ;
@@ -197,33 +194,15 @@ impl<'b, 'a, 'tcx> Gatherer<'b, 'a, 'tcx> {
197
194
ProjectionElem :: ConstantIndex { .. } | ProjectionElem :: Subslice { .. } => {
198
195
match place_ty. kind ( ) {
199
196
ty:: Slice ( _) => {
200
- return Err ( MoveError :: cannot_move_out_of (
201
- self . loc ,
202
- InteriorOfSliceOrArray {
203
- ty : place_ty,
204
- is_index : matches ! ( elem, ProjectionElem :: Index ( ..) ) ,
205
- } ,
206
- ) ) ;
197
+ return MovePathResult :: Error ;
207
198
}
208
199
ty:: Array ( _, _) => ( ) ,
209
200
_ => bug ! ( "Unexpected type {:#?}" , place_ty. is_array( ) ) ,
210
201
}
211
202
}
212
203
ProjectionElem :: Index ( _) => match place_ty. kind ( ) {
213
- ty:: Array ( ..) => {
214
- return Err ( MoveError :: cannot_move_out_of (
215
- self . loc ,
216
- InteriorOfSliceOrArray { ty : place_ty, is_index : true } ,
217
- ) ) ;
218
- }
219
- ty:: Slice ( _) => {
220
- return Err ( MoveError :: cannot_move_out_of (
221
- self . loc ,
222
- InteriorOfSliceOrArray {
223
- ty : place_ty,
224
- is_index : matches ! ( elem, ProjectionElem :: Index ( ..) ) ,
225
- } ,
226
- ) ) ;
204
+ ty:: Array ( ..) | ty:: Slice ( _) => {
205
+ return MovePathResult :: Error ;
227
206
}
228
207
_ => bug ! ( "Unexpected type {place_ty:#?}" ) ,
229
208
} ,
@@ -252,9 +231,9 @@ impl<'b, 'a, 'tcx> Gatherer<'b, 'a, 'tcx> {
252
231
253
232
if let Some ( base) = union_path {
254
233
// Move out of union - always move the entire union.
255
- Err ( MoveError :: UnionMove { path : base } )
234
+ MovePathResult :: Union ( base)
256
235
} else {
257
- Ok ( base)
236
+ MovePathResult :: Path ( base)
258
237
}
259
238
}
260
239
@@ -543,12 +522,14 @@ impl<'b, 'a, 'tcx> Gatherer<'b, 'a, 'tcx> {
543
522
let base_place =
544
523
Place { local : place. local , projection : self . builder . tcx . mk_place_elems ( base) } ;
545
524
let base_path = match self . move_path_for ( base_place) {
546
- Ok ( path) => path,
547
- Err ( MoveError :: UnionMove { path } ) => {
525
+ MovePathResult :: Path ( path) => path,
526
+ MovePathResult :: Union ( path) => {
548
527
self . record_move ( place, path) ;
549
528
return ;
550
529
}
551
- Err ( MoveError :: IllegalMove { .. } | MoveError :: UntrackedLocal ) => return ,
530
+ MovePathResult :: Error => {
531
+ return ;
532
+ }
552
533
} ;
553
534
let base_ty = base_place. ty ( self . builder . body , self . builder . tcx ) . ty ;
554
535
let len: u64 = match base_ty. kind ( ) {
@@ -566,8 +547,10 @@ impl<'b, 'a, 'tcx> Gatherer<'b, 'a, 'tcx> {
566
547
}
567
548
} else {
568
549
match self . move_path_for ( place) {
569
- Ok ( path) | Err ( MoveError :: UnionMove { path } ) => self . record_move ( place, path) ,
570
- Err ( MoveError :: IllegalMove { .. } | MoveError :: UntrackedLocal ) => { }
550
+ MovePathResult :: Path ( path) | MovePathResult :: Union ( path) => {
551
+ self . record_move ( place, path)
552
+ }
553
+ MovePathResult :: Error => { }
571
554
} ;
572
555
}
573
556
}
0 commit comments