about summary refs log tree commit diff
diff options
context:
space:
mode:
authorclubby789 <jamie@hill-daniel.co.uk>2025-03-18 01:01:15 +0000
committerclubby789 <jamie@hill-daniel.co.uk>2025-04-03 18:10:48 +0000
commit984c51f6a1d93fa244829f488d2945e7fc06b880 (patch)
tree896ab18075e3aa3bbab36d23f7fa86c938c2832f
parent946aea0b3d9f43e57953ce5094d8e4a2a244ce71 (diff)
downloadrust-984c51f6a1d93fa244829f488d2945e7fc06b880.tar.gz
rust-984c51f6a1d93fa244829f488d2945e7fc06b880.zip
Stabilize `cfg_boolean_literals`
-rw-r--r--compiler/rustc_attr_parsing/src/attributes/cfg.rs15
-rw-r--r--compiler/rustc_feature/src/accepted.rs2
-rw-r--r--compiler/rustc_feature/src/unstable.rs2
-rw-r--r--src/doc/unstable-book/src/language-features/cfg-boolean-literals.md22
-rw-r--r--src/tools/rust-analyzer/crates/ide-db/src/generated/lints.rs29
-rw-r--r--tests/rustdoc-ui/cfg-boolean-literal.rs1
-rw-r--r--tests/rustdoc-ui/doc-cfg-unstable.rs4
-rw-r--r--tests/rustdoc-ui/doc-cfg-unstable.stderr14
-rw-r--r--tests/ui/cfg/true-false.rs1
-rw-r--r--tests/ui/feature-gates/feature-gate-cfg-boolean-literals.rs10
-rw-r--r--tests/ui/feature-gates/feature-gate-cfg-boolean-literals.stderr43
-rw-r--r--tests/ui/lint/inert-attr-macro.rs1
-rw-r--r--tests/ui/lint/inert-attr-macro.stderr14
-rw-r--r--tests/ui/proc-macro/cfg-attr-trace.rs1
-rw-r--r--tests/ui/proc-macro/cfg-attr-trace.stdout30
15 files changed, 26 insertions, 163 deletions
diff --git a/compiler/rustc_attr_parsing/src/attributes/cfg.rs b/compiler/rustc_attr_parsing/src/attributes/cfg.rs
index 0d6d521b40c..48297b2ebd8 100644
--- a/compiler/rustc_attr_parsing/src/attributes/cfg.rs
+++ b/compiler/rustc_attr_parsing/src/attributes/cfg.rs
@@ -7,7 +7,6 @@ use rustc_session::config::ExpectedValues;
 use rustc_session::lint::BuiltinLintDiag;
 use rustc_session::lint::builtin::UNEXPECTED_CFGS;
 use rustc_session::parse::feature_err;
-use rustc_span::symbol::kw;
 use rustc_span::{Span, Symbol, sym};
 
 use crate::session_diagnostics::{self, UnsupportedLiteralReason};
@@ -89,20 +88,6 @@ pub fn eval_condition(
     let cfg = match cfg {
         MetaItemInner::MetaItem(meta_item) => meta_item,
         MetaItemInner::Lit(MetaItemLit { kind: LitKind::Bool(b), .. }) => {
-            if let Some(features) = features {
-                // we can't use `try_gate_cfg` as symbols don't differentiate between `r#true`
-                // and `true`, and we want to keep the former working without feature gate
-                gate_cfg(
-                    &(
-                        if *b { kw::True } else { kw::False },
-                        sym::cfg_boolean_literals,
-                        |features: &Features| features.cfg_boolean_literals(),
-                    ),
-                    cfg.span(),
-                    sess,
-                    features,
-                );
-            }
             return *b;
         }
         _ => {
diff --git a/compiler/rustc_feature/src/accepted.rs b/compiler/rustc_feature/src/accepted.rs
index 88e6593572b..a9ef7c3f9f1 100644
--- a/compiler/rustc_feature/src/accepted.rs
+++ b/compiler/rustc_feature/src/accepted.rs
@@ -95,6 +95,8 @@ declare_features! (
     (accepted, c_unwind, "1.81.0", Some(74990)),
     /// Allows `#[cfg_attr(predicate, multiple, attributes, here)]`.
     (accepted, cfg_attr_multi, "1.33.0", Some(54881)),
+    /// Allows the use of `#[cfg(<true/false>)]`.
+    (accepted, cfg_boolean_literals, "CURRENT_RUSTC_VERSION", Some(131204)),
     /// Allows the use of `#[cfg(doctest)]`, set when rustdoc is collecting doctests.
     (accepted, cfg_doctest, "1.40.0", Some(62210)),
     /// Enables `#[cfg(panic = "...")]` config key.
diff --git a/compiler/rustc_feature/src/unstable.rs b/compiler/rustc_feature/src/unstable.rs
index 87b88bb4223..6ead07ac0ff 100644
--- a/compiler/rustc_feature/src/unstable.rs
+++ b/compiler/rustc_feature/src/unstable.rs
@@ -391,8 +391,6 @@ declare_features! (
     (unstable, async_trait_bounds, "1.85.0", Some(62290)),
     /// Allows using C-variadics.
     (unstable, c_variadic, "1.34.0", Some(44930)),
-    /// Allows the use of `#[cfg(<true/false>)]`.
-    (unstable, cfg_boolean_literals, "1.83.0", Some(131204)),
     /// Allows the use of `#[cfg(contract_checks)` to check if contract checks are enabled.
     (unstable, cfg_contract_checks, "1.86.0", Some(128044)),
     /// Allows the use of `#[cfg(overflow_checks)` to check if integer overflow behaviour.
diff --git a/src/doc/unstable-book/src/language-features/cfg-boolean-literals.md b/src/doc/unstable-book/src/language-features/cfg-boolean-literals.md
deleted file mode 100644
index ad795ff9d9b..00000000000
--- a/src/doc/unstable-book/src/language-features/cfg-boolean-literals.md
+++ /dev/null
@@ -1,22 +0,0 @@
-# `cfg_boolean_literals`
-
-The tracking issue for this feature is: [#131204]
-
-[#131204]: https://github.com/rust-lang/rust/issues/131204
-
-------------------------
-
-The `cfg_boolean_literals` feature makes it possible to use the `true`/`false`
-literal as cfg predicate. They always evaluate to true/false respectively.
-
-## Examples
-
-```rust
-#![feature(cfg_boolean_literals)]
-
-#[cfg(true)]
-const A: i32 = 5;
-
-#[cfg(all(false))]
-const A: i32 = 58 * 89;
-```
diff --git a/src/tools/rust-analyzer/crates/ide-db/src/generated/lints.rs b/src/tools/rust-analyzer/crates/ide-db/src/generated/lints.rs
index 0a7a7d1fb24..706d04484f6 100644
--- a/src/tools/rust-analyzer/crates/ide-db/src/generated/lints.rs
+++ b/src/tools/rust-analyzer/crates/ide-db/src/generated/lints.rs
@@ -3795,35 +3795,6 @@ The tracking issue for this feature is: [#64797]
         deny_since: None,
     },
     Lint {
-        label: "cfg_boolean_literals",
-        description: r##"# `cfg_boolean_literals`
-
-The tracking issue for this feature is: [#131204]
-
-[#131204]: https://github.com/rust-lang/rust/issues/131204
-
-------------------------
-
-The `cfg_boolean_literals` feature makes it possible to use the `true`/`false`
-literal as cfg predicate. They always evaluate to true/false respectively.
-
-## Examples
-
-```rust
-#![feature(cfg_boolean_literals)]
-
-#[cfg(true)]
-const A: i32 = 5;
-
-#[cfg(all(false))]
-const A: i32 = 58 * 89;
-```
-"##,
-        default_severity: Severity::Allow,
-        warn_since: None,
-        deny_since: None,
-    },
-    Lint {
         label: "cfg_eval",
         description: r##"# `cfg_eval`
 
diff --git a/tests/rustdoc-ui/cfg-boolean-literal.rs b/tests/rustdoc-ui/cfg-boolean-literal.rs
index 4d4e599bfee..74808d066c7 100644
--- a/tests/rustdoc-ui/cfg-boolean-literal.rs
+++ b/tests/rustdoc-ui/cfg-boolean-literal.rs
@@ -1,6 +1,5 @@
 //@ check-pass
 
-#![feature(cfg_boolean_literals)]
 #![feature(doc_cfg)]
 
 #[doc(cfg(false))]
diff --git a/tests/rustdoc-ui/doc-cfg-unstable.rs b/tests/rustdoc-ui/doc-cfg-unstable.rs
index 14c2e83ec85..b77c3654497 100644
--- a/tests/rustdoc-ui/doc-cfg-unstable.rs
+++ b/tests/rustdoc-ui/doc-cfg-unstable.rs
@@ -1,10 +1,6 @@
 // #138113: rustdoc didn't gate unstable predicates inside `doc(cfg(..))`
 #![feature(doc_cfg)]
 
-// `cfg_boolean_literals`
-#[doc(cfg(false))] //~ ERROR `cfg(false)` is experimental and subject to change
-pub fn cfg_boolean_literals() {}
-
 // `cfg_version`
 #[doc(cfg(sanitize = "thread"))] //~ ERROR `cfg(sanitize)` is experimental and subject to change
 pub fn cfg_sanitize() {}
diff --git a/tests/rustdoc-ui/doc-cfg-unstable.stderr b/tests/rustdoc-ui/doc-cfg-unstable.stderr
index 54de3b178ed..9651c5f1a0b 100644
--- a/tests/rustdoc-ui/doc-cfg-unstable.stderr
+++ b/tests/rustdoc-ui/doc-cfg-unstable.stderr
@@ -1,15 +1,5 @@
-error[E0658]: `cfg(false)` is experimental and subject to change
-  --> $DIR/doc-cfg-unstable.rs:5:11
-   |
-LL | #[doc(cfg(false))]
-   |           ^^^^^
-   |
-   = note: see issue #131204 <https://github.com/rust-lang/rust/issues/131204> for more information
-   = help: add `#![feature(cfg_boolean_literals)]` to the crate attributes to enable
-   = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
-
 error[E0658]: `cfg(sanitize)` is experimental and subject to change
-  --> $DIR/doc-cfg-unstable.rs:9:11
+  --> $DIR/doc-cfg-unstable.rs:5:11
    |
 LL | #[doc(cfg(sanitize = "thread"))]
    |           ^^^^^^^^^^^^^^^^^^^
@@ -18,6 +8,6 @@ LL | #[doc(cfg(sanitize = "thread"))]
    = help: add `#![feature(cfg_sanitize)]` to the crate attributes to enable
    = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
 
-error: aborting due to 2 previous errors
+error: aborting due to 1 previous error
 
 For more information about this error, try `rustc --explain E0658`.
diff --git a/tests/ui/cfg/true-false.rs b/tests/ui/cfg/true-false.rs
index 03d96fbafec..0bd1cf427fa 100644
--- a/tests/ui/cfg/true-false.rs
+++ b/tests/ui/cfg/true-false.rs
@@ -1,7 +1,6 @@
 //@ run-pass
 
 #![feature(link_cfg)]
-#![feature(cfg_boolean_literals)]
 
 #[cfg(true)]
 fn foo() -> bool {
diff --git a/tests/ui/feature-gates/feature-gate-cfg-boolean-literals.rs b/tests/ui/feature-gates/feature-gate-cfg-boolean-literals.rs
deleted file mode 100644
index 6784b445049..00000000000
--- a/tests/ui/feature-gates/feature-gate-cfg-boolean-literals.rs
+++ /dev/null
@@ -1,10 +0,0 @@
-#[cfg(true)] //~ ERROR `cfg(true)` is experimental
-fn foo() {}
-
-#[cfg_attr(true, cfg(false))] //~ ERROR `cfg(true)` is experimental
-//~^ ERROR `cfg(false)` is experimental
-fn foo() {}
-
-fn main() {
-    cfg!(false); //~ ERROR `cfg(false)` is experimental
-}
diff --git a/tests/ui/feature-gates/feature-gate-cfg-boolean-literals.stderr b/tests/ui/feature-gates/feature-gate-cfg-boolean-literals.stderr
deleted file mode 100644
index 64491464f1d..00000000000
--- a/tests/ui/feature-gates/feature-gate-cfg-boolean-literals.stderr
+++ /dev/null
@@ -1,43 +0,0 @@
-error[E0658]: `cfg(true)` is experimental and subject to change
-  --> $DIR/feature-gate-cfg-boolean-literals.rs:1:7
-   |
-LL | #[cfg(true)]
-   |       ^^^^
-   |
-   = note: see issue #131204 <https://github.com/rust-lang/rust/issues/131204> for more information
-   = help: add `#![feature(cfg_boolean_literals)]` to the crate attributes to enable
-   = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
-
-error[E0658]: `cfg(true)` is experimental and subject to change
-  --> $DIR/feature-gate-cfg-boolean-literals.rs:4:12
-   |
-LL | #[cfg_attr(true, cfg(false))]
-   |            ^^^^
-   |
-   = note: see issue #131204 <https://github.com/rust-lang/rust/issues/131204> for more information
-   = help: add `#![feature(cfg_boolean_literals)]` to the crate attributes to enable
-   = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
-
-error[E0658]: `cfg(false)` is experimental and subject to change
-  --> $DIR/feature-gate-cfg-boolean-literals.rs:4:22
-   |
-LL | #[cfg_attr(true, cfg(false))]
-   |                      ^^^^^
-   |
-   = note: see issue #131204 <https://github.com/rust-lang/rust/issues/131204> for more information
-   = help: add `#![feature(cfg_boolean_literals)]` to the crate attributes to enable
-   = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
-
-error[E0658]: `cfg(false)` is experimental and subject to change
-  --> $DIR/feature-gate-cfg-boolean-literals.rs:9:10
-   |
-LL |     cfg!(false);
-   |          ^^^^^
-   |
-   = note: see issue #131204 <https://github.com/rust-lang/rust/issues/131204> for more information
-   = help: add `#![feature(cfg_boolean_literals)]` to the crate attributes to enable
-   = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
-
-error: aborting due to 4 previous errors
-
-For more information about this error, try `rustc --explain E0658`.
diff --git a/tests/ui/lint/inert-attr-macro.rs b/tests/ui/lint/inert-attr-macro.rs
index 5d4133d6c77..f2d50e30aec 100644
--- a/tests/ui/lint/inert-attr-macro.rs
+++ b/tests/ui/lint/inert-attr-macro.rs
@@ -1,6 +1,5 @@
 //@ check-pass
 
-#![feature(cfg_boolean_literals)]
 #![warn(unused)]
 
 macro_rules! foo {
diff --git a/tests/ui/lint/inert-attr-macro.stderr b/tests/ui/lint/inert-attr-macro.stderr
index b85b0319e71..5ccb4ffe792 100644
--- a/tests/ui/lint/inert-attr-macro.stderr
+++ b/tests/ui/lint/inert-attr-macro.stderr
@@ -1,41 +1,41 @@
 warning: unused attribute `inline`
-  --> $DIR/inert-attr-macro.rs:11:5
+  --> $DIR/inert-attr-macro.rs:10:5
    |
 LL |     #[inline] foo!();
    |     ^^^^^^^^^
    |
 note: the built-in attribute `inline` will be ignored, since it's applied to the macro invocation `foo`
-  --> $DIR/inert-attr-macro.rs:11:15
+  --> $DIR/inert-attr-macro.rs:10:15
    |
 LL |     #[inline] foo!();
    |               ^^^
 note: the lint level is defined here
-  --> $DIR/inert-attr-macro.rs:4:9
+  --> $DIR/inert-attr-macro.rs:3:9
    |
 LL | #![warn(unused)]
    |         ^^^^^^
    = note: `#[warn(unused_attributes)]` implied by `#[warn(unused)]`
 
 warning: unused attribute `allow`
-  --> $DIR/inert-attr-macro.rs:15:5
+  --> $DIR/inert-attr-macro.rs:14:5
    |
 LL |     #[allow(warnings)] #[inline] foo!();
    |     ^^^^^^^^^^^^^^^^^^
    |
 note: the built-in attribute `allow` will be ignored, since it's applied to the macro invocation `foo`
-  --> $DIR/inert-attr-macro.rs:15:34
+  --> $DIR/inert-attr-macro.rs:14:34
    |
 LL |     #[allow(warnings)] #[inline] foo!();
    |                                  ^^^
 
 warning: unused attribute `inline`
-  --> $DIR/inert-attr-macro.rs:15:24
+  --> $DIR/inert-attr-macro.rs:14:24
    |
 LL |     #[allow(warnings)] #[inline] foo!();
    |                        ^^^^^^^^^
    |
 note: the built-in attribute `inline` will be ignored, since it's applied to the macro invocation `foo`
-  --> $DIR/inert-attr-macro.rs:15:34
+  --> $DIR/inert-attr-macro.rs:14:34
    |
 LL |     #[allow(warnings)] #[inline] foo!();
    |                                  ^^^
diff --git a/tests/ui/proc-macro/cfg-attr-trace.rs b/tests/ui/proc-macro/cfg-attr-trace.rs
index 140dd10a7e0..412c65bed1d 100644
--- a/tests/ui/proc-macro/cfg-attr-trace.rs
+++ b/tests/ui/proc-macro/cfg-attr-trace.rs
@@ -3,7 +3,6 @@
 //@ check-pass
 //@ proc-macro: test-macros.rs
 
-#![feature(cfg_boolean_literals)]
 #![feature(cfg_eval)]
 
 #[macro_use]
diff --git a/tests/ui/proc-macro/cfg-attr-trace.stdout b/tests/ui/proc-macro/cfg-attr-trace.stdout
index 52f9ff4e05c..33bcfe5d69b 100644
--- a/tests/ui/proc-macro/cfg-attr-trace.stdout
+++ b/tests/ui/proc-macro/cfg-attr-trace.stdout
@@ -4,75 +4,75 @@ PRINT-ATTR INPUT (DEBUG): TokenStream [
     Punct {
         ch: '#',
         spacing: Alone,
-        span: #0 bytes(305..306),
+        span: #0 bytes(271..272),
     },
     Group {
         delimiter: Bracket,
         stream: TokenStream [
             Ident {
                 ident: "test_macros",
-                span: #0 bytes(322..333),
+                span: #0 bytes(288..299),
             },
             Punct {
                 ch: ':',
                 spacing: Joint,
-                span: #0 bytes(333..334),
+                span: #0 bytes(299..300),
             },
             Punct {
                 ch: ':',
                 spacing: Alone,
-                span: #0 bytes(334..335),
+                span: #0 bytes(300..301),
             },
             Ident {
                 ident: "print_attr",
-                span: #0 bytes(335..345),
+                span: #0 bytes(301..311),
             },
         ],
-        span: #0 bytes(306..347),
+        span: #0 bytes(272..313),
     },
     Ident {
         ident: "struct",
-        span: #0 bytes(348..354),
+        span: #0 bytes(314..320),
     },
     Ident {
         ident: "S",
-        span: #0 bytes(355..356),
+        span: #0 bytes(321..322),
     },
     Punct {
         ch: ';',
         spacing: Alone,
-        span: #0 bytes(356..357),
+        span: #0 bytes(322..323),
     },
 ]
 PRINT-ATTR INPUT (DISPLAY): struct S;
 PRINT-ATTR INPUT (DEBUG): TokenStream [
     Ident {
         ident: "struct",
-        span: #0 bytes(348..354),
+        span: #0 bytes(314..320),
     },
     Ident {
         ident: "S",
-        span: #0 bytes(355..356),
+        span: #0 bytes(321..322),
     },
     Punct {
         ch: ';',
         spacing: Alone,
-        span: #0 bytes(356..357),
+        span: #0 bytes(322..323),
     },
 ]
 PRINT-ATTR INPUT (DISPLAY): struct Z;
 PRINT-ATTR INPUT (DEBUG): TokenStream [
     Ident {
         ident: "struct",
-        span: #0 bytes(411..417),
+        span: #0 bytes(377..383),
     },
     Ident {
         ident: "Z",
-        span: #0 bytes(418..419),
+        span: #0 bytes(384..385),
     },
     Punct {
         ch: ';',
         spacing: Alone,
-        span: #0 bytes(419..420),
+        span: #0 bytes(385..386),
     },
 ]