errors: use -Z terminal-width in JSON emitter
This commit makes the JSON emitter use `-Z terminal-width` in the "rendered" field of the JSON output. Signed-off-by: David Wood <david@davidtw.co>
This commit is contained in:
parent
14e65d5e95
commit
3678e5c97e
7 changed files with 96 additions and 7 deletions
9
src/test/ui/terminal-width/flag-human.rs
Normal file
9
src/test/ui/terminal-width/flag-human.rs
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
// compile-flags: -Z terminal-width=20
|
||||
|
||||
// This test checks that `-Z terminal-width` effects the human error output by restricting it to an
|
||||
// arbitrarily low value so that the effect is visible.
|
||||
|
||||
fn main() {
|
||||
let _: () = 42;
|
||||
//~^ ERROR mismatched types
|
||||
}
|
||||
11
src/test/ui/terminal-width/flag-human.stderr
Normal file
11
src/test/ui/terminal-width/flag-human.stderr
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
error[E0308]: mismatched types
|
||||
--> $DIR/flag-human.rs:7:17
|
||||
|
|
||||
LL | ..._: () = 42;
|
||||
| -- ^^ expected `()`, found integer
|
||||
| |
|
||||
| expected due to this
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0308`.
|
||||
9
src/test/ui/terminal-width/flag-json.rs
Normal file
9
src/test/ui/terminal-width/flag-json.rs
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
// compile-flags: -Z terminal-width=20 --error-format=json
|
||||
|
||||
// This test checks that `-Z terminal-width` effects the JSON error output by restricting it to an
|
||||
// arbitrarily low value so that the effect is visible.
|
||||
|
||||
fn main() {
|
||||
let _: () = 42;
|
||||
//~^ ERROR mismatched types
|
||||
}
|
||||
32
src/test/ui/terminal-width/flag-json.stderr
Normal file
32
src/test/ui/terminal-width/flag-json.stderr
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
{"message":"mismatched types","code":{"code":"E0308","explanation":"Expected type did not match the received type.
|
||||
|
||||
Erroneous code example:
|
||||
|
||||
```compile_fail,E0308
|
||||
let x: i32 = \"I am not a number!\";
|
||||
// ~~~ ~~~~~~~~~~~~~~~~~~~~
|
||||
// | |
|
||||
// | initializing expression;
|
||||
// | compiler infers type `&str`
|
||||
// |
|
||||
// type `i32` assigned to variable `x`
|
||||
```
|
||||
|
||||
This error occurs when the compiler is unable to infer the concrete type of a
|
||||
variable. It can occur in several cases, the most common being a mismatch
|
||||
between two types: the type the author explicitly assigned, and the type the
|
||||
compiler inferred.
|
||||
"},"level":"error","spans":[{"file_name":"$DIR/flag-json.rs","byte_start":244,"byte_end":246,"line_start":7,"line_end":7,"column_start":17,"column_end":19,"is_primary":true,"text":[{"text":" let _: () = 42;","highlight_start":17,"highlight_end":19}],"label":"expected `()`, found integer","suggested_replacement":null,"suggestion_applicability":null,"expansion":null},{"file_name":"$DIR/flag-json.rs","byte_start":239,"byte_end":241,"line_start":7,"line_end":7,"column_start":12,"column_end":14,"is_primary":false,"text":[{"text":" let _: () = 42;","highlight_start":12,"highlight_end":14}],"label":"expected due to this","suggested_replacement":null,"suggestion_applicability":null,"expansion":null}],"children":[],"rendered":"error[E0308]: mismatched types
|
||||
--> $DIR/flag-json.rs:7:17
|
||||
|
|
||||
LL | ..._: () = 42;
|
||||
| -- ^^ expected `()`, found integer
|
||||
| |
|
||||
| expected due to this
|
||||
|
||||
"}
|
||||
{"message":"aborting due to previous error","code":null,"level":"error","spans":[],"children":[],"rendered":"error: aborting due to previous error
|
||||
|
||||
"}
|
||||
{"message":"For more information about this error, try `rustc --explain E0308`.","code":null,"level":"failure-note","spans":[],"children":[],"rendered":"For more information about this error, try `rustc --explain E0308`.
|
||||
"}
|
||||
Loading…
Add table
Add a link
Reference in a new issue