@@ -1740,20 +1740,18 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
1740
1740
1741
1741
self . check_if_full_path_is_moved ( location, desired_action, place_span, flow_state) ;
1742
1742
1743
- if let [ base_proj @ .. , ProjectionElem :: Subslice { from, to, from_end : false } ] =
1744
- place_span. 0 . projection
1743
+ if let Some ( ( place_base , ProjectionElem :: Subslice { from, to, from_end : false } ) ) =
1744
+ place_span. 0 . last_projection ( )
1745
1745
{
1746
- let place_ty =
1747
- Place :: ty_from ( place_span. 0 . local , base_proj, self . body ( ) , self . infcx . tcx ) ;
1746
+ let place_ty = PlaceRef :: ty ( & place_base, self . body ( ) , self . infcx . tcx ) ;
1748
1747
if let ty:: Array ( ..) = place_ty. ty . kind ( ) {
1749
- let array_place = PlaceRef { local : place_span. 0 . local , projection : base_proj } ;
1750
1748
self . check_if_subslice_element_is_moved (
1751
1749
location,
1752
1750
desired_action,
1753
- ( array_place , place_span. 1 ) ,
1751
+ ( place_base , place_span. 1 ) ,
1754
1752
maybe_uninits,
1755
- * from,
1756
- * to,
1753
+ from,
1754
+ to,
1757
1755
) ;
1758
1756
return ;
1759
1757
}
@@ -1825,10 +1823,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
1825
1823
debug ! ( "check_if_assigned_path_is_moved place: {:?}" , place) ;
1826
1824
1827
1825
// None case => assigning to `x` does not require `x` be initialized.
1828
- let mut cursor = & * place. projection . as_ref ( ) ;
1829
- while let [ proj_base @ .., elem] = cursor {
1830
- cursor = proj_base;
1831
-
1826
+ for ( place_base, elem) in place. iter_projections ( ) . rev ( ) {
1832
1827
match elem {
1833
1828
ProjectionElem :: Index ( _/*operand*/ ) |
1834
1829
ProjectionElem :: ConstantIndex { .. } |
@@ -1843,10 +1838,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
1843
1838
ProjectionElem :: Deref => {
1844
1839
self . check_if_full_path_is_moved (
1845
1840
location, InitializationRequiringAction :: Use ,
1846
- ( PlaceRef {
1847
- local : place. local ,
1848
- projection : proj_base,
1849
- } , span) , flow_state) ;
1841
+ ( place_base, span) , flow_state) ;
1850
1842
// (base initialized; no need to
1851
1843
// recur further)
1852
1844
break ;
@@ -1862,15 +1854,12 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
1862
1854
// assigning to `P.f` requires `P` itself
1863
1855
// be already initialized
1864
1856
let tcx = self . infcx . tcx ;
1865
- let base_ty = Place :: ty_from ( place . local , proj_base , self . body ( ) , tcx) . ty ;
1857
+ let base_ty = PlaceRef :: ty ( & place_base , self . body ( ) , tcx) . ty ;
1866
1858
match base_ty. kind ( ) {
1867
1859
ty:: Adt ( def, _) if def. has_dtor ( tcx) => {
1868
1860
self . check_if_path_or_subpath_is_moved (
1869
1861
location, InitializationRequiringAction :: Assignment ,
1870
- ( PlaceRef {
1871
- local : place. local ,
1872
- projection : proj_base,
1873
- } , span) , flow_state) ;
1862
+ ( place_base, span) , flow_state) ;
1874
1863
1875
1864
// (base initialized; no need to
1876
1865
// recur further)
@@ -1880,10 +1869,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
1880
1869
// Once `let s; s.x = V; read(s.x);`,
1881
1870
// is allowed, remove this match arm.
1882
1871
ty:: Adt ( ..) | ty:: Tuple ( ..) => {
1883
- check_parent_of_field ( self , location, PlaceRef {
1884
- local : place. local ,
1885
- projection : proj_base,
1886
- } , span, flow_state) ;
1872
+ check_parent_of_field ( self , location, place_base, span, flow_state) ;
1887
1873
1888
1874
// rust-lang/rust#21232, #54499, #54986: during period where we reject
1889
1875
// partial initialization, do not complain about unnecessary `mut` on
@@ -1965,9 +1951,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
1965
1951
// no move out from an earlier location) then this is an attempt at initialization
1966
1952
// of the union - we should error in that case.
1967
1953
let tcx = this. infcx . tcx ;
1968
- if let ty:: Adt ( def, _) =
1969
- Place :: ty_from ( base. local , base. projection , this. body ( ) , tcx) . ty . kind ( )
1970
- {
1954
+ if let ty:: Adt ( def, _) = PlaceRef :: ty ( & base, this. body ( ) , tcx) . ty . kind ( ) {
1971
1955
if def. is_union ( ) {
1972
1956
if this. move_data . path_map [ mpi] . iter ( ) . any ( |moi| {
1973
1957
this. move_data . moves [ * moi] . source . is_predecessor_of ( location, this. body )
@@ -2162,9 +2146,9 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
2162
2146
place : PlaceRef < ' tcx > ,
2163
2147
is_local_mutation_allowed : LocalMutationIsAllowed ,
2164
2148
) -> Result < RootPlace < ' tcx > , PlaceRef < ' tcx > > {
2165
- match place {
2166
- PlaceRef { local , projection : [ ] } => {
2167
- let local = & self . body . local_decls [ local] ;
2149
+ match place. last_projection ( ) {
2150
+ None => {
2151
+ let local = & self . body . local_decls [ place . local ] ;
2168
2152
match local. mutability {
2169
2153
Mutability :: Not => match is_local_mutation_allowed {
2170
2154
LocalMutationIsAllowed :: Yes => Ok ( RootPlace {
@@ -2186,11 +2170,10 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
2186
2170
} ) ,
2187
2171
}
2188
2172
}
2189
- PlaceRef { local : _ , projection : [ proj_base @ .. , elem] } => {
2173
+ Some ( ( place_base , elem) ) => {
2190
2174
match elem {
2191
2175
ProjectionElem :: Deref => {
2192
- let base_ty =
2193
- Place :: ty_from ( place. local , proj_base, self . body ( ) , self . infcx . tcx ) . ty ;
2176
+ let base_ty = PlaceRef :: ty ( & place_base, self . body ( ) , self . infcx . tcx ) . ty ;
2194
2177
2195
2178
// Check the kind of deref to decide
2196
2179
match base_ty. kind ( ) {
@@ -2208,10 +2191,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
2208
2191
_ => LocalMutationIsAllowed :: Yes ,
2209
2192
} ;
2210
2193
2211
- self . is_mutable (
2212
- PlaceRef { local : place. local , projection : proj_base } ,
2213
- mode,
2214
- )
2194
+ self . is_mutable ( place_base, mode)
2215
2195
}
2216
2196
}
2217
2197
}
@@ -2229,10 +2209,9 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
2229
2209
}
2230
2210
}
2231
2211
// `Box<T>` owns its content, so mutable if its location is mutable
2232
- _ if base_ty. is_box ( ) => self . is_mutable (
2233
- PlaceRef { local : place. local , projection : proj_base } ,
2234
- is_local_mutation_allowed,
2235
- ) ,
2212
+ _ if base_ty. is_box ( ) => {
2213
+ self . is_mutable ( place_base, is_local_mutation_allowed)
2214
+ }
2236
2215
// Deref should only be for reference, pointers or boxes
2237
2216
_ => bug ! ( "Deref of unexpected type: {:?}" , base_ty) ,
2238
2217
}
@@ -2286,10 +2265,8 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
2286
2265
// });
2287
2266
// }
2288
2267
// ```
2289
- let _ = self . is_mutable (
2290
- PlaceRef { local : place. local , projection : proj_base } ,
2291
- is_local_mutation_allowed,
2292
- ) ?;
2268
+ let _ =
2269
+ self . is_mutable ( place_base, is_local_mutation_allowed) ?;
2293
2270
Ok ( RootPlace {
2294
2271
place_local : place. local ,
2295
2272
place_projection : place. projection ,
@@ -2298,10 +2275,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
2298
2275
}
2299
2276
}
2300
2277
} else {
2301
- self . is_mutable (
2302
- PlaceRef { local : place. local , projection : proj_base } ,
2303
- is_local_mutation_allowed,
2304
- )
2278
+ self . is_mutable ( place_base, is_local_mutation_allowed)
2305
2279
}
2306
2280
}
2307
2281
}
0 commit comments