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:
commit
fc2daaae61
76 changed files with 940 additions and 882 deletions
|
@ -151,17 +151,11 @@ fn is_promotable_const_fn(tcx: TyCtxt<'_>, def_id: DefId) -> bool {
|
|||
}
|
||||
}
|
||||
|
||||
fn const_fn_is_allowed_fn_ptr(tcx: TyCtxt<'_>, def_id: DefId) -> bool {
|
||||
is_const_fn(tcx, def_id)
|
||||
&& tcx.lookup_const_stability(def_id).map(|stab| stab.allow_const_fn_ptr).unwrap_or(false)
|
||||
}
|
||||
|
||||
pub fn provide(providers: &mut Providers) {
|
||||
*providers = Providers {
|
||||
is_const_fn_raw,
|
||||
is_const_impl_raw: |tcx, def_id| is_const_impl_raw(tcx, def_id.expect_local()),
|
||||
is_promotable_const_fn,
|
||||
const_fn_is_allowed_fn_ptr,
|
||||
..*providers
|
||||
};
|
||||
}
|
||||
|
|
|
@ -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()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue