Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/sourcegen/src/lib.rs')
-rw-r--r--crates/sourcegen/src/lib.rs13
1 files changed, 7 insertions, 6 deletions
diff --git a/crates/sourcegen/src/lib.rs b/crates/sourcegen/src/lib.rs
index 398e846a14..719b35b630 100644
--- a/crates/sourcegen/src/lib.rs
+++ b/crates/sourcegen/src/lib.rs
@@ -11,7 +11,7 @@ use std::{
path::{Path, PathBuf},
};
-use xshell::{cmd, pushenv};
+use xshell::{cmd, Shell};
pub fn list_rust_files(dir: &Path) -> Vec<PathBuf> {
let mut res = list_files(dir);
@@ -133,8 +133,8 @@ impl fmt::Display for Location {
}
}
-fn ensure_rustfmt() {
- let version = cmd!("rustfmt --version").read().unwrap_or_default();
+fn ensure_rustfmt(sh: &Shell) {
+ let version = cmd!(sh, "rustfmt --version").read().unwrap_or_default();
if !version.contains("stable") {
panic!(
"Failed to run rustfmt from toolchain 'stable'. \
@@ -144,10 +144,11 @@ fn ensure_rustfmt() {
}
pub fn reformat(text: String) -> String {
- let _e = pushenv("RUSTUP_TOOLCHAIN", "stable");
- ensure_rustfmt();
+ 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!("rustfmt --config-path {rustfmt_toml} --config fn_single_line=true")
+ let mut stdout = cmd!(sh, "rustfmt --config-path {rustfmt_toml} --config fn_single_line=true")
.stdin(text)
.read()
.unwrap();