Skip to content

Remove impl PinCoerceUnsized for Pin #144896

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Darksonn
Copy link
Contributor

@Darksonn Darksonn commented Aug 4, 2025

The safety requirements for PinCoerceUnsized are essentially that the type does not have a malicious Deref or DerefMut impl. However, the Pin type is fundamental, so the end-user can provide their own implementation of DerefMut for Pin<&SomeLocalType>, so it's possible for Pin to have a malicious DerefMut impl.

Thus, remove the unsound implementation of PinCoerceUnsized for the Pin type.

This PR is a breaking change, but it fixes #85099.

@rustbot
Copy link
Collaborator

rustbot commented Aug 4, 2025

r? @fee1-dead

rustbot has assigned @fee1-dead.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Aug 4, 2025
@Darksonn Darksonn added the A-pin Area: Pin label Aug 4, 2025
@Darksonn
Copy link
Contributor Author

Darksonn commented Aug 4, 2025

Note that all other fundamental types that implement PinCoerceUnsized prevent this unsoundness by having an unconditional impl of either !DerefMut or DerefMut, both of which prevent the end user from providing an unsound impl of DerefMut.

Note that this also means that making Arc or Rc fundamental would be unsound unless an impl of !DerefMut is added.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-pin Area: Pin S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-libs Relevant to the library team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

A Pin unsoundness involving an impl DerefMut for Pin<&dyn LocalTrait>
3 participants