Skip to content
Merged
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
3 changes: 2 additions & 1 deletion src/tools/rustfmt/src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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(), &macro_name, style, ts.clone()) {
Ok(rw) => return Ok(rw),
Err(err) => match err {
Expand Down
11 changes: 10 additions & 1 deletion src/tools/rustfmt/src/test/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -754,6 +754,15 @@ fn check_files(files: Vec<PathBuf>, opt_config: &Option<PathBuf>) -> (Vec<Format
continue;
}

if sig_comments.contains_key("stable") && is_nightly_channel!() {
debug!(
"Skipping '{}' because nightly introduces formatting changes. \
Formatting should be stable on the `stable` channel.",
file_name.display()
);
continue;
}

debug!("Testing '{}'...", file_name.display());

match idempotent_check(&file_name, opt_config) {
Expand Down Expand Up @@ -824,7 +833,7 @@ fn read_config(filename: &Path) -> 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);
Expand Down
1 change: 1 addition & 0 deletions src/tools/rustfmt/tests/source/cfg_select.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// rustfmt-unstable: true
// rustfmt-style_edition: 2024
// rustfmt-skip_children: true

Expand Down
10 changes: 10 additions & 0 deletions src/tools/rustfmt/tests/source/cfg_select_stable.rs
Original file line number Diff line number Diff line change
@@ -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,
);
1 change: 1 addition & 0 deletions src/tools/rustfmt/tests/target/cfg_select.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// rustfmt-unstable: true
// rustfmt-style_edition: 2024
// rustfmt-skip_children: true

Expand Down
10 changes: 10 additions & 0 deletions src/tools/rustfmt/tests/target/cfg_select_stable.rs
Original file line number Diff line number Diff line change
@@ -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,
);
Loading