Skip to content

Commit 2863acb

Browse files
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.
1 parent 895c37a commit 2863acb

File tree

6 files changed

+8
-42
lines changed

6 files changed

+8
-42
lines changed

compiler/rustc_attr/src/builtin.rs

+7-24
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,6 @@ pub struct ConstStability {
145145
pub feature: Symbol,
146146
/// whether the function has a `#[rustc_promotable]` attribute
147147
pub promotable: bool,
148-
/// whether the function has a `#[rustc_allow_const_fn_ptr]` attribute
149-
pub allow_const_fn_ptr: bool,
150148
}
151149

152150
/// The available stability levels.
@@ -190,7 +188,6 @@ where
190188
let mut stab: Option<Stability> = None;
191189
let mut const_stab: Option<ConstStability> = None;
192190
let mut promotable = false;
193-
let mut allow_const_fn_ptr = false;
194191
let diagnostic = &sess.parse_sess.span_diagnostic;
195192

196193
'outer: for attr in attrs_iter {
@@ -200,7 +197,6 @@ where
200197
sym::unstable,
201198
sym::stable,
202199
sym::rustc_promotable,
203-
sym::rustc_allow_const_fn_ptr,
204200
]
205201
.iter()
206202
.any(|&s| attr.has_name(s))
@@ -215,9 +211,6 @@ where
215211
if attr.has_name(sym::rustc_promotable) {
216212
promotable = true;
217213
}
218-
if attr.has_name(sym::rustc_allow_const_fn_ptr) {
219-
allow_const_fn_ptr = true;
220-
}
221214
// attributes with data
222215
else if let Some(MetaItem { kind: MetaItemKind::List(ref metas), .. }) = meta {
223216
let meta = meta.as_ref().unwrap();
@@ -360,12 +353,8 @@ where
360353
if sym::unstable == meta_name {
361354
stab = Some(Stability { level, feature });
362355
} else {
363-
const_stab = Some(ConstStability {
364-
level,
365-
feature,
366-
promotable: false,
367-
allow_const_fn_ptr: false,
368-
});
356+
const_stab =
357+
Some(ConstStability { level, feature, promotable: false });
369358
}
370359
}
371360
(None, _, _) => {
@@ -440,12 +429,8 @@ where
440429
if sym::stable == meta_name {
441430
stab = Some(Stability { level, feature });
442431
} else {
443-
const_stab = Some(ConstStability {
444-
level,
445-
feature,
446-
promotable: false,
447-
allow_const_fn_ptr: false,
448-
});
432+
const_stab =
433+
Some(ConstStability { level, feature, promotable: false });
449434
}
450435
}
451436
(None, _) => {
@@ -464,18 +449,16 @@ where
464449
}
465450

466451
// Merge the const-unstable info into the stability info
467-
if promotable || allow_const_fn_ptr {
452+
if promotable {
468453
if let Some(ref mut stab) = const_stab {
469454
stab.promotable = promotable;
470-
stab.allow_const_fn_ptr = allow_const_fn_ptr;
471455
} else {
472456
struct_span_err!(
473457
diagnostic,
474458
item_sp,
475459
E0717,
476-
"rustc_promotable and rustc_allow_const_fn_ptr attributes \
477-
must be paired with either a rustc_const_unstable or a rustc_const_stable \
478-
attribute"
460+
"`rustc_promotable` attribute must be paired with either a `rustc_const_unstable` \
461+
or a `rustc_const_stable` attribute"
479462
)
480463
.emit();
481464
}

compiler/rustc_feature/src/builtin_attrs.rs

-1
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,6 @@ pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
464464
// ==========================================================================
465465

466466
rustc_attr!(rustc_promotable, AssumedUsed, template!(Word), IMPL_DETAIL),
467-
rustc_attr!(rustc_allow_const_fn_ptr, AssumedUsed, template!(Word), IMPL_DETAIL),
468467
rustc_attr!(rustc_args_required_const, AssumedUsed, template!(List: "N"), INTERNAL_UNSTABLE),
469468

470469
// ==========================================================================

compiler/rustc_middle/src/query/mod.rs

-4
Original file line numberDiff line numberDiff line change
@@ -457,10 +457,6 @@ rustc_queries! {
457457
desc { |tcx| "checking if item is promotable: `{}`", tcx.def_path_str(key) }
458458
}
459459

460-
query const_fn_is_allowed_fn_ptr(key: DefId) -> bool {
461-
desc { |tcx| "checking if const fn allows `fn()` types: `{}`", tcx.def_path_str(key) }
462-
}
463-
464460
/// Returns `true` if this is a foreign item (i.e., linked via `extern { ... }`).
465461
query is_foreign_item(key: DefId) -> bool {
466462
desc { |tcx| "checking if `{}` is a foreign item", tcx.def_path_str(key) }

compiler/rustc_mir/src/const_eval/fn_queries.rs

-6
Original file line numberDiff line numberDiff line change
@@ -151,17 +151,11 @@ fn is_promotable_const_fn(tcx: TyCtxt<'_>, def_id: DefId) -> bool {
151151
}
152152
}
153153

154-
fn const_fn_is_allowed_fn_ptr(tcx: TyCtxt<'_>, def_id: DefId) -> bool {
155-
is_const_fn(tcx, def_id)
156-
&& tcx.lookup_const_stability(def_id).map(|stab| stab.allow_const_fn_ptr).unwrap_or(false)
157-
}
158-
159154
pub fn provide(providers: &mut Providers) {
160155
*providers = Providers {
161156
is_const_fn_raw,
162157
is_const_impl_raw: |tcx, def_id| is_const_impl_raw(tcx, def_id.expect_local()),
163158
is_promotable_const_fn,
164-
const_fn_is_allowed_fn_ptr,
165159
..*providers
166160
};
167161
}

compiler/rustc_span/src/symbol.rs

-1
Original file line numberDiff line numberDiff line change
@@ -885,7 +885,6 @@ symbols! {
885885
rustc,
886886
rustc_allocator,
887887
rustc_allocator_nounwind,
888-
rustc_allow_const_fn_ptr,
889888
rustc_args_required_const,
890889
rustc_attrs,
891890
rustc_builtin_macro,

library/core/src/task/wake.rs

+1-6
Original file line numberDiff line numberDiff line change
@@ -129,14 +129,9 @@ impl RawWakerVTable {
129129
/// associated task.
130130
#[rustc_promotable]
131131
#[stable(feature = "futures_api", since = "1.36.0")]
132-
// `rustc_allow_const_fn_ptr` is a hack that should not be used anywhere else
133-
// without first consulting with T-Lang.
134-
//
135-
// FIXME: remove whenever we have a stable way to accept fn pointers from const fn
136-
// (see https://github.com/rust-rfcs/const-eval/issues/19#issuecomment-472799062)
137-
#[rustc_allow_const_fn_ptr]
138132
#[rustc_const_stable(feature = "futures_api", since = "1.36.0")]
139133
#[cfg_attr(not(bootstrap), allow_internal_unstable(const_fn_fn_ptr_basics))]
134+
#[cfg_attr(bootstrap, rustc_allow_const_fn_ptr)]
140135
pub const fn new(
141136
clone: unsafe fn(*const ()) -> RawWaker,
142137
wake: unsafe fn(*const ()),

0 commit comments

Comments
 (0)