-
Notifications
You must be signed in to change notification settings - Fork 13.1k
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
Implement Deref{Mut} for arrays #108650
Implement Deref{Mut} for arrays #108650
Conversation
r? @Nilstrieb (rustbot has picked a reviewer for you, use r? to override) |
Hey! It looks like you've submitted a new PR for the library teams! If this PR contains changes to any Examples of
|
@compiler-errors on the compiler part, for the rest |
Some changes occurred in src/tools/clippy cc @rust-lang/clippy |
Not sure if this might be a T-lang thing as well, since arrays now participate in deref coercions (and arrays being a language type opposed to library) |
I actually tried to implement this back in #92652. I don't think it makes sense to implement Deref in this case anymore, since array -> slice is an unsize coercion. Regardless, needs an ACP from T-libs-api I think? https://std-dev-guide.rust-lang.org/feature-lifecycle/api-change-proposals.html |
Guess I wasn't looking thoroughly enough for a previous PR :) I can see the reasoning behind why not to add this from eddy's comment. Turns out this is even the third PR trying to do this, I wonder if it makes sense to add a comment somewhere that states as to why we don't want this impl? |
The job Click to see the possible cause of the failure (guessed by this bot)
|
Now that we have const generics, there shouldn't really be a reason for arrays not to implement
Deref
/DerefMut
anymore (to my knowledge). So this PR is an attempt in making that work.With this, arrays now participate in deref coercions.
Unfortunately we still need to special case arrays in method probing, as unsizing can be always done in a const context while deref cannot on stable and currently the compiler will prefer dereferencing over unsizing. Of note is that once
Deref
is stably const, the unsizing step can (probably, not tested) be fully removed, meaningUnsize
adjustments no longer need to happen for arrays)Fixes #62992