diff options
| author | flip1995 <philipp.krones@embecosm.com> | 2022-01-13 13:18:19 +0100 |
|---|---|---|
| committer | flip1995 <philipp.krones@embecosm.com> | 2022-01-13 13:18:19 +0100 |
| commit | fb0142ae41a49a4dda6bc0c7487efa00818c8f49 (patch) | |
| tree | 0b51b29d80477019cca389c9b053d0d04c8d74ee /clippy_dev/src | |
| parent | dda2aef64fb5b4903a28e5d4fb8d63483642cc6f (diff) | |
| download | rust-fb0142ae41a49a4dda6bc0c7487efa00818c8f49.tar.gz rust-fb0142ae41a49a4dda6bc0c7487efa00818c8f49.zip | |
Merge commit '97a5daa65908e59744e2bc625b14849352231c75' into clippyup
Diffstat (limited to 'clippy_dev/src')
| -rw-r--r-- | clippy_dev/src/fmt.rs | 32 | ||||
| -rw-r--r-- | clippy_dev/src/update_lints.rs | 2 |
2 files changed, 27 insertions, 7 deletions
diff --git a/clippy_dev/src/fmt.rs b/clippy_dev/src/fmt.rs index 9ceadee58ea..d513a229b7e 100644 --- a/clippy_dev/src/fmt.rs +++ b/clippy_dev/src/fmt.rs @@ -3,7 +3,7 @@ use itertools::Itertools; use shell_escape::escape; use std::ffi::{OsStr, OsString}; use std::path::Path; -use std::process::{self, Command}; +use std::process::{self, Command, Stdio}; use std::{fs, io}; use walkdir::WalkDir; @@ -31,6 +31,7 @@ impl From<walkdir::Error> for CliError { struct FmtContext { check: bool, verbose: bool, + rustfmt_path: String, } // the "main" function of cargo dev fmt @@ -102,7 +103,23 @@ Please revert the changes to Cargo.tomls first." } } - let context = FmtContext { check, verbose }; + let output = Command::new("rustup") + .args(["which", "rustfmt"]) + .stderr(Stdio::inherit()) + .output() + .expect("error running `rustup which rustfmt`"); + if !output.status.success() { + eprintln!("`rustup which rustfmt` did not execute successfully"); + process::exit(1); + } + let mut rustfmt_path = String::from_utf8(output.stdout).expect("invalid rustfmt path"); + rustfmt_path.truncate(rustfmt_path.trim_end().len()); + + let context = FmtContext { + check, + verbose, + rustfmt_path, + }; let result = try_run(&context); let code = match result { Ok(true) => 0, @@ -141,8 +158,12 @@ fn exec( println!("{}", format_command(&program, &dir, args)); } - let child = Command::new(&program).current_dir(&dir).args(args.iter()).spawn()?; - let output = child.wait_with_output()?; + let output = Command::new(&program) + .env("RUSTFMT", &context.rustfmt_path) + .current_dir(&dir) + .args(args.iter()) + .output() + .unwrap(); let success = output.status.success(); if !context.check && !success { @@ -159,7 +180,6 @@ fn exec( fn cargo_fmt(context: &FmtContext, path: &Path) -> Result<bool, CliError> { let mut args = vec!["fmt", "--all"]; if context.check { - args.push("--"); args.push("--check"); } let success = exec(context, "cargo", path, &args)?; @@ -200,7 +220,7 @@ fn rustfmt(context: &FmtContext, paths: impl Iterator<Item = OsString>) -> Resul } args.extend(paths); - let success = exec(context, "rustfmt", std::env::current_dir()?, &args)?; + let success = exec(context, &context.rustfmt_path, std::env::current_dir()?, &args)?; Ok(success) } diff --git a/clippy_dev/src/update_lints.rs b/clippy_dev/src/update_lints.rs index 8dd073ef405..d368ef1f46a 100644 --- a/clippy_dev/src/update_lints.rs +++ b/clippy_dev/src/update_lints.rs @@ -321,7 +321,7 @@ fn gen_register_lint_list<'a>( for (is_public, module_name, lint_name) in details { if !is_public { - output.push_str(" #[cfg(feature = \"internal-lints\")]\n"); + output.push_str(" #[cfg(feature = \"internal\")]\n"); } output.push_str(&format!(" {}::{},\n", module_name, lint_name)); } |
