-
Notifications
You must be signed in to change notification settings - Fork 13.4k
proposal: Assign trait #4329
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
Labels
C-enhancement
Category: An issue proposing an enhancement or a PR with one.
Comments
I don't think that this is backwards incompatible. |
@pcwalton: agreed, this shouldn't break anything, it's just an extra method/trait |
just a bug, removing milestone/nomination. |
Tagging RFC. |
I think this would be better as a default method on |
RalfJung
added a commit
to RalfJung/rust
that referenced
this issue
May 22, 2025
enable clippy::as_conversions to fully rule out as-casts
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
At the moment,
a = b.clone()
is the way to copy-assign to a value in generic code (at least once there's a default implementation forCopy
able types, per #3313).If
a
is uninitialized, that's perfectly optimal. When the value is already initialized, assignment can often be done with fewer allocations; a list or chunked list can be partially or fully reused, and even a vector/string can often be reused if it's big enough.So, something like this (with a default impl for
Clone
able types):There's no need for any operator overload, since
a = b
is just an implicit copy or a move.The text was updated successfully, but these errors were encountered: