-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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
Decide what to do about UnsafePinned
and safe Pin::deref
#137750
Comments
Regarding this bit:
@RalfJung: Does it work at all, and if so, how ugly would it be to otherwise treat |
It would defer the unsoundness, but safe code would still be allowed to do real source reads through the The difference is that the I believe that theoretically it would be coherent to add a Footnotes |
In SB, this is just plain impossible. In TB, we could treat such a reference like But... honestly it doesn't seem worth it. Allowing aliasing of |
As context, this entirely safe code is reported as UB by Miri under both Stacked Borrows and Tree Borrows:
Playground link
Output
Under TB:This isn't a bug in Miri really. It's a bug... elsewhere. Part of that is described by:
But at the same time, this is relevant to the post-RFC work on
UnsafePinned
:The idea of
UnsafePinned
is that we use it to wrap the fields subject to self-borrows so that given a mutable reference to such fields, the compiler (and our model) won't assume that a foreign write can't occur.But the RFC suggested that while
&mut UnsafePinned<T>
was special,&UnsafePinned<T>
wasn't, and would therefore act like&T
. This is where we've hit problems due to safePin::deref
, as @RalfJung has described:UnsafePinned
implementation [Part 1: Libs] #137043 (comment)In the above example, if the compiler were to insert:
Then we still end up having a problem, under the RFC's model and our current model behavior, which is (quoting @RalfJung):
What happens in the example is that:
u8
owned by the future.Unique
under TB.deref
creating a reference to the future and our behavior to treat that as a read of the entire future, a foreign read occurs, marking the mutable reference asFrozen
.About this, @RalfJung has said:
And also that:
Anyway, it seems we should have a canonical issue to use to decide about how to proceed about this and how either our model or RFC 3467 would need to be adjusted before the stabilization of
UnsafePinned
, so here is that issue.cc @RalfJung @WaffleLapkin @rust-lang/opsem @rust-lang/lang
@rustbot labels +T-lang +T-opsem +C-discussion +F-unsafe_pinned
The text was updated successfully, but these errors were encountered: