@@ -7,8 +7,7 @@ use smallvec::{smallvec, SmallVec};
77use std:: mem;
88
99use 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 } ;
1211use super :: {
1312 LocationMap , MoveData , MoveOut , MoveOutIndex , MovePath , MovePathIndex , MovePathLookup ,
1413} ;
@@ -39,15 +38,15 @@ impl<'a, 'tcx> MoveDataBuilder<'a, 'tcx> {
3938 . iter_enumerated ( )
4039 . map ( |( i, l) | {
4140 if l. is_deref_temp ( ) {
42- MovePathIndex :: MAX
41+ None
4342 } else {
44- Self :: new_move_path (
43+ Some ( Self :: new_move_path (
4544 & mut move_paths,
4645 & mut path_map,
4746 & mut init_path_map,
4847 None ,
4948 Place :: from ( i) ,
50- )
49+ ) )
5150 }
5251 } )
5352 . collect ( ) ,
@@ -88,6 +87,12 @@ impl<'a, 'tcx> MoveDataBuilder<'a, 'tcx> {
8887 }
8988}
9089
90+ enum MovePathResult {
91+ Path ( MovePathIndex ) ,
92+ Union ( MovePathIndex ) ,
93+ Error ,
94+ }
95+
9196impl < ' b , ' a , ' tcx > Gatherer < ' b , ' a , ' tcx > {
9297 /// This creates a MovePath for a given place, returning an `MovePathError`
9398 /// if that place can't be moved from.
@@ -96,11 +101,13 @@ impl<'b, 'a, 'tcx> Gatherer<'b, 'a, 'tcx> {
96101 /// problematic for borrowck.
97102 ///
98103 /// 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 {
100105 let data = & mut self . builder . data ;
101106
102107 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+ } ;
104111
105112 // The move path index of the first union that we find. Once this is
106113 // some we stop creating child move paths, since moves from unions
@@ -116,12 +123,7 @@ impl<'b, 'a, 'tcx> Gatherer<'b, 'a, 'tcx> {
116123 match elem {
117124 ProjectionElem :: Deref => match place_ty. kind ( ) {
118125 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 ;
125127 }
126128 ty:: Adt ( adt, _) => {
127129 if !adt. is_box ( ) {
@@ -157,10 +159,7 @@ impl<'b, 'a, 'tcx> Gatherer<'b, 'a, 'tcx> {
157159 ProjectionElem :: Field ( _, _) => match place_ty. kind ( ) {
158160 ty:: Adt ( adt, _) => {
159161 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 ;
164163 }
165164 if adt. is_union ( ) {
166165 union_path. get_or_insert ( base) ;
@@ -195,33 +194,15 @@ impl<'b, 'a, 'tcx> Gatherer<'b, 'a, 'tcx> {
195194 ProjectionElem :: ConstantIndex { .. } | ProjectionElem :: Subslice { .. } => {
196195 match place_ty. kind ( ) {
197196 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 ;
205198 }
206199 ty:: Array ( _, _) => ( ) ,
207200 _ => bug ! ( "Unexpected type {:#?}" , place_ty. is_array( ) ) ,
208201 }
209202 }
210203 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 ;
225206 }
226207 _ => bug ! ( "Unexpected type {place_ty:#?}" ) ,
227208 } ,
@@ -247,9 +228,9 @@ impl<'b, 'a, 'tcx> Gatherer<'b, 'a, 'tcx> {
247228
248229 if let Some ( base) = union_path {
249230 // Move out of union - always move the entire union.
250- Err ( MoveError :: UnionMove { path : base } )
231+ MovePathResult :: Union ( base)
251232 } else {
252- Ok ( base)
233+ MovePathResult :: Path ( base)
253234 }
254235 }
255236
@@ -325,17 +306,17 @@ pub(super) fn gather_moves<'tcx>(
325306impl < ' a , ' tcx > MoveDataBuilder < ' a , ' tcx > {
326307 fn gather_args ( & mut self ) {
327308 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+ } ) ;
335315
336- debug ! ( "gather_args: adding init {:?} of {:?} for argument {:?}" , init, path, arg) ;
316+ debug ! ( "gather_args: adding init {:?} of {:?} for argument {:?}" , init, path, arg) ;
337317
338- self . data . init_path_map [ path] . push ( init) ;
318+ self . data . init_path_map [ path] . push ( init) ;
319+ }
339320 }
340321 }
341322
@@ -538,12 +519,12 @@ impl<'b, 'a, 'tcx> Gatherer<'b, 'a, 'tcx> {
538519 let base_place =
539520 Place { local : place. local , projection : self . builder . tcx . mk_place_elems ( base) } ;
540521 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) => {
543524 self . record_move ( place, path) ;
544525 return ;
545526 }
546- Err ( MoveError :: IllegalMove { .. } ) => {
527+ MovePathResult :: Error => {
547528 return ;
548529 }
549530 } ;
@@ -563,8 +544,10 @@ impl<'b, 'a, 'tcx> Gatherer<'b, 'a, 'tcx> {
563544 }
564545 } else {
565546 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 => { }
568551 } ;
569552 }
570553 }
0 commit comments