Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run stable fmt & cargo through rustup #12953

Merged
merged 1 commit into from
Aug 6, 2022
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
7 changes: 3 additions & 4 deletions crates/rust-analyzer/tests/slow-tests/tidy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,18 @@ use xshell::cmd;
fn check_code_formatting() {
let sh = &Shell::new().unwrap();
sh.change_dir(sourcegen::project_root());
sh.set_var("RUSTUP_TOOLCHAIN", "stable");

let out = cmd!(sh, "rustfmt --version").read().unwrap();
let out = cmd!(sh, "rustup run stable rustfmt --version").read().unwrap();
if !out.contains("stable") {
panic!(
"Failed to run rustfmt from toolchain 'stable'. \
Please run `rustup component add rustfmt --toolchain stable` to install it.",
)
}

let res = cmd!(sh, "cargo fmt -- --check").run();
let res = cmd!(sh, "rustup run stable cargo fmt -- --check").run();
if res.is_err() {
let _ = cmd!(sh, "cargo fmt").run();
let _ = cmd!(sh, "rustup run stable cargo fmt").run();
}
res.unwrap()
}
Expand Down
14 changes: 8 additions & 6 deletions crates/sourcegen/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ impl fmt::Display for Location {
}

fn ensure_rustfmt(sh: &Shell) {
let version = cmd!(sh, "rustfmt --version").read().unwrap_or_default();
let version = cmd!(sh, "rustup run stable rustfmt --version").read().unwrap_or_default();
if !version.contains("stable") {
panic!(
"Failed to run rustfmt from toolchain 'stable'. \
Expand All @@ -147,13 +147,15 @@ fn ensure_rustfmt(sh: &Shell) {

pub fn reformat(text: String) -> String {
let sh = Shell::new().unwrap();
sh.set_var("RUSTUP_TOOLCHAIN", "stable");
ensure_rustfmt(&sh);
let rustfmt_toml = project_root().join("rustfmt.toml");
let mut stdout = cmd!(sh, "rustfmt --config-path {rustfmt_toml} --config fn_single_line=true")
.stdin(text)
.read()
.unwrap();
let mut stdout = cmd!(
sh,
"rustup run stable rustfmt --config-path {rustfmt_toml} --config fn_single_line=true"
)
.stdin(text)
.read()
.unwrap();
if !stdout.ends_with('\n') {
stdout.push('\n');
}
Expand Down