Skip to content

Commit 3e41c8d

Browse files
committed
add JSON error-format UI test expectations
This checks in a baseline so that it's easy to see the diff when we change the output in a subsequent commit. These examples are from and for #53934.
1 parent 2596bc1 commit 3e41c8d

4 files changed

+326
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// compile-flags: --error-format pretty-json -Zunstable-options
2+
3+
struct Point { x: isize, y: isize }
4+
5+
fn main() {
6+
let p = Point { x: 1, y: 2 };
7+
let Point { .., y, } = p;
8+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
{
2+
"message": "expected `}`, found `,`",
3+
"code": null,
4+
"level": "error",
5+
"spans": [
6+
{
7+
"file_name": "$DIR/issue-53934-multiple-parts.rs",
8+
"byte_start": 166,
9+
"byte_end": 167,
10+
"line_start": 7,
11+
"line_end": 7,
12+
"column_start": 19,
13+
"column_end": 20,
14+
"is_primary": true,
15+
"text": [
16+
{
17+
"text": " let Point { .., y, } = p;",
18+
"highlight_start": 19,
19+
"highlight_end": 20
20+
}
21+
],
22+
"label": "expected `}`",
23+
"suggested_replacement": null,
24+
"suggestion_applicability": null,
25+
"expansion": null
26+
},
27+
{
28+
"file_name": "$DIR/issue-53934-multiple-parts.rs",
29+
"byte_start": 164,
30+
"byte_end": 167,
31+
"line_start": 7,
32+
"line_end": 7,
33+
"column_start": 17,
34+
"column_end": 20,
35+
"is_primary": false,
36+
"text": [
37+
{
38+
"text": " let Point { .., y, } = p;",
39+
"highlight_start": 17,
40+
"highlight_end": 20
41+
}
42+
],
43+
"label": "`..` must be at the end and cannot have a trailing comma",
44+
"suggested_replacement": null,
45+
"suggestion_applicability": null,
46+
"expansion": null
47+
}
48+
],
49+
"children": [
50+
{
51+
"message": "move the `..` to the end of the field list",
52+
"code": null,
53+
"level": "help",
54+
"spans": [
55+
{
56+
"file_name": "$DIR/issue-53934-multiple-parts.rs",
57+
"byte_start": 164,
58+
"byte_end": 168,
59+
"line_start": 7,
60+
"line_end": 7,
61+
"column_start": 17,
62+
"column_end": 21,
63+
"is_primary": true,
64+
"text": [
65+
{
66+
"text": " let Point { .., y, } = p;",
67+
"highlight_start": 17,
68+
"highlight_end": 21
69+
}
70+
],
71+
"label": null,
72+
"suggested_replacement": "",
73+
"suggestion_applicability": "MachineApplicable",
74+
"expansion": null
75+
},
76+
{
77+
"file_name": "$DIR/issue-53934-multiple-parts.rs",
78+
"byte_start": 171,
79+
"byte_end": 172,
80+
"line_start": 7,
81+
"line_end": 7,
82+
"column_start": 24,
83+
"column_end": 25,
84+
"is_primary": true,
85+
"text": [
86+
{
87+
"text": " let Point { .., y, } = p;",
88+
"highlight_start": 24,
89+
"highlight_end": 25
90+
}
91+
],
92+
"label": null,
93+
"suggested_replacement": ".. }",
94+
"suggestion_applicability": "MachineApplicable",
95+
"expansion": null
96+
}
97+
],
98+
"children": [],
99+
"rendered": null
100+
}
101+
],
102+
"rendered": "error: expected `}`, found `,`
103+
--> $DIR/issue-53934-multiple-parts.rs:7:19
104+
|
105+
LL | let Point { .., y, } = p;
106+
| --^
107+
| | |
108+
| | expected `}`
109+
| `..` must be at the end and cannot have a trailing comma
110+
help: move the `..` to the end of the field list
111+
|
112+
LL | let Point { y, .. } = p;
113+
| -- ^^^^
114+
115+
"
116+
}
117+
{
118+
"message": "aborting due to previous error",
119+
"code": null,
120+
"level": "error",
121+
"spans": [],
122+
"children": [],
123+
"rendered": "error: aborting due to previous error
124+
125+
"
126+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// compile-flags: --error-format pretty-json -Zunstable-options
2+
3+
fn main() {
4+
let xs = vec![String::from("foo")];
5+
let d: &Display = &xs;
6+
println!("{}", d);
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,185 @@
1+
{
2+
"message": "cannot find type `Display` in this scope",
3+
"code": {
4+
"code": "E0412",
5+
"explanation": "
6+
The type name used is not in scope.
7+
8+
Erroneous code examples:
9+
10+
```compile_fail,E0412
11+
impl Something {} // error: type name `Something` is not in scope
12+
13+
// or:
14+
15+
trait Foo {
16+
fn bar(N); // error: type name `N` is not in scope
17+
}
18+
19+
// or:
20+
21+
fn foo(x: T) {} // type name `T` is not in scope
22+
```
23+
24+
To fix this error, please verify you didn't misspell the type name, you did
25+
declare it or imported it into the scope. Examples:
26+
27+
```
28+
struct Something;
29+
30+
impl Something {} // ok!
31+
32+
// or:
33+
34+
trait Foo {
35+
type N;
36+
37+
fn bar(_: Self::N); // ok!
38+
}
39+
40+
// or:
41+
42+
fn foo<T>(x: T) {} // ok!
43+
```
44+
45+
Another case that causes this error is when a type is imported into a parent
46+
module. To fix this, you can follow the suggestion and use File directly or
47+
`use super::File;` which will import the types from the parent namespace. An
48+
example that causes this error is below:
49+
50+
```compile_fail,E0412
51+
use std::fs::File;
52+
53+
mod foo {
54+
fn some_function(f: File) {}
55+
}
56+
```
57+
58+
```
59+
use std::fs::File;
60+
61+
mod foo {
62+
// either
63+
use super::File;
64+
// or
65+
// use std::fs::File;
66+
fn foo(f: File) {}
67+
}
68+
# fn main() {} // don't insert it for us; that'll break imports
69+
```
70+
"
71+
},
72+
"level": "error",
73+
"spans": [
74+
{
75+
"file_name": "$DIR/issue-53934-multiple-substitutions.rs",
76+
"byte_start": 129,
77+
"byte_end": 136,
78+
"line_start": 5,
79+
"line_end": 5,
80+
"column_start": 13,
81+
"column_end": 20,
82+
"is_primary": true,
83+
"text": [
84+
{
85+
"text": " let d: &Display = &xs;",
86+
"highlight_start": 13,
87+
"highlight_end": 20
88+
}
89+
],
90+
"label": "not found in this scope",
91+
"suggested_replacement": null,
92+
"suggestion_applicability": null,
93+
"expansion": null
94+
}
95+
],
96+
"children": [
97+
{
98+
"message": "possible candidates are found in other modules, you can import them into scope",
99+
"code": null,
100+
"level": "help",
101+
"spans": [
102+
{
103+
"file_name": "$DIR/issue-53934-multiple-substitutions.rs",
104+
"byte_start": 65,
105+
"byte_end": 65,
106+
"line_start": 3,
107+
"line_end": 3,
108+
"column_start": 1,
109+
"column_end": 1,
110+
"is_primary": true,
111+
"text": [
112+
{
113+
"text": "fn main() {",
114+
"highlight_start": 1,
115+
"highlight_end": 1
116+
}
117+
],
118+
"label": null,
119+
"suggested_replacement": "use std::fmt::Display;
120+
121+
",
122+
"suggestion_applicability": "Unspecified",
123+
"expansion": null
124+
},
125+
{
126+
"file_name": "$DIR/issue-53934-multiple-substitutions.rs",
127+
"byte_start": 65,
128+
"byte_end": 65,
129+
"line_start": 3,
130+
"line_end": 3,
131+
"column_start": 1,
132+
"column_end": 1,
133+
"is_primary": true,
134+
"text": [
135+
{
136+
"text": "fn main() {",
137+
"highlight_start": 1,
138+
"highlight_end": 1
139+
}
140+
],
141+
"label": null,
142+
"suggested_replacement": "use std::path::Display;
143+
144+
",
145+
"suggestion_applicability": "Unspecified",
146+
"expansion": null
147+
}
148+
],
149+
"children": [],
150+
"rendered": null
151+
}
152+
],
153+
"rendered": "error[E0412]: cannot find type `Display` in this scope
154+
--> $DIR/issue-53934-multiple-substitutions.rs:5:13
155+
|
156+
LL | let d: &Display = &xs;
157+
| ^^^^^^^ not found in this scope
158+
help: possible candidates are found in other modules, you can import them into scope
159+
|
160+
LL | use std::fmt::Display;
161+
|
162+
LL | use std::path::Display;
163+
|
164+
165+
"
166+
}
167+
{
168+
"message": "aborting due to previous error",
169+
"code": null,
170+
"level": "error",
171+
"spans": [],
172+
"children": [],
173+
"rendered": "error: aborting due to previous error
174+
175+
"
176+
}
177+
{
178+
"message": "For more information about this error, try `rustc --explain E0412`.",
179+
"code": null,
180+
"level": "",
181+
"spans": [],
182+
"children": [],
183+
"rendered": "For more information about this error, try `rustc --explain E0412`.
184+
"
185+
}

0 commit comments

Comments
 (0)