Skip to content

Commit

Permalink
Auto merge of rust-lang#13064 - Veykril:rustfmt-err, r=Veykril
Browse files Browse the repository at this point in the history
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 rust-lang/rust-analyzer#10209

Closes rust-lang/rust-analyzer#10209
  • Loading branch information
bors committed Aug 19, 2022
2 parents 04c487d + 638755a commit a2ad3d0
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions crates/rust-analyzer/src/handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1777,7 +1777,7 @@ fn run_rustfmt(

let line_index = snap.file_line_index(file_id)?;

let mut rustfmt = match snap.config.rustfmt() {
let mut command = match snap.config.rustfmt() {
RustfmtConfig::Rustfmt { extra_args, enable_range_formatting } => {
let mut cmd = process::Command::new(toolchain::rustfmt());
cmd.args(extra_args);
Expand Down Expand Up @@ -1842,12 +1842,12 @@ fn run_rustfmt(
}
};

let mut rustfmt = rustfmt
let mut rustfmt = command
.stdin(Stdio::piped())
.stdout(Stdio::piped())
.stderr(Stdio::piped())
.spawn()
.context(format!("Failed to spawn {:?}", rustfmt))?;
.context(format!("Failed to spawn {:?}", command))?;

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

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

0 comments on commit a2ad3d0

Please sign in to comment.