Stabilize cfg_select

This commit is contained in:
Folkert de Vries
2026-02-07 20:42:31 +01:00
parent 99246f4093
commit 14d29f9ae2
29 changed files with 41 additions and 100 deletions
@@ -128,20 +128,14 @@ pub fn parse_cfg_select(
}
}
if let Some(features) = features
&& features.enabled(sym::cfg_select)
{
let it = branches
.reachable
.iter()
.map(|(entry, _, _)| CfgSelectPredicate::Cfg(entry.clone()))
.chain(branches.wildcard.as_ref().map(|(t, _, _)| CfgSelectPredicate::Wildcard(*t)))
.chain(
branches.unreachable.iter().map(|(entry, _, _)| CfgSelectPredicate::clone(entry)),
);
let it = branches
.reachable
.iter()
.map(|(entry, _, _)| CfgSelectPredicate::Cfg(entry.clone()))
.chain(branches.wildcard.as_ref().map(|(t, _, _)| CfgSelectPredicate::Wildcard(*t)))
.chain(branches.unreachable.iter().map(|(entry, _, _)| CfgSelectPredicate::clone(entry)));
lint_unreachable(p, it, lint_node_id);
}
lint_unreachable(p, it, lint_node_id);
Ok(branches)
}
@@ -17,8 +17,8 @@ index 1e336bf..35e6f54 100644
@@ -2,4 +2,3 @@
// tidy-alphabetical-start
-#![cfg_attr(target_has_atomic = "128", feature(integer_atomics))]
#![cfg_attr(test, feature(cfg_select))]
#![feature(array_ptr_get)]
#![feature(array_try_from_fn)]
diff --git a/coretests/tests/atomic.rs b/coretests/tests/atomic.rs
index b735957..ea728b6 100644
--- a/coretests/tests/atomic.rs
+1 -1
View File
@@ -11,6 +11,7 @@
#![allow(rustc::default_hash_types)]
#![allow(rustc::potential_query_instability)]
#![cfg_attr(bootstrap, feature(assert_matches))]
#![cfg_attr(bootstrap, feature(cfg_select))]
#![cfg_attr(bootstrap, feature(cold_path))]
#![cfg_attr(test, feature(test))]
#![deny(unsafe_op_in_unsafe_fn)]
@@ -18,7 +19,6 @@
#![feature(ascii_char)]
#![feature(ascii_char_variants)]
#![feature(auto_traits)]
#![feature(cfg_select)]
#![feature(const_default)]
#![feature(const_trait_impl)]
#![feature(dropck_eyepatch)]
+2
View File
@@ -102,6 +102,8 @@ macro_rules! declare_features {
(accepted, cfg_doctest, "1.40.0", Some(62210)),
/// Enables `#[cfg(panic = "...")]` config key.
(accepted, cfg_panic, "1.60.0", Some(77443)),
/// Provides a native way to easily manage multiple conditional flags without having to rewrite each clause multiple times.
(accepted, cfg_select, "CURRENT_RUSTC_VERSION", Some(115585)),
/// Allows `cfg(target_abi = "...")`.
(accepted, cfg_target_abi, "1.78.0", Some(80970)),
/// Allows `cfg(target_feature = "...")`.
-2
View File
@@ -388,8 +388,6 @@ pub fn internal(&self, feature: Symbol) -> bool {
(unstable, cfg_sanitize, "1.41.0", Some(39699)),
/// Allows `cfg(sanitizer_cfi_generalize_pointers)` and `cfg(sanitizer_cfi_normalize_integers)`.
(unstable, cfg_sanitizer_cfi, "1.77.0", Some(89653)),
/// Provides a native way to easily manage multiple conditional flags without having to rewrite each clause multiple times.
(unstable, cfg_select, "CURRENT_RUSTC_VERSION", Some(115585)),
/// Allows `cfg(target(abi = "..."))`.
(unstable, cfg_target_compact, "1.63.0", Some(96901)),
/// Allows `cfg(target_has_atomic_load_store = "...")`.
+1 -2
View File
@@ -864,7 +864,7 @@
/// ### Example
///
/// ```rust
/// #![feature(cfg_select)]
/// # #![cfg_attr(bootstrap, feature(cfg_select))]
/// cfg_select! {
/// _ => (),
/// windows => (),
@@ -882,7 +882,6 @@
pub UNREACHABLE_CFG_SELECT_PREDICATES,
Warn,
"detects unreachable configuration predicates in the cfg_select macro",
@feature_gate = cfg_select;
}
declare_lint! {
+1 -1
View File
@@ -17,9 +17,9 @@
// tidy-alphabetical-start
#![allow(internal_features)]
#![cfg_attr(bootstrap, feature(cfg_select))]
#![cfg_attr(bootstrap, feature(if_let_guard))]
#![cfg_attr(target_arch = "loongarch64", feature(stdarch_loongarch))]
#![feature(cfg_select)]
#![feature(core_io_borrowed_buf)]
#![feature(map_try_insert)]
#![feature(negative_impls)]
+1 -2
View File
@@ -98,7 +98,6 @@
// tidy-alphabetical-start
#![feature(asm_experimental_arch)]
#![feature(bstr_internals)]
#![feature(cfg_select)]
#![feature(cfg_target_has_reliable_f16_f128)]
#![feature(const_carrying_mul_add)]
#![feature(const_cmp)]
@@ -227,7 +226,7 @@ pub mod autodiff {
#[unstable(feature = "contracts", issue = "128044")]
pub mod contracts;
#[unstable(feature = "cfg_select", issue = "115585")]
#[stable(feature = "cfg_select", since = "CURRENT_RUSTC_VERSION")]
pub use crate::macros::cfg_select;
#[macro_use]
+1 -5
View File
@@ -206,8 +206,6 @@ macro_rules! assert_ne {
/// # Example
///
/// ```
/// #![feature(cfg_select)]
///
/// cfg_select! {
/// unix => {
/// fn foo() { /* unix specific functionality */ }
@@ -225,14 +223,12 @@ macro_rules! assert_ne {
/// right-hand side:
///
/// ```
/// #![feature(cfg_select)]
///
/// let _some_string = cfg_select! {
/// unix => "With great power comes great electricity bills",
/// _ => { "Behind every successful diet is an unwatched pizza" }
/// };
/// ```
#[unstable(feature = "cfg_select", issue = "115585")]
#[stable(feature = "cfg_select", since = "CURRENT_RUSTC_VERSION")]
#[rustc_diagnostic_item = "cfg_select"]
#[rustc_builtin_macro]
pub macro cfg_select($($tt:tt)*) {
+1 -1
View File
@@ -80,7 +80,7 @@ mod panic {}
#[doc(no_inline)]
pub use self::ambiguous_macros_only::{env, panic};
#[unstable(feature = "cfg_select", issue = "115585")]
#[stable(feature = "cfg_select", since = "CURRENT_RUSTC_VERSION")]
#[doc(no_inline)]
pub use crate::cfg_select;
-1
View File
@@ -1,6 +1,5 @@
// tidy-alphabetical-start
#![cfg_attr(target_has_atomic = "128", feature(integer_atomics))]
#![cfg_attr(test, feature(cfg_select))]
#![feature(array_ptr_get)]
#![feature(array_try_from_fn)]
#![feature(array_try_map)]
-1
View File
@@ -15,7 +15,6 @@
#![unstable(feature = "panic_unwind", issue = "32837")]
#![doc(issue_tracker_base_url = "https://github.com/rust-lang/rust/issues/")]
#![feature(cfg_emscripten_wasm_eh)]
#![feature(cfg_select)]
#![feature(core_intrinsics)]
#![feature(panic_unwind)]
#![feature(staged_api)]
+1 -2
View File
@@ -322,7 +322,6 @@
#![feature(bstr)]
#![feature(bstr_internals)]
#![feature(cast_maybe_uninit)]
#![feature(cfg_select)]
#![feature(char_internals)]
#![feature(clone_to_uninit)]
#![feature(const_convert)]
@@ -695,7 +694,7 @@ pub mod arch {
#[allow(dead_code, unused_attributes, fuzzy_provenance_casts, unsafe_op_in_unsafe_fn)]
mod backtrace_rs;
#[unstable(feature = "cfg_select", issue = "115585")]
#[stable(feature = "cfg_select", since = "CURRENT_RUSTC_VERSION")]
pub use core::cfg_select;
#[unstable(
feature = "concat_bytes",
+1 -1
View File
@@ -79,7 +79,7 @@ mod panic {}
#[doc(no_inline)]
pub use self::ambiguous_macros_only::{vec, panic};
#[unstable(feature = "cfg_select", issue = "115585")]
#[stable(feature = "cfg_select", since = "CURRENT_RUSTC_VERSION")]
#[doc(no_inline)]
pub use core::prelude::v1::cfg_select;
-1
View File
@@ -1,6 +1,5 @@
// These tests are in a separate integration test as they modify the environment,
// and would otherwise cause some other tests to fail.
#![feature(cfg_select)]
use std::env::*;
use std::ffi::{OsStr, OsString};
+1 -1
View File
@@ -15,7 +15,7 @@
//! * `s390x`: [`is_s390x_feature_detected`]
#![unstable(feature = "stdarch_internal", issue = "none")]
#![feature(staged_api, cfg_select, doc_cfg, allow_internal_unstable)]
#![feature(staged_api, doc_cfg, allow_internal_unstable)]
#![deny(rust_2018_idioms)]
#![allow(clippy::shadow_reuse)]
#![cfg_attr(test, allow(unused_imports))]
-1
View File
@@ -1,7 +1,6 @@
#![no_std]
#![unstable(feature = "panic_unwind", issue = "32837")]
#![feature(cfg_emscripten_wasm_eh)]
#![feature(cfg_select)]
#![feature(link_cfg)]
#![feature(staged_api)]
#![cfg_attr(
+1 -1
View File
@@ -1,6 +1,5 @@
#![cfg_attr(bootstrap, feature(if_let_guard))]
#![feature(abort_unwind)]
#![feature(cfg_select)]
#![feature(rustc_private)]
#![feature(float_gamma)]
#![feature(float_erf)]
@@ -17,6 +16,7 @@
#![feature(derive_coerce_pointee)]
#![feature(arbitrary_self_types)]
#![feature(iter_advance_by)]
#![cfg_attr(bootstrap, feature(cfg_select))]
// Configure clippy and other lints
#![allow(
clippy::collapsible_else_if,
@@ -2,7 +2,6 @@
//@revisions: random max none
//@[max]compile-flags: -Zmiri-max-extra-rounding-error
//@[none]compile-flags: -Zmiri-no-extra-rounding-error
#![feature(cfg_select)]
use std::collections::HashSet;
use std::hint::black_box;
@@ -1,6 +1,5 @@
#![crate_type = "staticlib"]
#![feature(c_variadic)]
#![feature(cfg_select)]
use std::ffi::{CStr, CString, VaList, c_char, c_double, c_int, c_long, c_longlong};
-1
View File
@@ -3,7 +3,6 @@
//@ revisions: reva revb
//@ only-x86_64
//@ run-pass
#![feature(cfg_select)]
use std::arch::{asm, naked_asm};
-1
View File
@@ -1,6 +1,5 @@
//@ check-pass
#![feature(cfg_select)]
#![crate_type = "lib"]
cfg_select! {
+2 -2
View File
@@ -1,5 +1,5 @@
warning: unexpected `cfg` condition name: `invalid_cfg1`
--> $DIR/cfg-select.rs:8:5
--> $DIR/cfg-select.rs:7:5
|
LL | invalid_cfg1 => {}
| ^^^^^^^^^^^^
@@ -10,7 +10,7 @@ LL | invalid_cfg1 => {}
= note: `#[warn(unexpected_cfgs)]` on by default
warning: unexpected `cfg` condition name: `invalid_cfg2`
--> $DIR/cfg-select.rs:14:5
--> $DIR/cfg-select.rs:13:5
|
LL | invalid_cfg2 => {}
| ^^^^^^^^^^^^
@@ -1,11 +0,0 @@
#![warn(unreachable_cfg_select_predicates)]
//~^ WARN unknown lint: `unreachable_cfg_select_predicates`
cfg_select! {
//~^ ERROR use of unstable library feature `cfg_select`
_ => {}
// With the feature enabled, this branch would trip the unreachable_cfg_select_predicate lint.
true => {}
}
fn main() {}
@@ -1,25 +0,0 @@
error[E0658]: use of unstable library feature `cfg_select`
--> $DIR/feature-gate-cfg-select.rs:4:1
|
LL | cfg_select! {
| ^^^^^^^^^^
|
= note: see issue #115585 <https://github.com/rust-lang/rust/issues/115585> for more information
= help: add `#![feature(cfg_select)]` to the crate attributes to enable
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
warning: unknown lint: `unreachable_cfg_select_predicates`
--> $DIR/feature-gate-cfg-select.rs:1:9
|
LL | #![warn(unreachable_cfg_select_predicates)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: the `unreachable_cfg_select_predicates` lint is unstable
= note: see issue #115585 <https://github.com/rust-lang/rust/issues/115585> for more information
= help: add `#![feature(cfg_select)]` to the crate attributes to enable
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
= note: `#[warn(unknown_lints)]` on by default
error: aborting due to 1 previous error; 1 warning emitted
For more information about this error, try `rustc --explain E0658`.
-1
View File
@@ -1,4 +1,3 @@
#![feature(cfg_select)]
#![crate_type = "lib"]
#![warn(unreachable_cfg_select_predicates)] // Unused warnings are disabled by default in UI tests.
+17 -17
View File
@@ -1,5 +1,5 @@
error: none of the predicates in this `cfg_select` evaluated to true
--> $DIR/cfg_select.rs:162:1
--> $DIR/cfg_select.rs:161:1
|
LL | / cfg_select! {
LL | |
@@ -8,55 +8,55 @@ LL | | }
| |_^
error: none of the predicates in this `cfg_select` evaluated to true
--> $DIR/cfg_select.rs:167:1
--> $DIR/cfg_select.rs:166:1
|
LL | cfg_select! {}
| ^^^^^^^^^^^^^^
error: expected a literal (`1u8`, `1.0f32`, `"string"`, etc.) here, found `=>`
--> $DIR/cfg_select.rs:171:5
--> $DIR/cfg_select.rs:170:5
|
LL | => {}
| ^^
error: expected a literal (`1u8`, `1.0f32`, `"string"`, etc.) here, found expression
--> $DIR/cfg_select.rs:176:5
--> $DIR/cfg_select.rs:175:5
|
LL | () => {}
| ^^ expressions are not allowed here
error[E0539]: malformed `cfg_select` macro input
--> $DIR/cfg_select.rs:181:5
--> $DIR/cfg_select.rs:180:5
|
LL | "str" => {}
| ^^^^^ expected a valid identifier here
error[E0539]: malformed `cfg_select` macro input
--> $DIR/cfg_select.rs:186:5
--> $DIR/cfg_select.rs:185:5
|
LL | a::b => {}
| ^^^^ expected a valid identifier here
error[E0537]: invalid predicate `a`
--> $DIR/cfg_select.rs:191:5
--> $DIR/cfg_select.rs:190:5
|
LL | a() => {}
| ^^^
error: expected one of `(`, `::`, `=>`, or `=`, found `+`
--> $DIR/cfg_select.rs:196:7
--> $DIR/cfg_select.rs:195:7
|
LL | a + 1 => {}
| ^ expected one of `(`, `::`, `=>`, or `=`
error: expected one of `(`, `::`, `=>`, or `=`, found `!`
--> $DIR/cfg_select.rs:202:8
--> $DIR/cfg_select.rs:201:8
|
LL | cfg!() => {}
| ^ expected one of `(`, `::`, `=>`, or `=`
warning: unreachable configuration predicate
--> $DIR/cfg_select.rs:137:5
--> $DIR/cfg_select.rs:136:5
|
LL | _ => {}
| - always matches
@@ -64,13 +64,13 @@ LL | true => {}
| ^^^^ this configuration predicate is never reached
|
note: the lint level is defined here
--> $DIR/cfg_select.rs:3:9
--> $DIR/cfg_select.rs:2:9
|
LL | #![warn(unreachable_cfg_select_predicates)] // Unused warnings are disabled by default in UI tests.
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
warning: unreachable configuration predicate
--> $DIR/cfg_select.rs:143:5
--> $DIR/cfg_select.rs:142:5
|
LL | true => {}
| ---- always matches
@@ -78,25 +78,25 @@ LL | _ => {}
| ^ this configuration predicate is never reached
warning: unreachable configuration predicate
--> $DIR/cfg_select.rs:150:5
--> $DIR/cfg_select.rs:149:5
|
LL | _ => {}
| ^ this configuration predicate is never reached
warning: unreachable configuration predicate
--> $DIR/cfg_select.rs:156:5
--> $DIR/cfg_select.rs:155:5
|
LL | test => {}
| ^^^^ this configuration predicate is never reached
warning: unreachable configuration predicate
--> $DIR/cfg_select.rs:158:5
--> $DIR/cfg_select.rs:157:5
|
LL | _ => {}
| ^ this configuration predicate is never reached
warning: unexpected `cfg` condition name: `a`
--> $DIR/cfg_select.rs:196:5
--> $DIR/cfg_select.rs:195:5
|
LL | a + 1 => {}
| ^ help: found config with similar value: `target_feature = "a"`
@@ -107,7 +107,7 @@ LL | a + 1 => {}
= note: `#[warn(unexpected_cfgs)]` on by default
warning: unexpected `cfg` condition name: `cfg`
--> $DIR/cfg_select.rs:202:5
--> $DIR/cfg_select.rs:201:5
|
LL | cfg!() => {}
| ^^^
@@ -1,4 +1,3 @@
#![feature(cfg_select)]
#![crate_type = "lib"]
// Check that parse errors in arms that are not selected are still reported.
@@ -1,5 +1,5 @@
error: Rust has no postfix increment operator
--> $DIR/cfg_select_parse_error.rs:8:22
--> $DIR/cfg_select_parse_error.rs:7:22
|
LL | false => { 1 ++ 2 }
| ^^ not a valid postfix operator
@@ -11,7 +11,7 @@ LL + false => { { let tmp = 1 ; 1 += 1; tmp } 2 }
|
error: Rust has no postfix increment operator
--> $DIR/cfg_select_parse_error.rs:15:29
--> $DIR/cfg_select_parse_error.rs:14:29
|
LL | false => { fn foo() { 1 +++ 2 } }
| ^^ not a valid postfix operator