@@ -148,7 +148,7 @@ fn check_rvalue(
148148 Rvalue :: Len ( place) | Rvalue :: Discriminant ( place) | Rvalue :: Ref ( _, _, place) => {
149149 check_place ( tcx, mir, place, span, PlaceMode :: Read )
150150 }
151- Rvalue :: Cast ( _ , operand, cast_ty) => {
151+ Rvalue :: Cast ( CastKind :: Misc , operand, cast_ty) => {
152152 use rustc:: ty:: cast:: CastTy ;
153153 let cast_in = CastTy :: from_ty ( operand. ty ( mir, tcx) ) . expect ( "bad input type for cast" ) ;
154154 let cast_out = CastTy :: from_ty ( cast_ty) . expect ( "bad output type for cast" ) ;
@@ -163,6 +163,16 @@ fn check_rvalue(
163163 _ => check_operand ( tcx, mir, operand, span) ,
164164 }
165165 }
166+ Rvalue :: Cast ( CastKind :: UnsafeFnPointer , _, _) |
167+ Rvalue :: Cast ( CastKind :: ClosureFnPointer , _, _) |
168+ Rvalue :: Cast ( CastKind :: ReifyFnPointer , _, _) => Err ( (
169+ span,
170+ "function pointer casts are not allowed in const fn" . into ( ) ,
171+ ) ) ,
172+ Rvalue :: Cast ( CastKind :: Unsize , _, _) => Err ( (
173+ span,
174+ "unsizing casts are not allowed in const fn" . into ( ) ,
175+ ) ) ,
166176 // binops are fine on integers
167177 Rvalue :: BinaryOp ( _, lhs, rhs) | Rvalue :: CheckedBinaryOp ( _, lhs, rhs) => {
168178 check_operand ( tcx, mir, lhs, span) ?;
@@ -177,8 +187,11 @@ fn check_rvalue(
177187 ) )
178188 }
179189 }
180- // checked by regular const fn checks
181- Rvalue :: NullaryOp ( ..) => Ok ( ( ) ) ,
190+ Rvalue :: NullaryOp ( NullOp :: SizeOf , _) => Ok ( ( ) ) ,
191+ Rvalue :: NullaryOp ( NullOp :: Box , _) => Err ( (
192+ span,
193+ "heap allocations are not allowed in const fn" . into ( ) ,
194+ ) ) ,
182195 Rvalue :: UnaryOp ( _, operand) => {
183196 let ty = operand. ty ( mir, tcx) ;
184197 if ty. is_integral ( ) || ty. is_bool ( ) {
0 commit comments