@@ -250,28 +250,29 @@ fn check_operand(
250
250
}
251
251
}
252
252
253
- fn check_place (
254
- place : & Place < ' tcx > ,
255
- span : Span ,
256
- ) -> McfResult {
257
- match place {
258
- Place :: Base ( PlaceBase :: Local ( _) ) => Ok ( ( ) ) ,
259
- // promoteds are always fine, they are essentially constants
260
- Place :: Base ( PlaceBase :: Static ( box Static { kind : StaticKind :: Promoted ( _) , .. } ) ) => Ok ( ( ) ) ,
261
- Place :: Base ( PlaceBase :: Static ( box Static { kind : StaticKind :: Static ( _) , .. } ) ) =>
262
- Err ( ( span, "cannot access `static` items in const fn" . into ( ) ) ) ,
263
- Place :: Projection ( proj) => {
253
+ fn check_place ( place : & Place < ' tcx > , span : Span ) -> McfResult {
254
+ place. iterate ( |place_base, place_projection| {
255
+ for proj in place_projection {
264
256
match proj. elem {
265
- | ProjectionElem :: ConstantIndex { .. } | ProjectionElem :: Subslice { .. }
266
- | ProjectionElem :: Deref | ProjectionElem :: Field ( ..) | ProjectionElem :: Index ( _) => {
267
- check_place ( & proj. base , span)
268
- }
269
- | ProjectionElem :: Downcast ( ..) => {
270
- Err ( ( span, "`match` or `if let` in `const fn` is unstable" . into ( ) ) )
257
+ ProjectionElem :: Downcast ( ..) => {
258
+ return Err ( ( span, "`match` or `if let` in `const fn` is unstable" . into ( ) ) ) ;
271
259
}
260
+ ProjectionElem :: ConstantIndex { .. }
261
+ | ProjectionElem :: Subslice { .. }
262
+ | ProjectionElem :: Deref
263
+ | ProjectionElem :: Field ( ..)
264
+ | ProjectionElem :: Index ( _) => { }
272
265
}
273
266
}
274
- }
267
+
268
+ match place_base {
269
+ PlaceBase :: Static ( box Static { kind : StaticKind :: Static ( _) , .. } ) => {
270
+ Err ( ( span, "cannot access `static` items in const fn" . into ( ) ) )
271
+ }
272
+ PlaceBase :: Local ( _)
273
+ | PlaceBase :: Static ( box Static { kind : StaticKind :: Promoted ( _) , .. } ) => Ok ( ( ) ) ,
274
+ }
275
+ } )
275
276
}
276
277
277
278
fn check_terminator (
0 commit comments