Skip to content

Commit 3948b05

Browse files
committed
add rustc_allow_const_fn_unstable attribute
allow_internal_unstable is currently used to side-step feature gate and stability checks. While it was originally only meant to be used only on macros, its use was expanded to const functions. This commit prepares stricter checks for the usage of allow_internal_unstable (only on macros) and introduces the rustc_allow_const_fn_unstable attribute for usage on functions. See rust-lang#69399
1 parent 5546335 commit 3948b05

File tree

5 files changed

+28
-0
lines changed

5 files changed

+28
-0
lines changed

compiler/rustc_feature/src/active.rs

+5
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,11 @@ declare_features! (
210210
/// it is not on path for eventual stabilization).
211211
(active, no_niche, "1.42.0", None, None),
212212

213+
/// Allows using `#[rustc_allow_const_fn_unstable]`.
214+
/// This is an attribute on `const fn` for the same
215+
/// purpose as `#[allow_internal_unstable]`.
216+
(active, rustc_allow_const_fn_unstable, "1.49.0", Some(69399), None),
217+
213218
// no-tracking-issue-end
214219

215220
// -------------------------------------------------------------------------

compiler/rustc_feature/src/builtin_attrs.rs

+4
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,10 @@ pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
379379
allow_internal_unstable, AssumedUsed, template!(Word, List: "feat1, feat2, ..."),
380380
"allow_internal_unstable side-steps feature gating and stability checks",
381381
),
382+
gated!(
383+
rustc_allow_const_fn_unstable, AssumedUsed, template!(Word, List: "feat1, feat2, ..."),
384+
"rustc_allow_const_fn_unstable side-steps feature gating and stability checks"
385+
),
382386
gated!(
383387
allow_internal_unsafe, Normal, template!(Word),
384388
"allow_internal_unsafe side-steps the unsafe_code lint",

compiler/rustc_span/src/symbol.rs

+1
Original file line numberDiff line numberDiff line change
@@ -893,6 +893,7 @@ symbols! {
893893
rustc,
894894
rustc_allocator,
895895
rustc_allocator_nounwind,
896+
rustc_allow_const_fn_unstable,
896897
rustc_args_required_const,
897898
rustc_attrs,
898899
rustc_builtin_macro,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#![allow(unused_macros)]
2+
3+
#[rustc_allow_const_fn_unstable()] //~ ERROR rustc_allow_const_fn_unstable side-steps
4+
const fn foo() { }
5+
6+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
error[E0658]: rustc_allow_const_fn_unstable side-steps feature gating and stability checks
2+
--> $DIR/feature-gate-rustc-allow-const-fn-unstable.rs:3:1
3+
|
4+
LL | #[rustc_allow_const_fn_unstable()]
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6+
|
7+
= note: see issue #69399 <https://github.com/rust-lang/rust/issues/69399> for more information
8+
= help: add `#![feature(rustc_allow_const_fn_unstable)]` to the crate attributes to enable
9+
10+
error: aborting due to previous error
11+
12+
For more information about this error, try `rustc --explain E0658`.

0 commit comments

Comments
 (0)