diff options
| author | Esteban Küber <esteban@kuber.com.ar> | 2018-05-29 22:31:00 -0700 |
|---|---|---|
| committer | Esteban Küber <esteban@kuber.com.ar> | 2018-06-05 08:48:55 -0700 |
| commit | cbc70a0d68bae1d439eb679676c499d543e61396 (patch) | |
| tree | a9efe540a57f11894d8127b4686abb377a4b3178 /src/test | |
| parent | 8f4a5429c2cf7ce1f0a63f821484744024b364f1 (diff) | |
Improve diagnostics for incorrect `..` usage
When using `..` somewhere other than the end, parse the rest of the pattern correctly while still emitting an error. Add suggestions to either remove trailing `,` or moving the `..` to the end.
Diffstat (limited to 'src/test')
| -rw-r--r-- | src/test/ui/issue-49257.rs | 3 | ||||
| -rw-r--r-- | src/test/ui/issue-49257.stderr | 35 |
2 files changed, 35 insertions, 3 deletions
diff --git a/src/test/ui/issue-49257.rs b/src/test/ui/issue-49257.rs index edb4037d109..f288a2b2174 100644 --- a/src/test/ui/issue-49257.rs +++ b/src/test/ui/issue-49257.rs @@ -17,5 +17,8 @@ struct Point { x: u8, y: u8 } fn main() { let p = Point { x: 0, y: 0 }; + let Point { .., y, } = p; //~ ERROR expected `}`, found `,` let Point { .., y } = p; //~ ERROR expected `}`, found `,` + let Point { .., } = p; //~ ERROR expected `}`, found `,` + let Point { .. } = p; } diff --git a/src/test/ui/issue-49257.stderr b/src/test/ui/issue-49257.stderr index 6ca8d80fa2e..7c3e7df4a1f 100644 --- a/src/test/ui/issue-49257.stderr +++ b/src/test/ui/issue-49257.stderr @@ -1,9 +1,38 @@ error: expected `}`, found `,` --> $DIR/issue-49257.rs:20:19 | +LL | let Point { .., y, } = p; //~ ERROR expected `}`, found `,` + | --^ + | | | + | | expected `}` + | `..` must be at the end and cannot have a trailing comma +help: move the `..` to the end of the field list + | +LL | let Point { y, , .. } = p; //~ ERROR expected `}`, found `,` + | -- ^^^^^^ + +error: expected `}`, found `,` + --> $DIR/issue-49257.rs:21:19 + | LL | let Point { .., y } = p; //~ ERROR expected `}`, found `,` - | ^ `..` must be in the last position, and cannot have a trailing comma + | --^ + | | | + | | expected `}` + | `..` must be at the end and cannot have a trailing comma +help: move the `..` to the end of the field list + | +LL | let Point { y , .. } = p; //~ ERROR expected `}`, found `,` + | -- ^^^^^^ + +error: expected `}`, found `,` + --> $DIR/issue-49257.rs:22:19 + | +LL | let Point { .., } = p; //~ ERROR expected `}`, found `,` + | --^ + | | | + | | expected `}` + | | help: remove this comma + | `..` must be at the end and cannot have a trailing comma -error: aborting due to previous error +error: aborting due to 3 previous errors -For more information about this error, try `rustc --explain E0027`. |
