-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Change NonNull::as_uninit_*
to take self by value (as opposed to reference), matching primitive pointers.
#96100
Conversation
reference to taking `self` by value. This is consistent with the methods of the same names on primitive pointers. The returned lifetime was already previously unbounded.
Hey! It looks like you've submitted a new PR for the library teams! If this PR contains changes to any Examples of
|
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @thomcc (or someone else) soon. Please see the contribution instructions for more information. |
I'm in favor (because using &self here can lead to having to cast away lifetimes for no reason), but this is an API change, so r? rust-lang/libs-api @rustbot label +T-libs-api -T-lib |
I just noticed |
Yes, I don't think anything can be done there. In #80771 I made them return unbounded lifetimes which avoids most of the issues, but going further than that can't be done without breaking code. |
Personally, I think it's better still for
But in that case, I think |
I think it's better to take by value. If we could change the others compatibly, I think we would. The fact that it will lead to an inconsistency in lints seems fairly minor, I doubt anybody would notice. |
Personally I am leaning slightly towards consistency with other NonNull methods, but don't have a strong opinion. Let's see what @rust-lang/libs-api says. |
Changing Aside from that, is there/what code actually breaks specifically because of the API change? (Is there a chance all the methods can be made consistent in a new edition? I can try to do a crater run) |
I don't think the change can be made. It would also break code that tries to pass |
I see, I didn't think about function pointers. That's fair enough |
Actually thinking about it more, I think it's better for |
I agree. That's also consistent with |
Right, but these are not consistent with the methods on pointer types, e.g. https://doc.rust-lang.org/nightly/core/primitive.pointer.html#method.as_uninit_mut So I don't know that consistency is an unambiguous argument. |
I'm reassigning this PR because I'm taking a break from the review rotation for a little while. Thank you for your patience. r? rust-lang/libs-api |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I prefer the signatures in this PR. I think it's fine to leave as_ref
/as_mut
alone and just change these.
Thanks @Raekye!
@bors r+ |
📌 Commit d5f96e6 has been approved by |
☀️ Test successful - checks-actions |
Finished benchmarking commit (03c8b0b): comparison url. Instruction count
Max RSS (memory usage)Results
CyclesResults
If you disagree with this performance assessment, please file an issue in rust-lang/rustc-perf. @rustbot label: -perf-regression Footnotes |
Copied from my comment on #75402:
I realized the change is trivial (if desired) so here I am creating my first PR. I think it's not a breaking change since (it's on nightly and)
NonNull
isCopy
; all previous usages of these methods takingself
by reference should continue to compile. However, it might cause warnings to appear on usages ofNonNull::as_uninit_mut
, which used to require the theNonNull
variable be declaredmut
, but now it's not necessary.