Skip to content
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

Incorrect help message in matching structs with .. on both ends #112188

Closed
lebedev opened this issue Jun 1, 2023 · 0 comments · Fixed by #112199
Closed

Incorrect help message in matching structs with .. on both ends #112188

lebedev opened this issue Jun 1, 2023 · 0 comments · Fixed by #112199
Labels
A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@lebedev
Copy link

lebedev commented Jun 1, 2023

Code

fn main() {
    struct Foo {
        x: i32,
    }

    let foo = Foo { x: 1 };
    match foo {
        Foo { .., x, .. } => (),
        _ => (),
    }
}

Current output

error: expected `}`, found `,`
 --> src\main.rs:8:17
  |
8 |         Foo { .., x, .. } => (),
  |               --^
  |               | |
  |               | expected `}`
  |               `..` must be at the end and cannot have a trailing comma
  |
help: move the `..` to the end of the field list
  |
8 -         Foo { .., x, .. } => (),
8 +         Foo { .., x,  , .. } => (),
  |

Desired output

The part in help:

8 -         Foo { .., x, .. } => (),
8 +         Foo { x, .. } => (),

Rationale and extra context

A suggestion that can be compiled is better than the one that can't be compiled.

Other cases

No response

Anything else?

No response

@lebedev lebedev added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jun 1, 2023
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Jun 6, 2023
…errors

Fix suggestion for matching struct with `..` on both ends

### Before This PR

```
error: expected `}`, found `,`
 --> src\main.rs:8:17
  |
8 |         Foo { .., x, .. } => (),
  |               --^
  |               | |
  |               | expected `}`
  |               `..` must be at the end and cannot have a trailing comma
  |
help: move the `..` to the end of the field list
  |
8 -         Foo { .., x, .. } => (),
8 +         Foo { .., x,  , .. } => (),
  |
```

### After This PR

```
error: expected `}`, found `,`
  --> tests/ui/parser/issue-112188.rs:11:17
   |
11 |     let Foo { .., x, .. } = f; //~ ERROR expected `}`, found `,`
   |               --^-
   |               | |
   |               | expected `}`
   |               `..` must be at the end and cannot have a trailing comma
   |               help: remove the starting `..`
```

Fixes rust-lang#112188.
@bors bors closed this as completed in 71a72ee Jun 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant