Skip to content

Commit dca57c6

Browse files
committed
Add ui test suggest-box-for-expr-field-issue-139631
Signed-off-by: xizheyin <[email protected]>
1 parent 414482f commit dca57c6

File tree

2 files changed

+58
-0
lines changed

2 files changed

+58
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
struct X {
2+
a: Box<u32>,
3+
}
4+
5+
struct Y {
6+
y: Box<u32>,
7+
}
8+
9+
fn main() {
10+
let a = 8;
11+
let v2 = X { a }; //~ ERROR mismatched types [E0308]
12+
let v3 = Y { y: a }; //~ ERROR mismatched types [E0308]
13+
let v4 = Y { a }; //~ ERROR struct `Y` has no field named `a` [E0560]
14+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
error[E0308]: mismatched types
2+
--> $DIR/suggest-box-for-expr-field-issue-139631.rs:11:18
3+
|
4+
LL | let v2 = X { a };
5+
| ^ expected `Box<u32>`, found integer
6+
|
7+
= note: expected struct `Box<u32>`
8+
found type `{integer}`
9+
= note: for more on the distinction between the stack and the heap, read https://doc.rust-lang.org/book/ch15-01-box.html, https://doc.rust-lang.org/rust-by-example/std/box.html, and https://doc.rust-lang.org/std/boxed/index.html
10+
help: store this in the heap by calling `Box::new`
11+
|
12+
LL | let v2 = X { Box::new(a) };
13+
| +++++++++ +
14+
15+
error[E0308]: mismatched types
16+
--> $DIR/suggest-box-for-expr-field-issue-139631.rs:12:21
17+
|
18+
LL | let v3 = Y { y: a };
19+
| ^ expected `Box<u32>`, found integer
20+
|
21+
= note: expected struct `Box<u32>`
22+
found type `{integer}`
23+
= note: for more on the distinction between the stack and the heap, read https://doc.rust-lang.org/book/ch15-01-box.html, https://doc.rust-lang.org/rust-by-example/std/box.html, and https://doc.rust-lang.org/std/boxed/index.html
24+
help: store this in the heap by calling `Box::new`
25+
|
26+
LL | let v3 = Y { y: Box::new(a) };
27+
| +++++++++ +
28+
29+
error[E0560]: struct `Y` has no field named `a`
30+
--> $DIR/suggest-box-for-expr-field-issue-139631.rs:13:18
31+
|
32+
LL | let v4 = Y { a };
33+
| ^ unknown field
34+
|
35+
help: a field with a similar name exists
36+
|
37+
LL - let v4 = Y { a };
38+
LL + let v4 = Y { y };
39+
|
40+
41+
error: aborting due to 3 previous errors
42+
43+
Some errors have detailed explanations: E0308, E0560.
44+
For more information about an error, try `rustc --explain E0308`.

0 commit comments

Comments
 (0)