Skip to content
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

Rename ManuallyDrop::take to read #62198

Closed
wants to merge 2 commits into from
Closed

Conversation

CAD97
Copy link
Contributor

@CAD97 CAD97 commented Jun 28, 2019

Tracking issue: #55422

Renames ManuallyDrop::take to match ptr::read and MaybeUninit::read, and updates the documentation to more mirror MaybeUninit::read's documentation.

@rust-highfive
Copy link
Collaborator

r? @dtolnay

(rust_highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jun 28, 2019
@CAD97
Copy link
Contributor Author

CAD97 commented Jun 28, 2019

r? @SimonSapin

@Centril
Copy link
Contributor

Centril commented Jun 28, 2019

cc @RalfJung

@RalfJung
Copy link
Member

This is more consistent with MaybeUninit. I am not sure if that's what we want, but I proposed it, so I am curious what T-libs thinks. :)

@RalfJung RalfJung added the T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. label Jun 28, 2019
@cramertj
Copy link
Member

It's surprising to me that a method called read would mutate the container, especially to the point of leaving its contents in an invalid state.

@CAD97
Copy link
Contributor Author

CAD97 commented Jun 28, 2019

method called read would mutate the container

It doesn't actually mutate the container, just like ptr::read doesn't mutate what's behind the pointer. Rather, the state is changed logically (just like with ptr::read which logically moves the value out) without changing anything in memory.

I only used &mut slot.value because I already had &mut and forgot I didn't need it 😅. The only reason ManuallyDrop::read takes &mut currently rather than & like MaybeUninit::read is as a lint; it's almost certainly unsound to use if someone else has a reference as well. That said, MaybeUninit::read uses &self and ptr::read uses *const, so if the idea is to parallel those, this should probably use &slot as well.

The other option where we use take(&mut self) is treating ManuallyDrop as basically an untagged, unchecked Option with Deref sugar due to being Some 99.99% of its lifetime. The only time I expect this function will be used soundly is in drop(&mut self).

@RalfJung
Copy link
Member

That said, MaybeUninit::read uses &self and ptr::read uses *const, so if the idea is to parallel those, this should probably use &slot as well.

Good point, now I wonder if MaybeUninit::read should take &mut self...

@CAD97
Copy link
Contributor Author

CAD97 commented Jun 28, 2019

Relevant note: this method has just been mentioned in a blog post as take.

@RalfJung
Copy link
Member

The link seems to be broken?

@CAD97
Copy link
Contributor Author

CAD97 commented Jun 28, 2019

@RalfJung fixed (missing http:// messed up GitHub's URL parser)

@Centril
Copy link
Contributor

Centril commented Jun 28, 2019

Relevant note: this method has just been mentioned in a blog post as take.

I'm sure @pnkfelix could change that if need be when we decide. :)

@Dylan-DPC-zz
Copy link

ping from triage @SimonSapin any updates on this?

@CAD97
Copy link
Contributor Author

CAD97 commented Jul 24, 2019

Per #55422 (comment), MaybeUninit::read may get renamed, removing that reasoning for the rename. Whether the function gets called read or take, the documentation updates in this PR I think are a clear improvement.

I'm happy to remove the rename if we can agree take is the better name.

@wirelessringo
Copy link

Ping from triage. @SimonSapin any updates on this? Thanks.

@Dylan-DPC-zz
Copy link

can anyone from @rust-lang/libs review this?

@Dylan-DPC-zz Dylan-DPC-zz added S-waiting-on-team Status: Awaiting decision from the relevant subteam (see the T-<team> label). and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Aug 17, 2019
@CAD97 CAD97 closed this Oct 1, 2019
@CAD97 CAD97 deleted the ManullyDrop_read branch October 1, 2019 17:06
bors added a commit that referenced this pull request Jan 20, 2020
…ark-Simulacrum

Stabilize ManuallyDrop::take

Tracking issue: closes #55422
FCP merge: #55422 (comment)

Reclaims the doc improvements from closed #62198.

-----

Stable version is a simple change if necessary.

Proposal: [relnotes] (this changes how to best take advantage of `ManuallyDrop`, esp. wrt. `Drop::drop` and finalize-by-value members)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-team Status: Awaiting decision from the relevant subteam (see the T-<team> label). T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants