-
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>
🚧 Experiment ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more |
🎉 Experiment
|
It seems like there are no real regressions. |
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