Skip to content

Commit c7706c6

Browse files
committed
Add ui test for struct construction by calling syntax
Signed-off-by: xizheyin <[email protected]>
1 parent ae8ab87 commit c7706c6

File tree

2 files changed

+85
-0
lines changed

2 files changed

+85
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
struct PersonOnlyName {
2+
name: String
3+
}
4+
5+
struct PersonWithAge {
6+
name: String,
7+
age: u8,
8+
height: u8,
9+
}
10+
11+
12+
13+
fn main() {
14+
let wilfred = PersonOnlyName("Name1".to_owned());
15+
//~^ ERROR expected function, tuple struct or tuple variant, found struct `PersonOnlyName` [E0423]
16+
17+
let bill = PersonWithAge( //~ ERROR expected function, tuple struct or tuple variant, found struct `PersonWithAge` [E0423]
18+
"Name2".to_owned(),
19+
20,
20+
180,
21+
);
22+
23+
let person = PersonWithAge("Name3".to_owned());
24+
//~^ ERROR expected function, tuple struct or tuple variant, found struct `PersonWithAge` [E0423]
25+
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
error[E0423]: expected function, tuple struct or tuple variant, found struct `PersonOnlyName`
2+
--> $DIR/struct-construct-with-call-issue-138931.rs:14:19
3+
|
4+
LL | / struct PersonOnlyName {
5+
LL | | name: String
6+
LL | | }
7+
| |_- `PersonOnlyName` defined here
8+
...
9+
LL | let wilfred = PersonOnlyName("Name1".to_owned());
10+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
11+
|
12+
help: use struct literal syntax instead of calling
13+
|
14+
LL - let wilfred = PersonOnlyName("Name1".to_owned());
15+
LL + let wilfred = PersonOnlyName{name: "Name1".to_owned()};
16+
|
17+
18+
error[E0423]: expected function, tuple struct or tuple variant, found struct `PersonWithAge`
19+
--> $DIR/struct-construct-with-call-issue-138931.rs:17:16
20+
|
21+
LL | / struct PersonWithAge {
22+
LL | | name: String,
23+
LL | | age: u8,
24+
LL | | height: u8,
25+
LL | | }
26+
| |_- `PersonWithAge` defined here
27+
...
28+
LL | let bill = PersonWithAge(
29+
| ________________^
30+
LL | | "Name2".to_owned(),
31+
LL | | 20,
32+
LL | | 180,
33+
LL | | );
34+
| |_____^
35+
|
36+
help: use struct literal syntax instead of calling
37+
|
38+
LL ~ let bill = PersonWithAge{
39+
LL ~ name: "Name2".to_owned(),
40+
LL ~ age: 20,
41+
LL ~ height: 180,
42+
LL ~ };
43+
|
44+
45+
error[E0423]: expected function, tuple struct or tuple variant, found struct `PersonWithAge`
46+
--> $DIR/struct-construct-with-call-issue-138931.rs:23:18
47+
|
48+
LL | / struct PersonWithAge {
49+
LL | | name: String,
50+
LL | | age: u8,
51+
LL | | height: u8,
52+
LL | | }
53+
| |_- `PersonWithAge` defined here
54+
...
55+
LL | let person = PersonWithAge("Name3".to_owned());
56+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use struct literal syntax instead: `PersonWithAge { name: val, age: val, height: val }`
57+
58+
error: aborting due to 3 previous errors
59+
60+
For more information about this error, try `rustc --explain E0423`.

0 commit comments

Comments
 (0)