Add ui test for struct construction by calling syntax
Signed-off-by: xizheyin <xizheyin@smail.nju.edu.cn>
This commit is contained in:
parent
ae8ab87de4
commit
d0353f5c7a
2 changed files with 70 additions and 0 deletions
25
tests/ui/structs/struct-construct-with-call-issue-138931.rs
Normal file
25
tests/ui/structs/struct-construct-with-call-issue-138931.rs
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
struct PersonOnlyName {
|
||||
name: String
|
||||
}
|
||||
|
||||
struct PersonWithAge {
|
||||
name: String,
|
||||
age: u8,
|
||||
height: u8,
|
||||
}
|
||||
|
||||
|
||||
|
||||
fn main() {
|
||||
let wilfred = PersonOnlyName("Name1".to_owned());
|
||||
//~^ ERROR expected function, tuple struct or tuple variant, found struct `PersonOnlyName` [E0423]
|
||||
|
||||
let bill = PersonWithAge( //~ ERROR expected function, tuple struct or tuple variant, found struct `PersonWithAge` [E0423]
|
||||
"Name2".to_owned(),
|
||||
20,
|
||||
180,
|
||||
);
|
||||
|
||||
let person = PersonWithAge("Name3".to_owned());
|
||||
//~^ ERROR expected function, tuple struct or tuple variant, found struct `PersonWithAge` [E0423]
|
||||
}
|
||||
|
|
@ -0,0 +1,45 @@
|
|||
error[E0423]: expected function, tuple struct or tuple variant, found struct `PersonOnlyName`
|
||||
--> $DIR/struct-construct-with-call-issue-138931.rs:14:19
|
||||
|
|
||||
LL | / struct PersonOnlyName {
|
||||
LL | | name: String
|
||||
LL | | }
|
||||
| |_- `PersonOnlyName` defined here
|
||||
...
|
||||
LL | let wilfred = PersonOnlyName("Name1".to_owned());
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use struct literal syntax instead: `PersonOnlyName { name: val }`
|
||||
|
||||
error[E0423]: expected function, tuple struct or tuple variant, found struct `PersonWithAge`
|
||||
--> $DIR/struct-construct-with-call-issue-138931.rs:17:16
|
||||
|
|
||||
LL | / struct PersonWithAge {
|
||||
LL | | name: String,
|
||||
LL | | age: u8,
|
||||
LL | | height: u8,
|
||||
LL | | }
|
||||
| |_- `PersonWithAge` defined here
|
||||
...
|
||||
LL | let bill = PersonWithAge(
|
||||
| ________________^
|
||||
LL | | "Name2".to_owned(),
|
||||
LL | | 20,
|
||||
LL | | 180,
|
||||
LL | | );
|
||||
| |_____^ help: use struct literal syntax instead: `PersonWithAge { name: val, age: val, height: val }`
|
||||
|
||||
error[E0423]: expected function, tuple struct or tuple variant, found struct `PersonWithAge`
|
||||
--> $DIR/struct-construct-with-call-issue-138931.rs:23:18
|
||||
|
|
||||
LL | / struct PersonWithAge {
|
||||
LL | | name: String,
|
||||
LL | | age: u8,
|
||||
LL | | height: u8,
|
||||
LL | | }
|
||||
| |_- `PersonWithAge` defined here
|
||||
...
|
||||
LL | let person = PersonWithAge("Name3".to_owned());
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use struct literal syntax instead: `PersonWithAge { name: val, age: val, height: val }`
|
||||
|
||||
error: aborting due to 3 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0423`.
|
||||
Loading…
Add table
Add a link
Reference in a new issue