]> git.lizzy.rs Git - rust.git/commitdiff
add rustc_allow_const_fn_unstable attribute
authorFlorian Warzecha <liketechnik@disroot.org>
Wed, 21 Oct 2020 10:36:07 +0000 (12:36 +0200)
committerFlorian Warzecha <liketechnik@disroot.org>
Wed, 21 Oct 2020 16:04:18 +0000 (18:04 +0200)
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
compiler/rustc_feature/src/builtin_attrs.rs
compiler/rustc_span/src/symbol.rs
src/test/ui/feature-gates/feature-gate-rustc-allow-const-fn-unstable.rs [new file with mode: 0644]
src/test/ui/feature-gates/feature-gate-rustc-allow-const-fn-unstable.stderr [new file with mode: 0644]

index c13fe2ae2806b9c675cbc2898a2870b26ee03dc1..90fed862b9993253957c2ec9e148832d5c5fdb9f 100644 (file)
@@ -210,6 +210,11 @@ pub fn set(&self, features: &mut Features, span: Span) {
     /// 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
 
     // -------------------------------------------------------------------------
index 83aa1f62106cbc1d2f377a4ab3a0d4103e3e5563..f73363cbccc25808e91f19c42c76118002277ae5 100644 (file)
@@ -379,6 +379,10 @@ macro_rules! experimental {
         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",
index 9cf530d57c0b1486c01402455745cc1dc339c2b0..13864f6d0ea8dbdb5ce73c3d8d891c92b24abd81 100644 (file)
         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 (file)
index 0000000..19d8fa8
--- /dev/null
@@ -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 (file)
index 0000000..a549cb6
--- /dev/null
@@ -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`.