-
Notifications
You must be signed in to change notification settings - Fork 13.7k
Make RefMut
Sync
#115157
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
Make RefMut
Sync
#115157
Conversation
r? @m-ou-se (rustbot has picked a reviewer for you, use r? to override) |
This comment has been minimized.
This comment has been minimized.
This is safe because a `&RefMut` cannot change the borrow flags. We cannot impl `Send` for `RefMut` because of `map_split()`; we cannot impl `Sync` for `Ref` because of `clone()`.
eb62f14
to
31718f0
Compare
Do you have a use case for this? Wouldn't it be better to just share the |
@m-ou-se I don't, but I think that we tend to impl traits as we can, no? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This precludes the addition of an API that transforms
&RefMut
toRef
, so we need to choose what we want.
I'd be interested in seeing a prototype of what a sound API for this might look like, to better understand what options we are closing off.
Is it fn(&'short RefMut<'long, T>) -> Ref<'short, T>
? I think I can see why that would be sound. The original RefMut
remains borrowed for 'short
, ensuring it cannot be used to mutate the T, consequently ensuring that no mutation of T is possible during 'short
so having other Ref
is okay.
And indeed, that would make it problematic to have RefMut<T>: Sync
because one could send &RefMut<T>
to 2 different threads, each of which performs the conversion to Ref
, racing on the reference count.
@dtolnay Yes, that is what I had in mind. |
@rust-lang/libs-api: Given that there is no known use case benefiting from Workaround: send the |
Team member @dtolnay has proposed to close 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! See this document for info about what commands tagged team members can give me. |
🔔 This is now entering its final comment period, as per the review above. 🔔 |
The final comment period, with a disposition to close, as per the review above, is now complete. As the automated representative of the governance process, I would like to thank the author for their work and everyone else who contributed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks anyway for the PR!
This is safe because a
&RefMut
cannot change the borrow flags.We cannot impl
Send
forRefMut
because ofmap_split()
; we cannot implSync
forRef
because ofclone()
.This is insta-stable and needs a FCP.
This precludes the addition of an API that transforms
&RefMut
toRef
, so we need to choose what we want.