Skip to content

Commit a2ad3d0

Browse files
committed
Auto merge of #13064 - Veykril:rustfmt-err, r=Veykril
Log rustfmt parsing errors as warnings We unconditionally pass an edition parameter to rustfmt, for some crates this might fail rustfmt so instead of swallowing the error, at least Log it on a level that is logged by default so users won't be completely confused about it. See for context #10209 Closes #10209
2 parents 04c487d + 638755a commit a2ad3d0

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

crates/rust-analyzer/src/handlers.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1777,7 +1777,7 @@ fn run_rustfmt(
17771777

17781778
let line_index = snap.file_line_index(file_id)?;
17791779

1780-
let mut rustfmt = match snap.config.rustfmt() {
1780+
let mut command = match snap.config.rustfmt() {
17811781
RustfmtConfig::Rustfmt { extra_args, enable_range_formatting } => {
17821782
let mut cmd = process::Command::new(toolchain::rustfmt());
17831783
cmd.args(extra_args);
@@ -1842,12 +1842,12 @@ fn run_rustfmt(
18421842
}
18431843
};
18441844

1845-
let mut rustfmt = rustfmt
1845+
let mut rustfmt = command
18461846
.stdin(Stdio::piped())
18471847
.stdout(Stdio::piped())
18481848
.stderr(Stdio::piped())
18491849
.spawn()
1850-
.context(format!("Failed to spawn {:?}", rustfmt))?;
1850+
.context(format!("Failed to spawn {:?}", command))?;
18511851

18521852
rustfmt.stdin.as_mut().unwrap().write_all(file.as_bytes())?;
18531853

@@ -1866,7 +1866,11 @@ fn run_rustfmt(
18661866
// formatting because otherwise an error is surfaced to the user on top of the
18671867
// syntax error diagnostics they're already receiving. This is especially jarring
18681868
// if they have format on save enabled.
1869-
tracing::info!("rustfmt exited with status 1, assuming parse error and ignoring");
1869+
tracing::warn!(
1870+
?command,
1871+
%captured_stderr,
1872+
"rustfmt exited with status 1"
1873+
);
18701874
Ok(None)
18711875
}
18721876
_ => {

0 commit comments

Comments
 (0)