-
Notifications
You must be signed in to change notification settings - Fork 967
Description
Whenever rustfmt encounters a condition that results in an eprint/eprintln invocation while formatting multiple files, when using the json emit mode the output in the terminal can be invalid json due to the error text splitting apart the json object.
Technically stdout will contain the valid json result, and stderr the warnings and errors. However, I believe the emitter can be tweaked so that the full/valid json representation of the formatting results can be displayed to users in the terminal without being broken and invalidated.
This is very similar to #1635, but opening as a separate issue for tracking/visbility and because I believe I have a solution for this problem that is emitter-specific.
To reproduce, use any input file that will err on formatting and that also includes a mod defined in another file. For example:
src/lib.rs
mod bar;
fn foo() {
// This line is extra long, and doesn't fit within 100 max_width. 1234567890123456789 aBcDeFgHiffffffffffffffffffffffffffffffffffffffffffffffffffffffffJ
let x = 0;
}src/bar.rs
pub(crate) fn do_baz() -> bool {
false
}with rustfmt.toml:
error_on_line_overflow = true
error_on_unformatted = trueThen run cargo fmt or rustfmt in recursive/non-skip_children mode:
$ rustfmt ./src/lib.rs --emit jsonand then notice the error displayed with the json object for the two respective files that makes the larger json output invalid
error[internal]: line formatted, but exceeded maximum width (maximum: 100 (see max_width option), found: 253)