Proposal: Remove arbitrary_self_types_pointers feature#157936
Conversation
Drop support for raw pointer receivers (`*const Self`/`*mut Self`) from arbitrary self types. This removes the `arbitrary_self_types_pointers` feature gate completely.
|
cc @rust-lang/miri
cc @rust-lang/rust-analyzer |
|
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @dingxiangfei2009 (or someone else) some time within the next two weeks. Please see the contribution instructions for more information. Namely, in order to ensure the minimum review times lag, PR authors and assigned reviewers should ensure that the review label (
|
|
Has this been MCP'd / discussed on a team level before? The tracking issue does not seem to contain any such discussion. What motivated you to propose this change, out of the blue, as your first PR for Rust? Raw pointer receivers could help in improving the ergonomics of working with raw pointers -- and that is an area that desperately needs improvement. So removing them does not seem like a step in the right direction. What happens with stable methods that have raw ptr receivers, such as this? |
Where does this test do auto-deref? Your patch for that file turns a raw pointer into a reference. Obviously that requires unsafe. This does not confirm your claim.
That would be a soundness bug. Do you have an example for this? What is your source for this claim? Note that generally we expect PR summaries to be written by the PR author. LLMs tend to generate incorrect and/or useless summaries. Your summary seems to contain factual mistakes, making it likely that you copied it without fact-checking it yourself. Please do not do that, it is disrespectful of maintainer's time. |
|
The job Click to see the possible cause of the failure (guessed by this bot)For more information how to resolve CI failures of this job, visit this link. |
|
Thanks a lot for your comments, @RalfJung!
I am not aware of any previous discussion on this issue. I was talking with @dingxiangfei2009 about how I was interested in contributing to the language, and he suggested that this might be a good first issue to start on. The point of this PR is not to land right away but to start a discussion. Hence the "Proposal".
My apologies, while I have used LLMs for parts of the PR description, the statements you mention and the factual mistakes you call out are explicitly mine and written by me. I honestly didn't expect anybody but Xiang to look at it yet, so I thought we could discuss how we want to move this forward and I could iterate on the description over the next couple of days. |
This PR proposes the complete removal of the unstable feature
arbitrary_self_types_pointers.1. Introduction
The
arbitrary_self_types_pointersfeature (tracked under the same issue asarbitrary_self_types- #44874) was introduced to extend the arbitrary self types mechanism to raw pointers, allowing methods to be declared with and resolved throughself: *const Selforself: *mut Selfreceivers.We propose removing this feature entirely.
2. What the feature allows right now
Currently, with
#![feature(arbitrary_self_types_pointers)]enabled, the compiler allows:3. Removal motivation
There are several design and safety issues with allowing raw pointer receivers:
Receiverguidelines: Raw pointers do not implement theReceivertrait, and their support was hardcoded directly into the compiler's well-formedness checks (wfcheck.rs) and method resolution search (probe.rs). This breaks the principle that arbitrary self types should be driven by theReceivertrait.unsafe. See for example the testtests/ui/cast/ptr-to-trait-obj-different-regions-lt-ext.rsthat, after the feature removal, now requiresunsafeto be used.tests/ui/self/arbitrary_self_types_niche_deshadowing.rs.4. Risk / Impact
Receiver(which is the recommended practice).#44874
r? @dingxiangfei2009