-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Missing comma when defaulting fields on a struct #96871
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
Comments
@rustbot claim |
Was able to reproduce this without using |
Looks like maybe a fix could be implemented in |
There's also this: rust/compiler/rustc_typeck/src/check/expr.rs Lines 1691 to 1694 in d4c3643
|
Using nightly in the playground example above, the slightly confusing error that mentions
This is spot on. See #94939 and #51103. There is arguably room for improvement here, but if this change from stable to nightly is improvement enough (and I think it is), I'm inclined to have this closed. @gilescope @estebank |
Yeah can’t ask for much more than that. Looking good.
…On Tue, 10 May 2022 at 22:01, pierwill ***@***.***> wrote:
Using nightly in the playground example above, the slightly confusing
error that mentions Range is followed by
error[[E0063]](https://doc.rust-lang.org/nightly/error-index.html#E0063): missing fields `n1` and `n2` in initializer of `A`
[--> src/main.rs:11:13
](https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021#) |
11 | let x = A {
| ^ missing `n1` and `n2`
|
help: to set the remaining fields from `x`, separate the last named field with a comma
|
13 | field2: String::from("yo"),
| +
This is spot on.
There is arguably room for improvement here, but if this change from
stable to nightly is improvement enough (and I think it is), I'm inclined
to have this closed. @gilescope <https://github.com./gilescope> @estebank
<https://github.com./estebank>
—
Reply to this email directly, view it on GitHub
<#96871 (comment)>,
or unsubscribe
<https://github.com./notifications/unsubscribe-auth/AAGEJCA673APSHCHNREDVF3VJLFB3ANCNFSM5VOTHOYA>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
I'm ok with closing as is, but would love it if you're still interested in looking into finding a way to improve this if we could silence the type mismatch error when encountering this case and only emit the later one that has the suggestion. |
I'll give this a look. 👍 |
Current output:
I'm gonna close as is. |
Context: You have an existing struct which has some fields defaulted. If you add another field but forget the comma like this:
Then currently rustc complains about a range. Here's a snapshot of an actual example:

It could be a legitimate range problem but in that situation it might very well be a missing comma.
The text was updated successfully, but these errors were encountered: