Skip to content

Per-byte handling for UnsafePinned#4954

Closed
LaneAsade wants to merge 1 commit intorust-lang:masterfrom
LaneAsade:unsafe_pinned
Closed

Per-byte handling for UnsafePinned#4954
LaneAsade wants to merge 1 commit intorust-lang:masterfrom
LaneAsade:unsafe_pinned

Conversation

@LaneAsade
Copy link
Copy Markdown

@LaneAsade LaneAsade commented Apr 10, 2026

Fixes #4819

This PR ensures that UnsafePinned is handled in per-byte way just like UnsafeCell by adding a check for UnsafePinned alongside the existing UnsafeCell check in visit_value. This makes sure that only the bytes actually covered by the UnsafePinned opt out and not the entire allocation.

@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Apr 10, 2026

Thank you for contributing to Miri! A reviewer will take a look at your PR, typically within a week or two.
Please remember to not force-push to the PR branch except when you need to rebase due to a conflict or when the reviewer asks you for it.

@rustbot rustbot added the S-waiting-on-review Status: Waiting for a review to complete label Apr 10, 2026
@RalfJung
Copy link
Copy Markdown
Member

Thanks! However, I think it is too early for this. We currently still honor the Unpin trait, for which it is rather unclear what it even means to do things per-byte. We have to first land rust-lang/rust#152946 before we can remove the Unpin hack from Miri, and then we can consider doing per-byte UnsafePinned.

Also, this PR treats UnsafeCell and UnsafePinned the same, which I don't think is right.
And finally, the test doesn't actually test anything. The same code already gets accepted by today's Miri.

@RalfJung RalfJung closed this Apr 14, 2026
@rustbot rustbot removed the S-waiting-on-review Status: Waiting for a review to complete label Apr 14, 2026
@LaneAsade
Copy link
Copy Markdown
Author

No worries! I was actually confused by UnsafeCell and UnsafePinned because it seemed like there weren't any differences between them. I genuinely thought that was how it was. Maybe its cuz I couldn't find a lot of information regarding UnsafePinned. I would love to work on this once #152946 is done (Of course, only after I have a full understanding of miri internals). Also, sorry for the trouble you went through to review my PR.

@RalfJung
Copy link
Copy Markdown
Member

RalfJung commented Apr 14, 2026

I was actually confused by UnsafeCell and UnsafePinned because it seemed like there weren't any differences between them.

As a general rule, please always point out your confusions when submitting a PR. The people reviewing your PRs will thank you. :)

@LaneAsade
Copy link
Copy Markdown
Author

Yes, I will keep that in mind from now on. Thank you for the advice. Again, I apologize for any inconvenience caused.

@RalfJung
Copy link
Copy Markdown
Member

No worries. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Make UnsafePinned handling properly per-byte

3 participants