Skip to content

Commit

Permalink
add rustc_allow_const_fn_unstable attribute
Browse files Browse the repository at this point in the history
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
  • Loading branch information
liketechnik committed Oct 21, 2020
1 parent 5546335 commit 3948b05
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 0 deletions.
5 changes: 5 additions & 0 deletions compiler/rustc_feature/src/active.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 210,11 @@ declare_features! (
/// it is not on path for eventual stabilization).
(active, no_niche, "1.42.0", None, None),

/// Allows using `#[rustc_allow_const_fn_unstable]`.
/// This is an attribute on `const fn` for the same
/// purpose as `#[allow_internal_unstable]`.
(active, rustc_allow_const_fn_unstable, "1.49.0", Some(69399), None),

// no-tracking-issue-end

// -------------------------------------------------------------------------
Expand Down
4 changes: 4 additions & 0 deletions compiler/rustc_feature/src/builtin_attrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 379,10 @@ pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
allow_internal_unstable, AssumedUsed, template!(Word, List: "feat1, feat2, ..."),
"allow_internal_unstable side-steps feature gating and stability checks",
),
gated!(
rustc_allow_const_fn_unstable, AssumedUsed, template!(Word, List: "feat1, feat2, ..."),
"rustc_allow_const_fn_unstable side-steps feature gating and stability checks"
),
gated!(
allow_internal_unsafe, Normal, template!(Word),
"allow_internal_unsafe side-steps the unsafe_code lint",
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_span/src/symbol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -893,6 893,7 @@ symbols! {
rustc,
rustc_allocator,
rustc_allocator_nounwind,
rustc_allow_const_fn_unstable,
rustc_args_required_const,
rustc_attrs,
rustc_builtin_macro,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 1,6 @@
#![allow(unused_macros)]

#[rustc_allow_const_fn_unstable()] //~ ERROR rustc_allow_const_fn_unstable side-steps
const fn foo() { }

fn main() {}
Original file line number Diff line number Diff line change
@@ -0,0 1,12 @@
error[E0658]: rustc_allow_const_fn_unstable side-steps feature gating and stability checks
--> $DIR/feature-gate-rustc-allow-const-fn-unstable.rs:3:1
|
LL | #[rustc_allow_const_fn_unstable()]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: see issue #69399 <https://github.com/rust-lang/rust/issues/69399> for more information
= help: add `#![feature(rustc_allow_const_fn_unstable)]` to the crate attributes to enable

error: aborting due to previous error

For more information about this error, try `rustc --explain E0658`.

0 comments on commit 3948b05

Please sign in to comment.