-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Better error message for ..
in struct patterns not in last position
#49257
Comments
An alternative would be allowing Anyway, if someone wants to work on this issue, go ahead, otherwise I will fix it when I have some free time. |
I think that it should remain accepted only at the end, the same as in struct literals. Tuple patterns need the flexibility, but struct patterns are named, so there's no reason to every have it anywhere but the end. |
I'll take this. |
…trochenkov Better diagnostics for '..' pattern fragment not in the last position Fixes rust-lang#49257.
…trochenkov Better diagnostics for '..' pattern fragment not in the last position Fixes rust-lang#49257.
…trochenkov Better diagnostics for '..' pattern fragment not in the last position Fixes rust-lang#49257.
Since the
let P(.., y) = p;
syntax is allowed in unnamed patterns, people will try the same in named patterns,let P { .., y } = p;
,and it won't work. Right now the error isfollowed by other errors about "pattern does not mention field x". Test code playground link
Adding a clear error message should be pretty easy, just check if there is a comma after
DotDot
and display a better error message "..
must always be the last field, and it cannot have a trailing comma". Actually, I think this is the code that checks if..
is followed by a}
, so adding the,
check should be pretty straight-forward:rust/src/libsyntax/parse/parser.rs
Lines 3672 to 3677 in c19264f
The text was updated successfully, but these errors were encountered: