From 3948b054dc8e598b83a194056dc4d3a0852dc79e Mon Sep 17 00:00:00 2001 From: Florian Warzecha Date: Wed, 21 Oct 2020 12:36:07 +0200 Subject: [PATCH] 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/rust#69399 --- compiler/rustc_feature/src/active.rs | 5 +++++ compiler/rustc_feature/src/builtin_attrs.rs | 4 ++++ compiler/rustc_span/src/symbol.rs | 1 + .../feature-gate-rustc-allow-const-fn-unstable.rs | 6 ++++++ ...feature-gate-rustc-allow-const-fn-unstable.stderr | 12 ++++++++++++ 5 files changed, 28 insertions(+) create mode 100644 src/test/ui/feature-gates/feature-gate-rustc-allow-const-fn-unstable.rs create mode 100644 src/test/ui/feature-gates/feature-gate-rustc-allow-const-fn-unstable.stderr diff --git a/compiler/rustc_feature/src/active.rs b/compiler/rustc_feature/src/active.rs index c13fe2ae280..90fed862b99 100644 --- a/compiler/rustc_feature/src/active.rs +++ b/compiler/rustc_feature/src/active.rs @@ -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 // ------------------------------------------------------------------------- diff --git a/compiler/rustc_feature/src/builtin_attrs.rs b/compiler/rustc_feature/src/builtin_attrs.rs index 83aa1f62106..f73363cbccc 100644 --- a/compiler/rustc_feature/src/builtin_attrs.rs +++ b/compiler/rustc_feature/src/builtin_attrs.rs @@ -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", diff --git a/compiler/rustc_span/src/symbol.rs b/compiler/rustc_span/src/symbol.rs index 9cf530d57c0..13864f6d0ea 100644 --- a/compiler/rustc_span/src/symbol.rs +++ b/compiler/rustc_span/src/symbol.rs @@ -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, diff --git a/src/test/ui/feature-gates/feature-gate-rustc-allow-const-fn-unstable.rs b/src/test/ui/feature-gates/feature-gate-rustc-allow-const-fn-unstable.rs new file mode 100644 index 00000000000..19d8fa87f55 --- /dev/null +++ b/src/test/ui/feature-gates/feature-gate-rustc-allow-const-fn-unstable.rs @@ -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() {} diff --git a/src/test/ui/feature-gates/feature-gate-rustc-allow-const-fn-unstable.stderr b/src/test/ui/feature-gates/feature-gate-rustc-allow-const-fn-unstable.stderr new file mode 100644 index 00000000000..a549cb64e0c --- /dev/null +++ b/src/test/ui/feature-gates/feature-gate-rustc-allow-const-fn-unstable.stderr @@ -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 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`.