Skip to content

Commit 4aed83a

Browse files
authored
Unrolled build for #160998
Rollup merge of #160998 - ytmimi:nightly_only_cfg_select_formatting, r=jieyouxu rustfmt: restrict `cfg_select!` formatting to the `nightly` release channel Closes: #160944 `cfg_select!` formatting was implemented in #154202. The formatting diverged from what was outlined in the original Style FCP (rust-lang/style-team#201 (comment) and #144323 (comment)). Since the 1.99 beta is scheduled to branch from main on August 14 I want to get this nightly formatting gate out so that we can correct the formatting issues before we promote the formatting to the beta / stable release channels. Style Guide PR: #160967 r? @jieyouxu cc: @traviscross
2 parents 52d0866 + 0febbac commit 4aed83a

6 files changed

Lines changed: 34 additions & 2 deletions

File tree

src/tools/rustfmt/src/macros.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ use crate::config::StyleEdition;
2727
use crate::config::lists::*;
2828
use crate::expr::{RhsAssignKind, rewrite_array, rewrite_assign_rhs};
2929
use crate::header::{HeaderPart, format_header};
30+
use crate::is_nightly_channel;
3031
use crate::lists::{ListFormatting, itemize_list, write_list};
3132
use crate::overflow;
3233
use crate::parse::macros::cfg_select::{CfgSelectFormatPredicate, parse_cfg_select_arms};
@@ -247,7 +248,7 @@ fn rewrite_macro_inner(
247248
}
248249
}
249250

250-
if macro_name.ends_with("cfg_select!") {
251+
if is_nightly_channel!() && macro_name.ends_with("cfg_select!") {
251252
match format_cfg_select(context, shape, mac.span(), &macro_name, style, ts.clone()) {
252253
Ok(rw) => return Ok(rw),
253254
Err(err) => match err {

src/tools/rustfmt/src/test/mod.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -754,6 +754,15 @@ fn check_files(files: Vec<PathBuf>, opt_config: &Option<PathBuf>) -> (Vec<Format
754754
continue;
755755
}
756756

757+
if sig_comments.contains_key("stable") && is_nightly_channel!() {
758+
debug!(
759+
"Skipping '{}' because nightly introduces formatting changes. \
760+
Formatting should be stable on the `stable` channel.",
761+
file_name.display()
762+
);
763+
continue;
764+
}
765+
757766
debug!("Testing '{}'...", file_name.display());
758767

759768
match idempotent_check(&file_name, opt_config) {
@@ -824,7 +833,7 @@ fn read_config(filename: &Path) -> Config {
824833
};
825834

826835
for (key, val) in &sig_comments {
827-
if key != "target" && key != "config" && key != "unstable" {
836+
if key != "target" && key != "config" && key != "unstable" && key != "stable" {
828837
config.override_value(key, val);
829838
if config.is_default(key) {
830839
warn!("Default value {} used explicitly for {}", val, key);

src/tools/rustfmt/tests/source/cfg_select.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// rustfmt-unstable: true
12
// rustfmt-style_edition: 2024
23
// rustfmt-skip_children: true
34

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// rustfmt-stable: true
2+
3+
// While we gate the `cfg_select!` formatting behind the `is_nightly_channel!()` check
4+
// this test helps ensure that we don't start formatting `cfg_select!` on the `stable`
5+
// or `beta` release channels. It is intentionally formatted incorrectly. As soon as the
6+
// `is_nightly_channel!()` gate is removed this will start formatting and we can remove this test.
7+
cfg_select! (
8+
unix => 1,
9+
windows => 1,
10+
);

src/tools/rustfmt/tests/target/cfg_select.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// rustfmt-unstable: true
12
// rustfmt-style_edition: 2024
23
// rustfmt-skip_children: true
34

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// rustfmt-stable: true
2+
3+
// While we gate the `cfg_select!` formatting behind the `is_nightly_channel!()` check
4+
// this test helps ensure that we don't start formatting `cfg_select!` on the `stable`
5+
// or `beta` release channels. It is intentionally formatted incorrectly. As soon as the
6+
// `is_nightly_channel!()` gate is removed this will start formatting and we can remove this test.
7+
cfg_select! (
8+
unix => 1,
9+
windows => 1,
10+
);

0 commit comments

Comments
 (0)