mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-01 11:31:15 +00:00
Revert "fix: do not assume rustup is installed in xtask codegen"
This reverts commit 7d9e4fcc07e5de94e37b73436147cdbbaa35dbdc.
This commit is contained in:
parent
5ca5d52697
commit
38c1d6e337
@ -126,28 +126,24 @@ impl fmt::Display for Location {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn rustfmt_executable(sh: &Shell) -> &str {
|
fn ensure_rustfmt(sh: &Shell) {
|
||||||
// First try explicitly requesting the stable channel via rustup in case nightly is being used by default,
|
let version = cmd!(sh, "rustup run stable rustfmt --version").read().unwrap_or_default();
|
||||||
// then plain rustfmt in case rustup isn't being used to manage the compiler (e.g. when using Nix).
|
if !version.contains("stable") {
|
||||||
for executable in ["rustup run stable rustfmt", "rustfmt"] {
|
|
||||||
let version = cmd!(sh, "{executable} --version").read().unwrap_or_default();
|
|
||||||
if version.contains("stable") {
|
|
||||||
return executable;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
panic!(
|
panic!(
|
||||||
"Failed to run rustfmt from toolchain 'stable'. \
|
"Failed to run rustfmt from toolchain 'stable'. \
|
||||||
Please run `rustup component add rustfmt --toolchain stable` to install it.",
|
Please run `rustup component add rustfmt --toolchain stable` to install it.",
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn reformat(text: String) -> String {
|
fn reformat(text: String) -> String {
|
||||||
let sh = Shell::new().unwrap();
|
let sh = Shell::new().unwrap();
|
||||||
let rustfmt_exe = rustfmt_executable(&sh);
|
ensure_rustfmt(&sh);
|
||||||
let rustfmt_toml = project_root().join("rustfmt.toml");
|
let rustfmt_toml = project_root().join("rustfmt.toml");
|
||||||
let mut stdout =
|
let mut stdout = cmd!(
|
||||||
cmd!(sh, "{rustfmt_exe} --config-path {rustfmt_toml} --config fn_single_line=true")
|
sh,
|
||||||
|
"rustup run stable rustfmt --config-path {rustfmt_toml} --config fn_single_line=true"
|
||||||
|
)
|
||||||
.stdin(text)
|
.stdin(text)
|
||||||
.read()
|
.read()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user