Skip to content

Commit 38c1d6e

Browse files
committed
Revert "fix: do not assume rustup is installed in xtask codegen"
This reverts commit 7d9e4fc.
1 parent 5ca5d52 commit 38c1d6e

File tree

1 file changed

+15
-19
lines changed

1 file changed

+15
-19
lines changed

xtask/src/codegen.rs

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -126,31 +126,27 @@ impl fmt::Display for Location {
126126
}
127127
}
128128

129-
fn rustfmt_executable(sh: &Shell) -> &str {
130-
// First try explicitly requesting the stable channel via rustup in case nightly is being used by default,
131-
// then plain rustfmt in case rustup isn't being used to manage the compiler (e.g. when using Nix).
132-
for executable in ["rustup run stable rustfmt", "rustfmt"] {
133-
let version = cmd!(sh, "{executable} --version").read().unwrap_or_default();
134-
if version.contains("stable") {
135-
return executable;
136-
}
137-
}
138-
139-
panic!(
140-
"Failed to run rustfmt from toolchain 'stable'. \
129+
fn ensure_rustfmt(sh: &Shell) {
130+
let version = cmd!(sh, "rustup run stable rustfmt --version").read().unwrap_or_default();
131+
if !version.contains("stable") {
132+
panic!(
133+
"Failed to run rustfmt from toolchain 'stable'. \
141134
Please run `rustup component add rustfmt --toolchain stable` to install it.",
142-
);
135+
);
136+
}
143137
}
144138

145139
fn reformat(text: String) -> String {
146140
let sh = Shell::new().unwrap();
147-
let rustfmt_exe = rustfmt_executable(&sh);
141+
ensure_rustfmt(&sh);
148142
let rustfmt_toml = project_root().join("rustfmt.toml");
149-
let mut stdout =
150-
cmd!(sh, "{rustfmt_exe} --config-path {rustfmt_toml} --config fn_single_line=true")
151-
.stdin(text)
152-
.read()
153-
.unwrap();
143+
let mut stdout = cmd!(
144+
sh,
145+
"rustup run stable rustfmt --config-path {rustfmt_toml} --config fn_single_line=true"
146+
)
147+
.stdin(text)
148+
.read()
149+
.unwrap();
154150
if !stdout.ends_with('\n') {
155151
stdout.push('\n');
156152
}

0 commit comments

Comments
 (0)