Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stabilize cfg_boolean_literals #138632

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 0 additions & 15 deletions compiler/rustc_attr_parsing/src/attributes/cfg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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;
}
_ => {
Expand Down
2 changes: 2 additions & 0 deletions compiler/rustc_feature/src/accepted.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 0 additions & 2 deletions compiler/rustc_feature/src/unstable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

This file was deleted.

29 changes: 0 additions & 29 deletions src/tools/rust-analyzer/crates/ide-db/src/generated/lints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3789,35 +3789,6 @@ The tracking issue for this feature is: [#64797]
[#64797]: https://github.com/rust-lang/rust/issues/64797

------------------------
"##,
default_severity: Severity::Allow,
warn_since: None,
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,
Expand Down
2 changes: 1 addition & 1 deletion tests/pretty/ast-stmt-expr-attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

fn main() {}

#[cfg(FALSE)]
#[cfg(false)]
fn syntax() {
let _ = #[attr] [];
let _ = #[attr] [0];
Expand Down
2 changes: 1 addition & 1 deletion tests/pretty/enum-variant-vis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@

fn main() {}

#[cfg(FALSE)]
#[cfg(false)]
enum Foo { pub V, }
8 changes: 4 additions & 4 deletions tests/pretty/if-attr.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//@ pp-exact

#[cfg(FALSE)]
#[cfg(false)]
fn simple_attr() {

#[attr]
Expand All @@ -10,21 +10,21 @@ fn simple_attr() {
if true {}
}

#[cfg(FALSE)]
#[cfg(false)]
fn if_else_chain() {

#[first_attr]
if true {} else if false {} else {}
}

#[cfg(FALSE)]
#[cfg(false)]
fn if_let() {

#[attr]
if let Some(_) = Some(true) {}
}

#[cfg(FALSE)]
#[cfg(false)]
fn let_attr_if() {
let _ = #[attr] if let _ = 0 {};
let _ = #[attr] if true {};
Expand Down
6 changes: 3 additions & 3 deletions tests/pretty/nested-item-vis-defaultness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

fn main() {}

#[cfg(FALSE)]
#[cfg(false)]
extern "C" {
static X: u8;
type X;
Expand All @@ -14,7 +14,7 @@ extern "C" {
pub fn foo();
}

#[cfg(FALSE)]
#[cfg(false)]
trait T {
const X: u8;
type X;
Expand All @@ -30,7 +30,7 @@ trait T {
pub default fn foo();
}

#[cfg(FALSE)]
#[cfg(false)]
impl T for S {
const X: u8;
type X;
Expand Down
1 change: 0 additions & 1 deletion tests/rustdoc-ui/cfg-boolean-literal.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
//@ check-pass

#![feature(cfg_boolean_literals)]
#![feature(doc_cfg)]

#[doc(cfg(false))]
Expand Down
4 changes: 0 additions & 4 deletions tests/rustdoc-ui/doc-cfg-unstable.rs
Original file line number Diff line number Diff line change
@@ -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() {}
14 changes: 2 additions & 12 deletions tests/rustdoc-ui/doc-cfg-unstable.stderr
Original file line number Diff line number Diff line change
@@ -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"))]
| ^^^^^^^^^^^^^^^^^^^
Expand All @@ -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`.
2 changes: 1 addition & 1 deletion tests/ui/associated-types/associated-type-macro.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
fn main() {
#[cfg(FALSE)]
#[cfg(false)]
<() as module>::mac!(); //~ ERROR macros cannot use qualified paths
}
2 changes: 1 addition & 1 deletion tests/ui/async-await/feature-async-for-loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ fn f() {
};
}

#[cfg(FALSE)]
#[cfg(false)]
fn g() {
let _ = async {
for await _i in core::async_iter::from_iter(0..3) {
Expand Down
4 changes: 2 additions & 2 deletions tests/ui/async-await/no-unsafe-async.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
struct S;

impl S {
#[cfg(FALSE)]
#[cfg(false)]
unsafe async fn g() {} //~ ERROR expected one of `extern` or `fn`, found keyword `async`
}

#[cfg(FALSE)]
#[cfg(false)]
unsafe async fn f() {} //~ ERROR expected one of `extern` or `fn`, found keyword `async`

fn main() {}
4 changes: 2 additions & 2 deletions tests/ui/attributes/z-crate-attr/cfg-false.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Ensure that `-Z crate-attr=cfg(FALSE)` can comment out the whole crate
//@ compile-flags: --crate-type=lib -Zcrate-attr=cfg(FALSE)
// Ensure that `-Z crate-attr=cfg(false)` can comment out the whole crate
//@ compile-flags: --crate-type=lib -Zcrate-attr=cfg(false)
//@ check-pass

// NOTE: duplicate items are load-bearing
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/auto-traits/pre-cfg.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//@ check-pass

#[cfg(FALSE)]
#[cfg(false)]
auto trait Foo {}
//~^ WARN `auto` traits are unstable
//~| WARN unstable syntax can change at any point in the future, causing a hard error!
Expand Down
4 changes: 2 additions & 2 deletions tests/ui/cfg/auxiliary/cfg_false_lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// `#![no_std]` on a fully unconfigured crate is respected if it's placed before `cfg(FALSE)`.
// `#![no_std]` on a fully unconfigured crate is respected if it's placed before `cfg(false)`.
// This crate has no such attribute, therefore this crate does link to libstd.

#![cfg(FALSE)]
#![cfg(false)]
4 changes: 2 additions & 2 deletions tests/ui/cfg/auxiliary/cfg_false_lib_no_std_after.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// `#![no_std]` on a fully unconfigured crate is respected if it's placed before `cfg(FALSE)`.
// `#![no_std]` on a fully unconfigured crate is respected if it's placed before `cfg(false)`.
// Therefore this crate does link to libstd.

#![cfg(FALSE)]
#![cfg(false)]
#![no_std]
4 changes: 2 additions & 2 deletions tests/ui/cfg/auxiliary/cfg_false_lib_no_std_before.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// `#![no_std]` on a fully unconfigured crate is respected if it's placed before `cfg(FALSE)`.
// `#![no_std]` on a fully unconfigured crate is respected if it's placed before `cfg(false)`.
// Therefore this crate doesn't link to libstd.

//@ no-prefer-dynamic

#![no_std]
#![crate_type = "lib"]
#![cfg(FALSE)]
#![cfg(false)]
4 changes: 2 additions & 2 deletions tests/ui/cfg/auxiliary/cfged_out.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
pub mod inner {
#[cfg(FALSE)]
#[cfg(false)]
pub fn uwu() {}

#[cfg(FALSE)]
#[cfg(false)]
pub mod doesnt_exist {
pub fn hello() {}
}
Expand Down
14 changes: 14 additions & 0 deletions tests/ui/cfg/both-true-false.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/// Test that placing a `cfg(true)` and `cfg(false)` on the same item result in
//. it being disabled.`

#[cfg(false)]
#[cfg(true)]
fn foo() {}

#[cfg(true)]
#[cfg(false)]
fn foo() {}

fn main() {
foo(); //~ ERROR cannot find function `foo` in this scope
}
9 changes: 9 additions & 0 deletions tests/ui/cfg/both-true-false.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
error[E0425]: cannot find function `foo` in this scope
--> $DIR/both-true-false.rs:13:5
|
LL | foo();
| ^^^ not found in this scope

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0425`.
4 changes: 2 additions & 2 deletions tests/ui/cfg/cfg-false-feature.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// Features above `cfg(FALSE)` are in effect in a fully unconfigured crate (issue #104633).
// Features above `cfg(false)` are in effect in a fully unconfigured crate (issue #104633).

//@ check-pass
//@ compile-flags: --crate-type lib

#![feature(decl_macro)]
#![cfg(FALSE)]
#![cfg(false)]
#![feature(box_patterns)]

macro mac() {} // OK
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/cfg/cfg-macros-notfoo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// check that cfg correctly chooses between the macro impls (see also
// cfg-macros-foo.rs)

#[cfg(FALSE)]
#[cfg(false)]
#[macro_use]
mod foo {
macro_rules! bar {
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/cfg/cfg-match-arm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ fn foo(f: Foo) {
Foo::Bar => {},
#[cfg(not(FALSE))]
Foo::Baz => {},
#[cfg(FALSE)]
#[cfg(false)]
Basdfwe => {}
}
}
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/cfg/cfg-stmt-recovery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#[cfg_eval]
fn main() {
#[cfg_eval]
let _ = #[cfg(FALSE)] 0;
let _ = #[cfg(false)] 0;
//~^ ERROR removing an expression is not supported in this position
//~| ERROR expected expression, found `;`
//~| ERROR removing an expression is not supported in this position
Expand Down
6 changes: 3 additions & 3 deletions tests/ui/cfg/cfg-stmt-recovery.stderr
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
error: removing an expression is not supported in this position
--> $DIR/cfg-stmt-recovery.rs:9:13
|
LL | let _ = #[cfg(FALSE)] 0;
LL | let _ = #[cfg(false)] 0;
| ^^^^^^^^^^^^^

error: expected expression, found `;`
--> $DIR/cfg-stmt-recovery.rs:9:28
|
LL | let _ = #[cfg(FALSE)] 0;
LL | let _ = #[cfg(false)] 0;
| ^ expected expression

error: removing an expression is not supported in this position
--> $DIR/cfg-stmt-recovery.rs:9:13
|
LL | let _ = #[cfg(FALSE)] 0;
LL | let _ = #[cfg(false)] 0;
| ^^^^^^^^^^^^^

error: aborting due to 3 previous errors
Expand Down
Loading
Loading