-
Notifications
You must be signed in to change notification settings - Fork 13.7k
Prevent downstream impl DerefMut for Pin<LocalType>
#145608
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
base: master
Are you sure you want to change the base?
Conversation
Prevent downstream impl DerefMut for Pin
This comment has been minimized.
This comment has been minimized.
We discussed this PR in today's standard library API meeting. Those present were on board with the approach, but it will be important to see a reasonably clean crater result and send PRs for any breakage, because not all downstream impls of DerefMut for Pin are necessarily unsound. The new implementation rules out correct as well as incorrect impls. Once crater is finished, we would like to do a libs-api FCP to surface this to the rest of the team. We noticed that the new pin::hidden::PinHelper type is now going to appear in diagnostics such as the pin-unsound-issue-85099-derefmut.stderr in this PR, but hopefully this mostly only happens when someone is doing funny business like writing their own DerefMut impl, and not for more typical use of Pin's methods and impls. |
Ok, let's see what crater says. But I don't think there are any valid use-cases for |
@craterbot check |
👌 Experiment ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more |
017ed97
to
9bb2a3a
Compare
Updating this with some additional tests for error messages. I'm not worried about (See individual commits for how the error messages change.) |
A slightly different implementation seems to give somewhat better errors: But let's wait for crater before we think about that further. |
impl DerefMut for Pin<LocalType>
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
@craterbot run mode=check-only start=master#8c32e313cccf7df531e2d49ffb8227bb92304aee end=try#c659ee110de67e82444e4b6c8407c1a9af9c2cf6 crates=https://crater-reports.s3.amazonaws.com/pr-145608-1/retry-regressed-list.txt |
👌 Experiment ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more |
🚧 Experiment ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more |
🎉 Experiment
Footnotes
|
lgtm and I agree that this is a good fix for #85099. Great job coming up with this solution. It's a lot nicer than adding some weird type system hack and has pretty much exactly the behavior we want. r=me after FCP My only open question is #145608 (comment) and whether we want the docs to lie. I guess @rust-lang/libs-api vibe is "yes, hiding the helper stuff is desirable". |
I still think there is the open question of whether we should use the current implementation, or the one mentioned in #145608 (comment). It seems like the other implementation produces better error messages. I believe the behavior is identical. |
if u go with the alternative impl we won't need to transmute anything 🤔 by changing the signature of |
It isn't easy to declare that signature in the trait, because right now |
Team member @traviscross has proposed to merge this. The next step is review by the rest of the tagged team members:
No concerns currently listed. Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up! cc @rust-lang/lang-advisors: FCP proposed for lang, please feel free to register concerns. |
ah btw, why does this FCP involve lang instead of only being a libs one 😅 😁 |
The type is special, given how we lean on it in the language. We take some interest in the core special types of the language. That's basically it. |
Writing an impl like this doesn't make a lot of sense and I'm fine removing the ability, especially given the clean crater run. Given the fact that Pin is @rfcbot reviewed |
@rfcbot reviewed So, I think this is very clever and we should land it. I also feel like this is an interesting case study -- there is obviously something missing at the language level that we ought to be expressing more clearly. But I'm not really clear on what it is. I'm also struggling a bit to express the requirements around this impl in 'plain english' terms. |
Add tests for deref on pin Tests split out from rust-lang#145608. r? `@lcnr`
The safety requirements for
PinCoerceUnsized
are essentially that the type does not have a maliciousDeref
orDerefMut
impl. However, thePin
type is fundamental, so the end-user can provide their own implementation ofDerefMut
forPin<&SomeLocalType>
, so it's possible forPin
to have a maliciousDerefMut
impl. This unsoundness is known as #85099.Unfortunately, this means that the implementation of
PinCoerceUnsized
forPin
is currently unsound. To fix that, modify the impl so that it becomes impossible for downstream crates to provide their own implementation ofDerefMut
forPin
by abusing a hidden struct that is not fundamental.This PR is a breaking change, but it fixes #85099. The PR supersedes #144896.
r? lcnr