about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorMatthias Krüger <matthias.krueger@famsik.de>2022-11-06 08:35:26 +0100
committerGitHub <noreply@github.com>2022-11-06 08:35:26 +0100
commit58f5d57b5d622c87af4aaba45ab434ebcd867b20 (patch)
treee33e2b4be37182e26e0b9101c6b2f4998efdc146 /src
parenta4ab2e064306c2c3e5b1d2efe1d5c0e1a6e0346a (diff)
parent28d82ddfc22bcbcef2ade0a3c75e6711475a9098 (diff)
downloadrust-58f5d57b5d622c87af4aaba45ab434ebcd867b20.tar.gz
rust-58f5d57b5d622c87af4aaba45ab434ebcd867b20.zip
Rollup merge of #103012 - chenyukang:fix-102806, r=davidtwco,compiler-errors
Suggest use .. to fill in the rest of the fields of Struct

Fixes #102806
Diffstat (limited to 'src')
-rw-r--r--src/test/ui/parser/issue-102806.rs25
-rw-r--r--src/test/ui/parser/issue-102806.stderr45
2 files changed, 70 insertions, 0 deletions
diff --git a/src/test/ui/parser/issue-102806.rs b/src/test/ui/parser/issue-102806.rs
new file mode 100644
index 00000000000..ba297bdc967
--- /dev/null
+++ b/src/test/ui/parser/issue-102806.rs
@@ -0,0 +1,25 @@
+#![allow(dead_code)]
+
+#[derive(Default)]
+struct V3 {
+    x: f32,
+    y: f32,
+    z: f32,
+}
+
+fn pz(v: V3) {
+    let _ = V3 { z: 0.0, ...v};
+    //~^ ERROR expected `..`
+
+    let _ = V3 { z: 0.0, ...Default::default() };
+    //~^ ERROR expected `..`
+
+    let _ = V3 { z: 0.0, ... };
+    //~^ expected identifier
+    //~| ERROR missing fields `x` and `y` in initializer of `V3`
+
+    let V3 { z: val, ... } = v;
+    //~^ ERROR expected field pattern
+}
+
+fn main() {}
diff --git a/src/test/ui/parser/issue-102806.stderr b/src/test/ui/parser/issue-102806.stderr
new file mode 100644
index 00000000000..6872b8bc0af
--- /dev/null
+++ b/src/test/ui/parser/issue-102806.stderr
@@ -0,0 +1,45 @@
+error: expected `..`, found `...`
+  --> $DIR/issue-102806.rs:11: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 `..`, found `...`
+  --> $DIR/issue-102806.rs:14: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: expected identifier, found `...`
+  --> $DIR/issue-102806.rs:17:26
+   |
+LL |     let _ = V3 { z: 0.0, ... };
+   |             --           ^^^ expected identifier
+   |             |
+   |             while parsing this struct
+
+error: expected field pattern, found `...`
+  --> $DIR/issue-102806.rs:21:22
+   |
+LL |     let V3 { z: val, ... } = v;
+   |                      ^^^ help: to omit remaining fields, use one fewer `.`: `..`
+
+error[E0063]: missing fields `x` and `y` in initializer of `V3`
+  --> $DIR/issue-102806.rs:17:13
+   |
+LL |     let _ = V3 { z: 0.0, ... };
+   |             ^^ missing `x` and `y`
+
+error: aborting due to 5 previous errors
+
+For more information about this error, try `rustc --explain E0063`.