Skip to content

When encountering ... when .. is expected, parser should suggest the latter #46718

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
pnkfelix opened this issue Dec 13, 2017 · 1 comment
Closed

Comments

@pnkfelix
Copy link
Member

Consider the following code:

fn main() {
    struct S { one: u32, _two: u32 }
    match (S { one: 1, _two: 2 }) {
        S { one: 1, ... } => println!("oy"),
        _ => println!("no"),
    }
}

If you try to compile this, you get the following errors:

error: expected identifier, found `...`
 --> src/main.rs:4:21
  |
4 |         S { one: 1, ... } => println!("oy"),
  |                     ^^^

error[E0027]: pattern does not mention field `one`
 --> src/main.rs:4:9
  |
4 |         S { one: 1, ... } => println!("oy"),
  |         ^^^^^^^^^^^^^^^^^ missing field `one`

error[E0027]: pattern does not mention field `_two`
 --> src/main.rs:4:9
  |
4 |         S { one: 1, ... } => println!("oy"),
  |         ^^^^^^^^^^^^^^^^^ missing field `_two`

error: aborting due to 3 previous errors

See the bug?

Its because I used ... when I should have used ..

It would be nice if the compiler, in its ever friendly manner, suggested the latter to me.

@zackmdavis
Copy link
Member

I volunteer.

zackmdavis added a commit to zackmdavis/rust that referenced this issue Dec 14, 2017

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
This resolves rust-lang#46718.
zackmdavis added a commit to zackmdavis/rust that referenced this issue Dec 14, 2017
zackmdavis added a commit to zackmdavis/rust that referenced this issue Dec 14, 2017
Previously, if an error occured while parsing field patterns, we would
just return the error, discarding any field patterns that did
successfully parse, which sometimes resulted in spurious diagnostics. At
the cost of a little boilerplate (the repetitious `.map_err(|err|
((fields.clone(), etc), err))` is annoying and the present author is
sorry to say she could not do better), we can pack the
successfully-parsed field patterns into the error and use them.

This was inspired by rust-lang#46718.
zackmdavis added a commit to zackmdavis/rust that referenced this issue Dec 16, 2017
bors added a commit that referenced this issue Dec 16, 2017
…_pattern_ellipsis, r=petrochenkov

in which `..` is suggested for erroneous `...` in struct field patterns

Resolves #46718. Supersedes #46721.

r? @petrochenkov
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants