diff --git a/src/tools/rustfmt/src/macros.rs b/src/tools/rustfmt/src/macros.rs index 527140eca3a18..e4c05d58004a7 100644 --- a/src/tools/rustfmt/src/macros.rs +++ b/src/tools/rustfmt/src/macros.rs @@ -27,6 +27,7 @@ use crate::config::StyleEdition; use crate::config::lists::*; use crate::expr::{RhsAssignKind, rewrite_array, rewrite_assign_rhs}; use crate::header::{HeaderPart, format_header}; +use crate::is_nightly_channel; use crate::lists::{ListFormatting, itemize_list, write_list}; use crate::overflow; use crate::parse::macros::cfg_select::{CfgSelectFormatPredicate, parse_cfg_select_arms}; @@ -247,7 +248,7 @@ fn rewrite_macro_inner( } } - if macro_name.ends_with("cfg_select!") { + if is_nightly_channel!() && macro_name.ends_with("cfg_select!") { match format_cfg_select(context, shape, mac.span(), ¯o_name, style, ts.clone()) { Ok(rw) => return Ok(rw), Err(err) => match err { diff --git a/src/tools/rustfmt/src/test/mod.rs b/src/tools/rustfmt/src/test/mod.rs index 29904c6c7765f..201a581549914 100644 --- a/src/tools/rustfmt/src/test/mod.rs +++ b/src/tools/rustfmt/src/test/mod.rs @@ -754,6 +754,15 @@ fn check_files(files: Vec, opt_config: &Option) -> (Vec Config { }; for (key, val) in &sig_comments { - if key != "target" && key != "config" && key != "unstable" { + if key != "target" && key != "config" && key != "unstable" && key != "stable" { config.override_value(key, val); if config.is_default(key) { warn!("Default value {} used explicitly for {}", val, key); diff --git a/src/tools/rustfmt/tests/source/cfg_select.rs b/src/tools/rustfmt/tests/source/cfg_select.rs index 794967afeb26b..26f276edeef6e 100644 --- a/src/tools/rustfmt/tests/source/cfg_select.rs +++ b/src/tools/rustfmt/tests/source/cfg_select.rs @@ -1,3 +1,4 @@ +// rustfmt-unstable: true // rustfmt-style_edition: 2024 // rustfmt-skip_children: true diff --git a/src/tools/rustfmt/tests/source/cfg_select_stable.rs b/src/tools/rustfmt/tests/source/cfg_select_stable.rs new file mode 100644 index 0000000000000..7f37a155cfcd0 --- /dev/null +++ b/src/tools/rustfmt/tests/source/cfg_select_stable.rs @@ -0,0 +1,10 @@ +// rustfmt-stable: true + +// While we gate the `cfg_select!` formatting behind the `is_nightly_channel!()` check +// this test helps ensure that we don't start formatting `cfg_select!` on the `stable` +// or `beta` release channels. It is intentionally formatted incorrectly. As soon as the +// `is_nightly_channel!()` gate is removed this will start formatting and we can remove this test. +cfg_select! ( + unix => 1, + windows => 1, +); diff --git a/src/tools/rustfmt/tests/target/cfg_select.rs b/src/tools/rustfmt/tests/target/cfg_select.rs index fa242c7d2062f..fa70ea80dad38 100644 --- a/src/tools/rustfmt/tests/target/cfg_select.rs +++ b/src/tools/rustfmt/tests/target/cfg_select.rs @@ -1,3 +1,4 @@ +// rustfmt-unstable: true // rustfmt-style_edition: 2024 // rustfmt-skip_children: true diff --git a/src/tools/rustfmt/tests/target/cfg_select_stable.rs b/src/tools/rustfmt/tests/target/cfg_select_stable.rs new file mode 100644 index 0000000000000..7f37a155cfcd0 --- /dev/null +++ b/src/tools/rustfmt/tests/target/cfg_select_stable.rs @@ -0,0 +1,10 @@ +// rustfmt-stable: true + +// While we gate the `cfg_select!` formatting behind the `is_nightly_channel!()` check +// this test helps ensure that we don't start formatting `cfg_select!` on the `stable` +// or `beta` release channels. It is intentionally formatted incorrectly. As soon as the +// `is_nightly_channel!()` gate is removed this will start formatting and we can remove this test. +cfg_select! ( + unix => 1, + windows => 1, +);