Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit d0df47f

Browse files
authored
Merge pull request rust-lang#3506 from rchaser53/issue-3505
fix not to emit version
2 parents 34bf137 + 15ab363 commit d0df47f

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

src/cargo-fmt/main.rs

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ fn execute() -> i32 {
7979
}
8080

8181
if matches.opt_present("version") {
82-
return handle_command_status(get_version(verbosity), &opts);
82+
return handle_command_status(get_version(), &opts);
8383
}
8484

8585
let strategy = CargoFmtStrategy::from_matches(&matches);
@@ -122,8 +122,24 @@ fn handle_command_status(status: Result<i32, io::Error>, opts: &getopts::Options
122122
}
123123
}
124124

125-
fn get_version(verbosity: Verbosity) -> Result<i32, io::Error> {
126-
run_rustfmt(&BTreeSet::new(), &[String::from("--version")], verbosity)
125+
fn get_version() -> Result<i32, io::Error> {
126+
let mut command = Command::new("rustfmt")
127+
.stdout(std::process::Stdio::inherit())
128+
.args(&[String::from("--version")])
129+
.spawn()
130+
.map_err(|e| match e.kind() {
131+
io::ErrorKind::NotFound => io::Error::new(
132+
io::ErrorKind::Other,
133+
"Could not run rustfmt, please make sure it is in your PATH.",
134+
),
135+
_ => e,
136+
})?;
137+
let result = command.wait()?;
138+
if result.success() {
139+
Ok(SUCCESS)
140+
} else {
141+
Ok(result.code().unwrap_or(SUCCESS))
142+
}
127143
}
128144

129145
fn format_crate(verbosity: Verbosity, strategy: &CargoFmtStrategy) -> Result<i32, io::Error> {

0 commit comments

Comments
 (0)