@@ -115,44 +115,56 @@ impl<'b, 'a, 'tcx> Gatherer<'b, 'a, 'tcx> {
115115 let body = self . builder . body ;
116116 let tcx = self . builder . tcx ;
117117 let place_ty = place_ref. ty ( body, tcx) . ty ;
118- match place_ty. kind ( ) {
119- ty:: Ref ( ..) | ty:: RawPtr ( ..) => {
120- return Err ( MoveError :: cannot_move_out_of (
121- self . loc ,
122- BorrowedContent { target_place : place_ref. project_deeper ( & [ elem] , tcx) } ,
123- ) ) ;
124- }
125- ty:: Adt ( adt, _) if adt. has_dtor ( tcx) && !adt. is_box ( ) => {
126- return Err ( MoveError :: cannot_move_out_of (
127- self . loc ,
128- InteriorOfTypeWithDestructor { container_ty : place_ty } ,
129- ) ) ;
130- }
131- ty:: Adt ( adt, _) if adt. is_union ( ) => {
132- union_path. get_or_insert ( base) ;
133- }
134- ty:: Slice ( _) => {
135- return Err ( MoveError :: cannot_move_out_of (
136- self . loc ,
137- InteriorOfSliceOrArray {
138- ty : place_ty,
139- is_index : matches ! ( elem, ProjectionElem :: Index ( ..) ) ,
140- } ,
141- ) ) ;
142- }
143-
144- ty:: Array ( ..) => {
145- if let ProjectionElem :: Index ( ..) = elem {
118+ match elem {
119+ ProjectionElem :: Deref => match place_ty. kind ( ) {
120+ ty:: Ref ( ..) | ty:: RawPtr ( ..) => {
146121 return Err ( MoveError :: cannot_move_out_of (
147122 self . loc ,
148- InteriorOfSliceOrArray { ty : place_ty, is_index : true } ,
123+ BorrowedContent {
124+ target_place : place_ref. project_deeper ( & [ elem] , tcx) ,
125+ } ,
149126 ) ) ;
150127 }
151- }
152-
153- _ => { }
154- } ;
128+ _ => ( ) ,
129+ } ,
130+ ProjectionElem :: Field ( _, _)
131+ | ProjectionElem :: OpaqueCast ( _)
132+ | ProjectionElem :: Downcast ( _, _) => match place_ty. kind ( ) {
133+ ty:: Adt ( adt, _) if adt. has_dtor ( tcx) && !adt. is_box ( ) => {
134+ return Err ( MoveError :: cannot_move_out_of (
135+ self . loc ,
136+ InteriorOfTypeWithDestructor { container_ty : place_ty } ,
137+ ) ) ;
138+ }
139+ ty:: Adt ( adt, _) if adt. is_union ( ) => {
140+ union_path. get_or_insert ( base) ;
141+ }
155142
143+ _ => ( ) ,
144+ } ,
145+ ProjectionElem :: ConstantIndex { .. }
146+ | ProjectionElem :: Index ( _)
147+ | ProjectionElem :: Subslice { .. } => match place_ty. kind ( ) {
148+ ty:: Slice ( _) => {
149+ return Err ( MoveError :: cannot_move_out_of (
150+ self . loc ,
151+ InteriorOfSliceOrArray {
152+ ty : place_ty,
153+ is_index : matches ! ( elem, ProjectionElem :: Index ( ..) ) ,
154+ } ,
155+ ) ) ;
156+ }
157+ ty:: Array ( ..) => {
158+ if let ProjectionElem :: Index ( ..) = elem {
159+ return Err ( MoveError :: cannot_move_out_of (
160+ self . loc ,
161+ InteriorOfSliceOrArray { ty : place_ty, is_index : true } ,
162+ ) ) ;
163+ }
164+ }
165+ _ => ( ) ,
166+ } ,
167+ }
156168 if union_path. is_none ( ) {
157169 // inlined from add_move_path because of a borrowck conflict with the iterator
158170 base =
0 commit comments