Skip to content

Commit 1d4648d

Browse files
committed
Stabilize cfg_boolean_literals
1 parent 5cc6072 commit 1d4648d

File tree

15 files changed

+26
-163
lines changed

15 files changed

+26
-163
lines changed

compiler/rustc_attr_parsing/src/attributes/cfg.rs

-15
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ use rustc_session::config::ExpectedValues;
77
use rustc_session::lint::BuiltinLintDiag;
88
use rustc_session::lint::builtin::UNEXPECTED_CFGS;
99
use rustc_session::parse::feature_err;
10-
use rustc_span::symbol::kw;
1110
use rustc_span::{Span, Symbol, sym};
1211

1312
use crate::session_diagnostics::{self, UnsupportedLiteralReason};
@@ -89,20 +88,6 @@ pub fn eval_condition(
8988
let cfg = match cfg {
9089
MetaItemInner::MetaItem(meta_item) => meta_item,
9190
MetaItemInner::Lit(MetaItemLit { kind: LitKind::Bool(b), .. }) => {
92-
if let Some(features) = features {
93-
// we can't use `try_gate_cfg` as symbols don't differentiate between `r#true`
94-
// and `true`, and we want to keep the former working without feature gate
95-
gate_cfg(
96-
&(
97-
if *b { kw::True } else { kw::False },
98-
sym::cfg_boolean_literals,
99-
|features: &Features| features.cfg_boolean_literals(),
100-
),
101-
cfg.span(),
102-
sess,
103-
features,
104-
);
105-
}
10691
return *b;
10792
}
10893
_ => {

compiler/rustc_feature/src/accepted.rs

+2
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ declare_features! (
9595
(accepted, c_unwind, "1.81.0", Some(74990)),
9696
/// Allows `#[cfg_attr(predicate, multiple, attributes, here)]`.
9797
(accepted, cfg_attr_multi, "1.33.0", Some(54881)),
98+
/// Allows the use of `#[cfg(<true/false>)]`.
99+
(accepted, cfg_boolean_literals, "CURRENT_RUSTC_VERSION", Some(131204)),
98100
/// Allows the use of `#[cfg(doctest)]`, set when rustdoc is collecting doctests.
99101
(accepted, cfg_doctest, "1.40.0", Some(62210)),
100102
/// Enables `#[cfg(panic = "...")]` config key.

compiler/rustc_feature/src/unstable.rs

-2
Original file line numberDiff line numberDiff line change
@@ -390,8 +390,6 @@ declare_features! (
390390
(unstable, async_trait_bounds, "1.85.0", Some(62290)),
391391
/// Allows using C-variadics.
392392
(unstable, c_variadic, "1.34.0", Some(44930)),
393-
/// Allows the use of `#[cfg(<true/false>)]`.
394-
(unstable, cfg_boolean_literals, "1.83.0", Some(131204)),
395393
/// Allows the use of `#[cfg(contract_checks)` to check if contract checks are enabled.
396394
(unstable, cfg_contract_checks, "1.86.0", Some(128044)),
397395
/// Allows the use of `#[cfg(overflow_checks)` to check if integer overflow behaviour.

src/doc/unstable-book/src/language-features/cfg-boolean-literals.md

-22
This file was deleted.

src/tools/rust-analyzer/crates/ide-db/src/generated/lints.rs

-29
Original file line numberDiff line numberDiff line change
@@ -3789,35 +3789,6 @@ The tracking issue for this feature is: [#64797]
37893789
[#64797]: https://github.com/rust-lang/rust/issues/64797
37903790

37913791
------------------------
3792-
"##,
3793-
default_severity: Severity::Allow,
3794-
warn_since: None,
3795-
deny_since: None,
3796-
},
3797-
Lint {
3798-
label: "cfg_boolean_literals",
3799-
description: r##"# `cfg_boolean_literals`
3800-
3801-
The tracking issue for this feature is: [#131204]
3802-
3803-
[#131204]: https://github.com/rust-lang/rust/issues/131204
3804-
3805-
------------------------
3806-
3807-
The `cfg_boolean_literals` feature makes it possible to use the `true`/`false`
3808-
literal as cfg predicate. They always evaluate to true/false respectively.
3809-
3810-
## Examples
3811-
3812-
```rust
3813-
#![feature(cfg_boolean_literals)]
3814-
3815-
#[cfg(true)]
3816-
const A: i32 = 5;
3817-
3818-
#[cfg(all(false))]
3819-
const A: i32 = 58 * 89;
3820-
```
38213792
"##,
38223793
default_severity: Severity::Allow,
38233794
warn_since: None,

tests/rustdoc-ui/cfg-boolean-literal.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
//@ check-pass
22

3-
#![feature(cfg_boolean_literals)]
43
#![feature(doc_cfg)]
54

65
#[doc(cfg(false))]

tests/rustdoc-ui/doc-cfg-unstable.rs

-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
// #138113: rustdoc didn't gate unstable predicates inside `doc(cfg(..))`
22
#![feature(doc_cfg)]
33

4-
// `cfg_boolean_literals`
5-
#[doc(cfg(false))] //~ ERROR `cfg(false)` is experimental and subject to change
6-
pub fn cfg_boolean_literals() {}
7-
84
// `cfg_version`
95
#[doc(cfg(sanitize = "thread"))] //~ ERROR `cfg(sanitize)` is experimental and subject to change
106
pub fn cfg_sanitize() {}
+2-12
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,5 @@
1-
error[E0658]: `cfg(false)` is experimental and subject to change
2-
--> $DIR/doc-cfg-unstable.rs:5:11
3-
|
4-
LL | #[doc(cfg(false))]
5-
| ^^^^^
6-
|
7-
= note: see issue #131204 <https://github.com/rust-lang/rust/issues/131204> for more information
8-
= help: add `#![feature(cfg_boolean_literals)]` to the crate attributes to enable
9-
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
10-
111
error[E0658]: `cfg(sanitize)` is experimental and subject to change
12-
--> $DIR/doc-cfg-unstable.rs:9:11
2+
--> $DIR/doc-cfg-unstable.rs:5:11
133
|
144
LL | #[doc(cfg(sanitize = "thread"))]
155
| ^^^^^^^^^^^^^^^^^^^
@@ -18,6 +8,6 @@ LL | #[doc(cfg(sanitize = "thread"))]
188
= help: add `#![feature(cfg_sanitize)]` to the crate attributes to enable
199
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
2010

21-
error: aborting due to 2 previous errors
11+
error: aborting due to 1 previous error
2212

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

tests/ui/cfg/true-false.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
//@ run-pass
22

33
#![feature(link_cfg)]
4-
#![feature(cfg_boolean_literals)]
54

65
#[cfg(true)]
76
fn foo() -> bool {

tests/ui/feature-gates/feature-gate-cfg-boolean-literals.rs

-10
This file was deleted.

tests/ui/feature-gates/feature-gate-cfg-boolean-literals.stderr

-43
This file was deleted.

tests/ui/lint/inert-attr-macro.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
//@ check-pass
22

3-
#![feature(cfg_boolean_literals)]
43
#![warn(unused)]
54

65
macro_rules! foo {

tests/ui/lint/inert-attr-macro.stderr

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,41 @@
11
warning: unused attribute `inline`
2-
--> $DIR/inert-attr-macro.rs:11:5
2+
--> $DIR/inert-attr-macro.rs:10:5
33
|
44
LL | #[inline] foo!();
55
| ^^^^^^^^^
66
|
77
note: the built-in attribute `inline` will be ignored, since it's applied to the macro invocation `foo`
8-
--> $DIR/inert-attr-macro.rs:11:15
8+
--> $DIR/inert-attr-macro.rs:10:15
99
|
1010
LL | #[inline] foo!();
1111
| ^^^
1212
note: the lint level is defined here
13-
--> $DIR/inert-attr-macro.rs:4:9
13+
--> $DIR/inert-attr-macro.rs:3:9
1414
|
1515
LL | #![warn(unused)]
1616
| ^^^^^^
1717
= note: `#[warn(unused_attributes)]` implied by `#[warn(unused)]`
1818

1919
warning: unused attribute `allow`
20-
--> $DIR/inert-attr-macro.rs:15:5
20+
--> $DIR/inert-attr-macro.rs:14:5
2121
|
2222
LL | #[allow(warnings)] #[inline] foo!();
2323
| ^^^^^^^^^^^^^^^^^^
2424
|
2525
note: the built-in attribute `allow` will be ignored, since it's applied to the macro invocation `foo`
26-
--> $DIR/inert-attr-macro.rs:15:34
26+
--> $DIR/inert-attr-macro.rs:14:34
2727
|
2828
LL | #[allow(warnings)] #[inline] foo!();
2929
| ^^^
3030

3131
warning: unused attribute `inline`
32-
--> $DIR/inert-attr-macro.rs:15:24
32+
--> $DIR/inert-attr-macro.rs:14:24
3333
|
3434
LL | #[allow(warnings)] #[inline] foo!();
3535
| ^^^^^^^^^
3636
|
3737
note: the built-in attribute `inline` will be ignored, since it's applied to the macro invocation `foo`
38-
--> $DIR/inert-attr-macro.rs:15:34
38+
--> $DIR/inert-attr-macro.rs:14:34
3939
|
4040
LL | #[allow(warnings)] #[inline] foo!();
4141
| ^^^

tests/ui/proc-macro/cfg-attr-trace.rs

-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
//@ check-pass
44
//@ proc-macro: test-macros.rs
55

6-
#![feature(cfg_boolean_literals)]
76
#![feature(cfg_eval)]
87

98
#[macro_use]

tests/ui/proc-macro/cfg-attr-trace.stdout

+15-15
Original file line numberDiff line numberDiff line change
@@ -4,75 +4,75 @@ PRINT-ATTR INPUT (DEBUG): TokenStream [
44
Punct {
55
ch: '#',
66
spacing: Alone,
7-
span: #0 bytes(305..306),
7+
span: #0 bytes(271..272),
88
},
99
Group {
1010
delimiter: Bracket,
1111
stream: TokenStream [
1212
Ident {
1313
ident: "test_macros",
14-
span: #0 bytes(322..333),
14+
span: #0 bytes(288..299),
1515
},
1616
Punct {
1717
ch: ':',
1818
spacing: Joint,
19-
span: #0 bytes(333..334),
19+
span: #0 bytes(299..300),
2020
},
2121
Punct {
2222
ch: ':',
2323
spacing: Alone,
24-
span: #0 bytes(334..335),
24+
span: #0 bytes(300..301),
2525
},
2626
Ident {
2727
ident: "print_attr",
28-
span: #0 bytes(335..345),
28+
span: #0 bytes(301..311),
2929
},
3030
],
31-
span: #0 bytes(306..347),
31+
span: #0 bytes(272..313),
3232
},
3333
Ident {
3434
ident: "struct",
35-
span: #0 bytes(348..354),
35+
span: #0 bytes(314..320),
3636
},
3737
Ident {
3838
ident: "S",
39-
span: #0 bytes(355..356),
39+
span: #0 bytes(321..322),
4040
},
4141
Punct {
4242
ch: ';',
4343
spacing: Alone,
44-
span: #0 bytes(356..357),
44+
span: #0 bytes(322..323),
4545
},
4646
]
4747
PRINT-ATTR INPUT (DISPLAY): struct S;
4848
PRINT-ATTR INPUT (DEBUG): TokenStream [
4949
Ident {
5050
ident: "struct",
51-
span: #0 bytes(348..354),
51+
span: #0 bytes(314..320),
5252
},
5353
Ident {
5454
ident: "S",
55-
span: #0 bytes(355..356),
55+
span: #0 bytes(321..322),
5656
},
5757
Punct {
5858
ch: ';',
5959
spacing: Alone,
60-
span: #0 bytes(356..357),
60+
span: #0 bytes(322..323),
6161
},
6262
]
6363
PRINT-ATTR INPUT (DISPLAY): struct Z;
6464
PRINT-ATTR INPUT (DEBUG): TokenStream [
6565
Ident {
6666
ident: "struct",
67-
span: #0 bytes(411..417),
67+
span: #0 bytes(377..383),
6868
},
6969
Ident {
7070
ident: "Z",
71-
span: #0 bytes(418..419),
71+
span: #0 bytes(384..385),
7272
},
7373
Punct {
7474
ch: ';',
7575
spacing: Alone,
76-
span: #0 bytes(419..420),
76+
span: #0 bytes(385..386),
7777
},
7878
]

0 commit comments

Comments
 (0)