Remove `rustc_allow_const_fn_ptr`
This was a hack to work around the lack of an escape hatch for the "min `const fn`" checks in const-stable functions. Now that we have co-opted `allow_internal_unstable` for this purpose, we no longer need the bespoke attribute.
This commit is contained in:
parent
1ff143191c
commit
3cbd17fcc6
|
@ -145,8 +145,6 @@ pub struct ConstStability {
|
||||||
pub feature: Symbol,
|
pub feature: Symbol,
|
||||||
/// whether the function has a `#[rustc_promotable]` attribute
|
/// whether the function has a `#[rustc_promotable]` attribute
|
||||||
pub promotable: bool,
|
pub promotable: bool,
|
||||||
/// whether the function has a `#[rustc_allow_const_fn_ptr]` attribute
|
|
||||||
pub allow_const_fn_ptr: bool,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The available stability levels.
|
/// The available stability levels.
|
||||||
|
@ -190,7 +188,6 @@ where
|
||||||
let mut stab: Option<Stability> = None;
|
let mut stab: Option<Stability> = None;
|
||||||
let mut const_stab: Option<ConstStability> = None;
|
let mut const_stab: Option<ConstStability> = None;
|
||||||
let mut promotable = false;
|
let mut promotable = false;
|
||||||
let mut allow_const_fn_ptr = false;
|
|
||||||
let diagnostic = &sess.parse_sess.span_diagnostic;
|
let diagnostic = &sess.parse_sess.span_diagnostic;
|
||||||
|
|
||||||
'outer: for attr in attrs_iter {
|
'outer: for attr in attrs_iter {
|
||||||
|
@ -200,7 +197,6 @@ where
|
||||||
sym::unstable,
|
sym::unstable,
|
||||||
sym::stable,
|
sym::stable,
|
||||||
sym::rustc_promotable,
|
sym::rustc_promotable,
|
||||||
sym::rustc_allow_const_fn_ptr,
|
|
||||||
]
|
]
|
||||||
.iter()
|
.iter()
|
||||||
.any(|&s| attr.has_name(s))
|
.any(|&s| attr.has_name(s))
|
||||||
|
@ -215,9 +211,6 @@ where
|
||||||
if attr.has_name(sym::rustc_promotable) {
|
if attr.has_name(sym::rustc_promotable) {
|
||||||
promotable = true;
|
promotable = true;
|
||||||
}
|
}
|
||||||
if attr.has_name(sym::rustc_allow_const_fn_ptr) {
|
|
||||||
allow_const_fn_ptr = true;
|
|
||||||
}
|
|
||||||
// attributes with data
|
// attributes with data
|
||||||
else if let Some(MetaItem { kind: MetaItemKind::List(ref metas), .. }) = meta {
|
else if let Some(MetaItem { kind: MetaItemKind::List(ref metas), .. }) = meta {
|
||||||
let meta = meta.as_ref().unwrap();
|
let meta = meta.as_ref().unwrap();
|
||||||
|
@ -360,12 +353,8 @@ where
|
||||||
if sym::unstable == meta_name {
|
if sym::unstable == meta_name {
|
||||||
stab = Some(Stability { level, feature });
|
stab = Some(Stability { level, feature });
|
||||||
} else {
|
} else {
|
||||||
const_stab = Some(ConstStability {
|
const_stab =
|
||||||
level,
|
Some(ConstStability { level, feature, promotable: false });
|
||||||
feature,
|
|
||||||
promotable: false,
|
|
||||||
allow_const_fn_ptr: false,
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
(None, _, _) => {
|
(None, _, _) => {
|
||||||
|
@ -440,12 +429,8 @@ where
|
||||||
if sym::stable == meta_name {
|
if sym::stable == meta_name {
|
||||||
stab = Some(Stability { level, feature });
|
stab = Some(Stability { level, feature });
|
||||||
} else {
|
} else {
|
||||||
const_stab = Some(ConstStability {
|
const_stab =
|
||||||
level,
|
Some(ConstStability { level, feature, promotable: false });
|
||||||
feature,
|
|
||||||
promotable: false,
|
|
||||||
allow_const_fn_ptr: false,
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
(None, _) => {
|
(None, _) => {
|
||||||
|
@ -464,18 +449,16 @@ where
|
||||||
}
|
}
|
||||||
|
|
||||||
// Merge the const-unstable info into the stability info
|
// Merge the const-unstable info into the stability info
|
||||||
if promotable || allow_const_fn_ptr {
|
if promotable {
|
||||||
if let Some(ref mut stab) = const_stab {
|
if let Some(ref mut stab) = const_stab {
|
||||||
stab.promotable = promotable;
|
stab.promotable = promotable;
|
||||||
stab.allow_const_fn_ptr = allow_const_fn_ptr;
|
|
||||||
} else {
|
} else {
|
||||||
struct_span_err!(
|
struct_span_err!(
|
||||||
diagnostic,
|
diagnostic,
|
||||||
item_sp,
|
item_sp,
|
||||||
E0717,
|
E0717,
|
||||||
"rustc_promotable and rustc_allow_const_fn_ptr attributes \
|
"`rustc_promotable` attribute must be paired with either a `rustc_const_unstable` \
|
||||||
must be paired with either a rustc_const_unstable or a rustc_const_stable \
|
or a `rustc_const_stable` attribute"
|
||||||
attribute"
|
|
||||||
)
|
)
|
||||||
.emit();
|
.emit();
|
||||||
}
|
}
|
||||||
|
|
|
@ -464,7 +464,6 @@ pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
|
||||||
// ==========================================================================
|
// ==========================================================================
|
||||||
|
|
||||||
rustc_attr!(rustc_promotable, AssumedUsed, template!(Word), IMPL_DETAIL),
|
rustc_attr!(rustc_promotable, AssumedUsed, template!(Word), IMPL_DETAIL),
|
||||||
rustc_attr!(rustc_allow_const_fn_ptr, AssumedUsed, template!(Word), IMPL_DETAIL),
|
|
||||||
rustc_attr!(rustc_args_required_const, AssumedUsed, template!(List: "N"), INTERNAL_UNSTABLE),
|
rustc_attr!(rustc_args_required_const, AssumedUsed, template!(List: "N"), INTERNAL_UNSTABLE),
|
||||||
|
|
||||||
// ==========================================================================
|
// ==========================================================================
|
||||||
|
|
|
@ -457,10 +457,6 @@ rustc_queries! {
|
||||||
desc { |tcx| "checking if item is promotable: `{}`", tcx.def_path_str(key) }
|
desc { |tcx| "checking if item is promotable: `{}`", tcx.def_path_str(key) }
|
||||||
}
|
}
|
||||||
|
|
||||||
query const_fn_is_allowed_fn_ptr(key: DefId) -> bool {
|
|
||||||
desc { |tcx| "checking if const fn allows `fn()` types: `{}`", tcx.def_path_str(key) }
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Returns `true` if this is a foreign item (i.e., linked via `extern { ... }`).
|
/// Returns `true` if this is a foreign item (i.e., linked via `extern { ... }`).
|
||||||
query is_foreign_item(key: DefId) -> bool {
|
query is_foreign_item(key: DefId) -> bool {
|
||||||
desc { |tcx| "checking if `{}` is a foreign item", tcx.def_path_str(key) }
|
desc { |tcx| "checking if `{}` is a foreign item", tcx.def_path_str(key) }
|
||||||
|
|
|
@ -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) {
|
pub fn provide(providers: &mut Providers) {
|
||||||
*providers = Providers {
|
*providers = Providers {
|
||||||
is_const_fn_raw,
|
is_const_fn_raw,
|
||||||
is_const_impl_raw: |tcx, def_id| is_const_impl_raw(tcx, def_id.expect_local()),
|
is_const_impl_raw: |tcx, def_id| is_const_impl_raw(tcx, def_id.expect_local()),
|
||||||
is_promotable_const_fn,
|
is_promotable_const_fn,
|
||||||
const_fn_is_allowed_fn_ptr,
|
|
||||||
..*providers
|
..*providers
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -885,7 +885,6 @@ symbols! {
|
||||||
rustc,
|
rustc,
|
||||||
rustc_allocator,
|
rustc_allocator,
|
||||||
rustc_allocator_nounwind,
|
rustc_allocator_nounwind,
|
||||||
rustc_allow_const_fn_ptr,
|
|
||||||
rustc_args_required_const,
|
rustc_args_required_const,
|
||||||
rustc_attrs,
|
rustc_attrs,
|
||||||
rustc_builtin_macro,
|
rustc_builtin_macro,
|
||||||
|
|
|
@ -129,14 +129,9 @@ impl RawWakerVTable {
|
||||||
/// associated task.
|
/// associated task.
|
||||||
#[rustc_promotable]
|
#[rustc_promotable]
|
||||||
#[stable(feature = "futures_api", since = "1.36.0")]
|
#[stable(feature = "futures_api", since = "1.36.0")]
|
||||||
// `rustc_allow_const_fn_ptr` is a hack that should not be used anywhere else
|
|
||||||
// without first consulting with T-Lang.
|
|
||||||
//
|
|
||||||
// FIXME: remove whenever we have a stable way to accept fn pointers from const fn
|
|
||||||
// (see https://github.com/rust-rfcs/const-eval/issues/19#issuecomment-472799062)
|
|
||||||
#[rustc_allow_const_fn_ptr]
|
|
||||||
#[rustc_const_stable(feature = "futures_api", since = "1.36.0")]
|
#[rustc_const_stable(feature = "futures_api", since = "1.36.0")]
|
||||||
#[cfg_attr(not(bootstrap), allow_internal_unstable(const_fn_fn_ptr_basics))]
|
#[cfg_attr(not(bootstrap), allow_internal_unstable(const_fn_fn_ptr_basics))]
|
||||||
|
#[cfg_attr(bootstrap, rustc_allow_const_fn_ptr)]
|
||||||
pub const fn new(
|
pub const fn new(
|
||||||
clone: unsafe fn(*const ()) -> RawWaker,
|
clone: unsafe fn(*const ()) -> RawWaker,
|
||||||
wake: unsafe fn(*const ()),
|
wake: unsafe fn(*const ()),
|
||||||
|
|
Loading…
Reference in New Issue