You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
By passing the --error-format json to cargo rustc, we have error messages as JSON only for the finalrustc invocation. Any intermediary compilation will still output error messages in the human-readable format.
For example, if the file examples/foo.rs requires the library crate src/lib.rs which contains errors, then when compiling the library crate directly we get the error as JSON, but compiling the examples/foo target, we get the same error as human-readable output. The parser for rust error messages in Flycheck will choke, and we'll get a "suspicious state" error.
At this stage, there are two solutions, all with downsides.
We can pass the --error-format json option in RUSTFLAGS when invoking cargo. This way, all invocations of rustc by cargo will output their errors as JSON.
The downside is that using different RUSTFLAGS in successive invocation of cargo will trigger a recompilation. That is, if we pass RUSTFLAGS='--error-format json' to cargo in Flycheck, and the user manually calls cargo build after that, all dependencies will have to be recompiled. This can take time, especially for larger crates.
To avoid the downside of RUSTFLAGS, the --message-format json flag was recently added (see Add --message-format flag. rust-lang/cargo#3000) to cargo. By passing this flag, we can have JSON messages for all rustc invocations, without retriggerring compilation (because this flag is known by cargo to have no effect on compilation output).
The downside is that this flag was is currently not compatible with -Z no-trans on rust stable (see cargo rustc --message-format=json fails to parse stderr of rustc rust-lang/cargo#3390). It works on nightly, but requires a slight adjustment to the rust parser.
So option 2 is better, but will only be available once rust-lang/cargo#3390 is fixed and that fix has landed in stable, because I don't think we want to cut support for rust stable.
The text was updated successfully, but these errors were encountered:
By passing the
--error-format json
tocargo rustc
, we have error messages as JSON only for the finalrustc
invocation. Any intermediary compilation will still output error messages in the human-readable format.For example, if the file
examples/foo.rs
requires the library cratesrc/lib.rs
which contains errors, then when compiling the library crate directly we get the error as JSON, but compiling theexamples/foo
target, we get the same error as human-readable output. The parser for rust error messages in Flycheck will choke, and we'll get a "suspicious state" error.At this stage, there are two solutions, all with downsides.
We can pass the
--error-format json
option in RUSTFLAGS when invokingcargo
. This way, all invocations ofrustc
by cargo will output their errors as JSON.The downside is that using different RUSTFLAGS in successive invocation of cargo will trigger a recompilation. That is, if we pass
RUSTFLAGS='--error-format json'
to cargo in Flycheck, and the user manually callscargo build
after that, all dependencies will have to be recompiled. This can take time, especially for larger crates.To avoid the downside of RUSTFLAGS, the
--message-format json
flag was recently added (see Add --message-format flag. rust-lang/cargo#3000) to cargo. By passing this flag, we can have JSON messages for allrustc
invocations, without retriggerring compilation (because this flag is known by cargo to have no effect on compilation output).The downside is that this flag was is currently not compatible with
-Z no-trans
on rust stable (seecargo rustc --message-format=json
fails to parse stderr ofrustc
rust-lang/cargo#3390). It works on nightly, but requires a slight adjustment to the rust parser.So option 2 is better, but will only be available once rust-lang/cargo#3390 is fixed and that fix has landed in stable, because I don't think we want to cut support for rust stable.
The text was updated successfully, but these errors were encountered: