@@ -213,11 +213,21 @@ impl NonConstOp for FnPtrCast {
213213 const STOPS_CONST_CHECKING : bool = true ;
214214
215215 fn status_in_item ( & self , ccx : & ConstCx < ' _ , ' _ > ) -> Status {
216- mcf_status_in_item ( ccx)
216+ if ccx. const_kind ( ) != hir:: ConstContext :: ConstFn {
217+ Status :: Allowed
218+ } else {
219+ Status :: Unstable ( sym:: const_fn_fn_ptr_basics)
220+ }
217221 }
218222
219223 fn emit_error ( & self , ccx : & ConstCx < ' _ , ' _ > , span : Span ) {
220- mcf_emit_error ( ccx, span, "function pointer casts are not allowed in const fn" ) ;
224+ feature_err (
225+ & ccx. tcx . sess . parse_sess ,
226+ sym:: const_fn_fn_ptr_basics,
227+ span,
228+ & format ! ( "function pointer casts are not allowed in {}s" , ccx. const_kind( ) ) ,
229+ )
230+ . emit ( )
221231 }
222232}
223233
@@ -596,17 +606,21 @@ pub mod ty {
596606 const STOPS_CONST_CHECKING : bool = true ;
597607
598608 fn status_in_item ( & self , ccx : & ConstCx < ' _ , ' _ > ) -> Status {
599- // FIXME: This attribute a hack to allow the specialization of the `futures` API. See
600- // #59739. We should have a proper feature gate for this.
601- if ccx. tcx . has_attr ( ccx. def_id . to_def_id ( ) , sym:: rustc_allow_const_fn_ptr) {
609+ if ccx. const_kind ( ) != hir:: ConstContext :: ConstFn {
602610 Status :: Allowed
603611 } else {
604- mcf_status_in_item ( ccx )
612+ Status :: Unstable ( sym :: const_fn_fn_ptr_basics )
605613 }
606614 }
607615
608616 fn emit_error ( & self , ccx : & ConstCx < ' _ , ' _ > , span : Span ) {
609- mcf_emit_error ( ccx, span, "function pointers in const fn are unstable" ) ;
617+ feature_err (
618+ & ccx. tcx . sess . parse_sess ,
619+ sym:: const_fn_fn_ptr_basics,
620+ span,
621+ & format ! ( "function pointers cannot appear in {}s" , ccx. const_kind( ) ) ,
622+ )
623+ . emit ( )
610624 }
611625 }
612626
0 commit comments