Auto merge of #77302 - RalfJung:rollup-n8gg3v6, r=RalfJung
Rollup of 7 pull requests Successful merges: - #76454 (UI to unit test for those using Cell/RefCell/UnsafeCell) - #76474 (Add option to pass a custom codegen backend from a driver) - #76711 (diag: improve closure/generic parameter mismatch) - #77170 (Remove `#[rustc_allow_const_fn_ptr]` and add `#![feature(const_fn_fn_ptr_basics)]`) - #77194 (Add doc alias for iterator fold) - #77288 (fix building libstd for Miri on macOS) - #77295 (Update unstable-book: Fix ABNF in inline assembly docs) Failed merges: r? `@ghost`
This commit is contained in:
@@ -213,11 +213,21 @@ impl NonConstOp for FnPtrCast {
|
||||
const STOPS_CONST_CHECKING: bool = true;
|
||||
|
||||
fn status_in_item(&self, ccx: &ConstCx<'_, '_>) -> Status {
|
||||
mcf_status_in_item(ccx)
|
||||
if ccx.const_kind() != hir::ConstContext::ConstFn {
|
||||
Status::Allowed
|
||||
} else {
|
||||
Status::Unstable(sym::const_fn_fn_ptr_basics)
|
||||
}
|
||||
}
|
||||
|
||||
fn emit_error(&self, ccx: &ConstCx<'_, '_>, span: Span) {
|
||||
mcf_emit_error(ccx, span, "function pointer casts are not allowed in const fn");
|
||||
feature_err(
|
||||
&ccx.tcx.sess.parse_sess,
|
||||
sym::const_fn_fn_ptr_basics,
|
||||
span,
|
||||
&format!("function pointer casts are not allowed in {}s", ccx.const_kind()),
|
||||
)
|
||||
.emit()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -596,17 +606,21 @@ pub mod ty {
|
||||
const STOPS_CONST_CHECKING: bool = true;
|
||||
|
||||
fn status_in_item(&self, ccx: &ConstCx<'_, '_>) -> Status {
|
||||
// FIXME: This attribute a hack to allow the specialization of the `futures` API. See
|
||||
// #59739. We should have a proper feature gate for this.
|
||||
if ccx.tcx.has_attr(ccx.def_id.to_def_id(), sym::rustc_allow_const_fn_ptr) {
|
||||
if ccx.const_kind() != hir::ConstContext::ConstFn {
|
||||
Status::Allowed
|
||||
} else {
|
||||
mcf_status_in_item(ccx)
|
||||
Status::Unstable(sym::const_fn_fn_ptr_basics)
|
||||
}
|
||||
}
|
||||
|
||||
fn emit_error(&self, ccx: &ConstCx<'_, '_>, span: Span) {
|
||||
mcf_emit_error(ccx, span, "function pointers in const fn are unstable");
|
||||
feature_err(
|
||||
&ccx.tcx.sess.parse_sess,
|
||||
sym::const_fn_fn_ptr_basics,
|
||||
span,
|
||||
&format!("function pointers cannot appear in {}s", ccx.const_kind()),
|
||||
)
|
||||
.emit()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user