fix #102806, suggest use .. to fill in the rest of the fields of Struct

This commit is contained in:
yukang 2022-10-13 23:27:17 +08:00
parent 6718ea1cff
commit 1e25882944
5 changed files with 103 additions and 3 deletions

View file

@ -0,0 +1,22 @@
#![allow(dead_code)]
struct V3 {
x: f32,
y: f32,
z: f32,
}
fn pz(v: V3) {
let _ = V3 { z: 0.0, ...v};
//~^ ERROR expected `..`
//~| ERROR missing fields `x` and `y` in initializer of `V3`
let _ = V3 { z: 0.0, ... };
//~^ expected identifier
//~| ERROR missing fields `x` and `y` in initializer of `V3`
let _ = V3 { z: 0.0, ...Default::default() };
//~^ ERROR expected `..`
//~| ERROR missing fields `x` and `y` in initializer of `V3`
}
fn main() {}

View file

@ -0,0 +1,51 @@
error: expected `..`, found `...`
--> $DIR/issue-102806.rs:10:26
|
LL | let _ = V3 { z: 0.0, ...v};
| ^^^
|
help: use `..` to fill in the rest of the fields
|
LL | let _ = V3 { z: 0.0, ..v};
| ~~
error: expected identifier, found `...`
--> $DIR/issue-102806.rs:13:26
|
LL | let _ = V3 { z: 0.0, ... };
| -- ^^^ expected identifier
| |
| while parsing this struct
error: expected `..`, found `...`
--> $DIR/issue-102806.rs:17:26
|
LL | let _ = V3 { z: 0.0, ...Default::default() };
| ^^^
|
help: use `..` to fill in the rest of the fields
|
LL | let _ = V3 { z: 0.0, ..Default::default() };
| ~~
error[E0063]: missing fields `x` and `y` in initializer of `V3`
--> $DIR/issue-102806.rs:10:13
|
LL | let _ = V3 { z: 0.0, ...v};
| ^^ missing `x` and `y`
error[E0063]: missing fields `x` and `y` in initializer of `V3`
--> $DIR/issue-102806.rs:13:13
|
LL | let _ = V3 { z: 0.0, ... };
| ^^ missing `x` and `y`
error[E0063]: missing fields `x` and `y` in initializer of `V3`
--> $DIR/issue-102806.rs:17:13
|
LL | let _ = V3 { z: 0.0, ...Default::default() };
| ^^ missing `x` and `y`
error: aborting due to 6 previous errors
For more information about this error, try `rustc --explain E0063`.