Desugaring of struct update syntax is unnecessarily restrictive for private fields #63538
Labels
C-feature-request
Category: A feature request, i.e: not implemented / a PR.
T-lang
Relevant to the language team, which will review and decide on the PR/issue.
Take the following example struct:
Let's say you don't have access to
b
, and you want to create an instance ofFoo
with a non-default value fora
. The idiomatic way to do that is with the struct update syntax, like so:Right now, that fails with the following error:
That error is unintuitive since we never directly reference
b
in our source code. What's more, it's entirely unnecessary, since it's merely the side effect of what seems to be the current desugaring strategy, as follows:Ideally we'd desugar to the following, which would allow the initial example to compile as expected:
This issue proposes moving to the second method. I can't see any disadvantages to doing that, although that may just be because I'm not looking close enough.
This admittedly changes the language's behavior, but I'm submitting it as an issue instead of an RFC because the current behavior seems unintentional and this is an extremely minor change. I'll happily create an RFC if that's necessary, though.
The text was updated successfully, but these errors were encountered: