Add into_inner and get_mut to Mutex and RwLock#29031
Conversation
|
r? @aturon (rust_highfive has picked a reviewer for you, use r? to override) |
There was a problem hiding this comment.
Also note that &T coerces to *T
There was a problem hiding this comment.
Done. (re: coercion, just doing &self.inner didn't type check for some reason---maybe some interaction with type inference.)
|
Other than the ptr::read stuff, this looks great! Really thorough. I'm not really qualified to review this kind of code, though. |
|
Thanks @gankro! I changed to |
|
Local (full) |
|
@aturon mentioned in a different bug he is going to be unavailable. r? @alexcrichton |
|
This shouldn't close #28968 if it is using it as a tracking issue. |
|
The libs team talked about this today, and the conclusion is that this is good to go. The changes we'd like to see, however, are:
let (a, b) = {
let Mutex { ref a, ref b } = self; // note exhaustive match
(ptr::read(a), ptr::read(b))
};
mem::forget(self);
|
|
@huonw Good point, I edited the description to not close the issue. @alexcrichton That all makes sense, I'll do all of that when I get back from work, thanks! |
|
@alexcrichton I implemented everything you asked for, please take a look. Thanks! |
There was a problem hiding this comment.
Ah as one final piece, could these #[inline] annotations be left out? These are pretty hefty functions and the inline shouldn't be needed anyway as a result of the generic parameter on Mutex
|
@alexcrichton Done and squashed. Don't feel strongly, but I had added The fact that it has a type param doesn't quite imply |
into_inner and get_mut to sync::Mutexinto_inner and get_mut to Mutex and RwLock
The implementation for `into_inner` was a bit more complex than I had hoped for---is there any simpler, less unsafe way of getting around the fact that one can't move out of a `Drop` struct? See #28968 and rust-lang/rfcs#1269 .
The implementation for
into_innerwas a bit more complex than I had hoped for---is there any simpler, less unsafe way of getting around the fact that one can't move out of aDropstruct?See #28968 and rust-lang/rfcs#1269 .