@@ -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} ;
@@ -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,12 +101,12 @@ 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) ;
103108 let Some ( mut base) = data. rev_lookup . find_local ( place. local ) else {
104- return Err ( MoveError :: UntrackedLocal ) ;
109+ return MovePathResult :: Error ;
105110 } ;
106111
107112 // 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> {
118123 match elem {
119124 ProjectionElem :: Deref => match place_ty. kind ( ) {
120125 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 ;
127127 }
128128 ty:: Adt ( adt, _) => {
129129 if !adt. is_box ( ) {
@@ -159,10 +159,7 @@ impl<'b, 'a, 'tcx> Gatherer<'b, 'a, 'tcx> {
159159 ProjectionElem :: Field ( _, _) => match place_ty. kind ( ) {
160160 ty:: Adt ( adt, _) => {
161161 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 ;
166163 }
167164 if adt. is_union ( ) {
168165 union_path. get_or_insert ( base) ;
@@ -197,33 +194,15 @@ impl<'b, 'a, 'tcx> Gatherer<'b, 'a, 'tcx> {
197194 ProjectionElem :: ConstantIndex { .. } | ProjectionElem :: Subslice { .. } => {
198195 match place_ty. kind ( ) {
199196 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 ;
207198 }
208199 ty:: Array ( _, _) => ( ) ,
209200 _ => bug ! ( "Unexpected type {:#?}" , place_ty. is_array( ) ) ,
210201 }
211202 }
212203 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 ;
227206 }
228207 _ => bug ! ( "Unexpected type {place_ty:#?}" ) ,
229208 } ,
@@ -252,9 +231,9 @@ impl<'b, 'a, 'tcx> Gatherer<'b, 'a, 'tcx> {
252231
253232 if let Some ( base) = union_path {
254233 // Move out of union - always move the entire union.
255- Err ( MoveError :: UnionMove { path : base } )
234+ MovePathResult :: Union ( base)
256235 } else {
257- Ok ( base)
236+ MovePathResult :: Path ( base)
258237 }
259238 }
260239
@@ -543,12 +522,14 @@ impl<'b, 'a, 'tcx> Gatherer<'b, 'a, 'tcx> {
543522 let base_place =
544523 Place { local : place. local , projection : self . builder . tcx . mk_place_elems ( base) } ;
545524 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) => {
548527 self . record_move ( place, path) ;
549528 return ;
550529 }
551- Err ( MoveError :: IllegalMove { .. } | MoveError :: UntrackedLocal ) => return ,
530+ MovePathResult :: Error => {
531+ return ;
532+ }
552533 } ;
553534 let base_ty = base_place. ty ( self . builder . body , self . builder . tcx ) . ty ;
554535 let len: u64 = match base_ty. kind ( ) {
@@ -566,8 +547,10 @@ impl<'b, 'a, 'tcx> Gatherer<'b, 'a, 'tcx> {
566547 }
567548 } else {
568549 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 => { }
571554 } ;
572555 }
573556 }
0 commit comments