Skip to content

Commit d0353f5

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

File tree

2 files changed

+70
-0
lines changed

2 files changed

+70
-0
lines changed
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+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
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+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use struct literal syntax instead: `PersonOnlyName { name: val }`
11+
12+
error[E0423]: expected function, tuple struct or tuple variant, found struct `PersonWithAge`
13+
--> $DIR/struct-construct-with-call-issue-138931.rs:17:16
14+
|
15+
LL | / struct PersonWithAge {
16+
LL | | name: String,
17+
LL | | age: u8,
18+
LL | | height: u8,
19+
LL | | }
20+
| |_- `PersonWithAge` defined here
21+
...
22+
LL | let bill = PersonWithAge(
23+
| ________________^
24+
LL | | "Name2".to_owned(),
25+
LL | | 20,
26+
LL | | 180,
27+
LL | | );
28+
| |_____^ help: use struct literal syntax instead: `PersonWithAge { name: val, age: val, height: val }`
29+
30+
error[E0423]: expected function, tuple struct or tuple variant, found struct `PersonWithAge`
31+
--> $DIR/struct-construct-with-call-issue-138931.rs:23:18
32+
|
33+
LL | / struct PersonWithAge {
34+
LL | | name: String,
35+
LL | | age: u8,
36+
LL | | height: u8,
37+
LL | | }
38+
| |_- `PersonWithAge` defined here
39+
...
40+
LL | let person = PersonWithAge("Name3".to_owned());
41+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use struct literal syntax instead: `PersonWithAge { name: val, age: val, height: val }`
42+
43+
error: aborting due to 3 previous errors
44+
45+
For more information about this error, try `rustc --explain E0423`.

0 commit comments

Comments
 (0)