Skip to content

Commit 8edb111

Browse files
Merge pull request #22074 from A4-Tacks/xtask-rsfmt-toolchain
internal: support RUSTFMT_TOOLCHAIN for xtask codegen
2 parents a52fa8d + 70e4af2 commit 8edb111

1 file changed

Lines changed: 7 additions & 6 deletions

File tree

xtask/src/codegen.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -130,16 +130,17 @@ impl fmt::Display for Location {
130130
fn reformat(text: String) -> String {
131131
let sh = Shell::new().unwrap();
132132
let rustfmt_toml = project_root().join("rustfmt.toml");
133-
let version = cmd!(sh, "rustup run stable rustfmt --version").read().unwrap_or_default();
133+
let toolchain = &std::env::var("RUSTFMT_TOOLCHAIN").unwrap_or("stable".to_owned());
134+
let version = cmd!(sh, "rustup run {toolchain} rustfmt --version").read().unwrap_or_default();
134135

135136
// First try explicitly requesting the stable channel via rustup in case nightly is being used by default,
136137
// then plain rustfmt in case rustup isn't being used to manage the compiler (e.g. when using Nix).
137-
let mut stdout = if !version.contains("stable") {
138+
let mut stdout = if !version.contains(toolchain) {
138139
let version = cmd!(sh, "rustfmt --version").read().unwrap_or_default();
139-
if !version.contains("stable") {
140+
if !version.contains(toolchain) {
140141
panic!(
141-
"Failed to run rustfmt from toolchain 'stable'. \
142-
Please run `rustup component add rustfmt --toolchain stable` to install it.",
142+
"Failed to run rustfmt from toolchain '{toolchain}'. \
143+
Please run `rustup component add rustfmt --toolchain {toolchain}` to install it.",
143144
);
144145
} else {
145146
cmd!(sh, "rustfmt --config-path {rustfmt_toml} --config fn_single_line=true")
@@ -150,7 +151,7 @@ fn reformat(text: String) -> String {
150151
} else {
151152
cmd!(
152153
sh,
153-
"rustup run stable rustfmt --config-path {rustfmt_toml} --config fn_single_line=true"
154+
"rustup run {toolchain} rustfmt --config-path {rustfmt_toml} --config fn_single_line=true"
154155
)
155156
.stdin(text)
156157
.read()

0 commit comments

Comments
 (0)