@@ -250,28 +250,29 @@ fn check_operand(
250250 }
251251}
252252
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 {
264256 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 ( ) ) ) ;
271259 }
260+ ProjectionElem :: ConstantIndex { .. }
261+ | ProjectionElem :: Subslice { .. }
262+ | ProjectionElem :: Deref
263+ | ProjectionElem :: Field ( ..)
264+ | ProjectionElem :: Index ( _) => { }
272265 }
273266 }
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+ } )
275276}
276277
277278fn check_terminator (
0 commit comments