You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
B-unstableBlocker: Implemented in the nightly compiler and unstable.C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCT-libs-api[DEPRECATED; DO NOT USE]disposition-mergeThis issue / PR is in PFCP or FCP with a disposition to merge it.finished-final-comment-periodThe final comment period is finished for this PR / Issue.
I am a bit worried about the name of this method being too innocent-looking. We have take as a safe method in other places, like Option and Iterator. This leaves the fact that the method is unsafe as the only safeguard -- which is a problem e.g. when this gets (accidentally) used inside an unsafe fn or in a large unsafe block.
I'd prefer a name that already indicates this to be a dangerous operation. Strawman: take_unchecked because it doesn't check you are taking twice?
Note that it has to be written as ManuallyDrop::take, which eliminates some of the risk of using a familiar name, as it's attached to ManuallyDrop, which is known to have interesting semantics, and thus is hard to use accidentally.
(Procedural note: I'll update OP with useful information soon.)
@RalfJung I’m sympathetic to this argument, but we also have ManuallyDrop::drop which is (almost) as innocent-looking, and also doesn’t check if we are dropping twice.
(I also notice that ManuallyDrop::into_inner is safe, even though it would be unsound to call after drop or take.)
So I’m inclined to FCP to stabilize as-is. Or do you feel strongly we should rename?
Anything that needs to be resolved for this to stabilize, libs?
I just ended up here because someone on discord was just using mem::replace(x, mem::uninitialized()) (😭) where hopefully they would have just used this if it were stable.
The corresponding (unstable) method on MaybeUninit is (currently) called "read", because the safety concerns are a lot like the ones of ptr::read. Would the same make sense here as well?
Documentation is updated and rename is done in #62198. I've also finally updated the OP with the proper details. I can roll stabilization into #62198 if desired, or it can be done separately of course.
I think this method is only reasonable only if we don't have MaybeUninit in stable. Practically we use ManuallyDrop when we need untagged Option, because we don't have any other way to prevent accidentally dropping invalid data. But now we have MaybeUninit in stable which exactly is for this purpose.
Is there some use case that can't be reasonably expressed using MaybeUninit?
@RalfJung So counter-argument to my "it should be clear" argument: How many people who are unfamiliar with ManuallyDrop read it and think "ah, drop flags!"?
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.
B-unstableBlocker: Implemented in the nightly compiler and unstable.C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCT-libs-api[DEPRECATED; DO NOT USE]disposition-mergeThis issue / PR is in PFCP or FCP with a disposition to merge it.finished-final-comment-periodThe final comment period is finished for this PR / Issue.
Activity
Rollup merge of rust-lang#55421 - CAD97:patch-1, r=kennytm
RalfJung commentedon Oct 29, 2018
I am a bit worried about the name of this method being too innocent-looking. We have
takeas a safe method in other places, likeOptionandIterator. This leaves the fact that the method isunsafeas the only safeguard -- which is a problem e.g. when this gets (accidentally) used inside anunsafe fnor in a largeunsafeblock.I'd prefer a name that already indicates this to be a dangerous operation. Strawman:
take_uncheckedbecause it doesn't check you are taking twice?CAD97 commentedon Oct 29, 2018
Note that it has to be written as
ManuallyDrop::take, which eliminates some of the risk of using a familiar name, as it's attached toManuallyDrop, which is known to have interesting semantics, and thus is hard to use accidentally.(Procedural note: I'll update OP with useful information soon.)
SimonSapin commentedon Feb 1, 2019
@RalfJung I’m sympathetic to this argument, but we also have
ManuallyDrop::dropwhich is (almost) as innocent-looking, and also doesn’t check if we are dropping twice.(I also notice that
ManuallyDrop::into_inneris safe, even though it would be unsound to call afterdroportake.)So I’m inclined to FCP to stabilize as-is. Or do you feel strongly we should rename?
RalfJung commentedon Feb 1, 2019
No, not very strongly. And not being able to say
foo.take()helps a lot.scottmcm commentedon Jun 27, 2019
Anything that needs to be resolved for this to stabilize, libs?
I just ended up here because someone on discord was just using
mem::replace(x, mem::uninitialized())(😭) where hopefully they would have just used this if it were stable.RalfJung commentedon Jun 27, 2019
The corresponding (unstable) method on
MaybeUninitis (currently) called "read", because the safety concerns are a lot like the ones ofptr::read. Would the same make sense here as well?SimonSapin commentedon Jun 27, 2019
This sounds reasonable. In fact both methods are implemented based on
ptr::read. We can repeat it again in the docs:@rust-lang/libs, what do you think?
CAD97 commentedon Jun 28, 2019
Documentation is updated and rename is done in #62198. I've also finally updated the OP with the proper details. I can roll stabilization into #62198 if desired, or it can be done separately of course.
HyeonuPark commentedon Jul 9, 2019
I think this method is only reasonable only if we don't have
MaybeUninitin stable. Practically we useManuallyDropwhen we need untaggedOption, because we don't have any other way to prevent accidentally dropping invalid data. But now we haveMaybeUninitin stable which exactly is for this purpose.Is there some use case that can't be reasonably expressed using
MaybeUninit?11 remaining items
petertodd commentedon Dec 22, 2019
@RalfJung So counter-argument to my "it should be clear" argument: How many people who are unfamiliar with
ManuallyDropread it and think "ah, drop flags!"?jyn514 commentedon Jan 8, 2020
IMO, anyone who sees
ManuallyDropandunsafealready knows there's something fishy going on, I don't think it needs to be reinforced by_unchecked.Amanieu commentedon Jan 9, 2020
I would like to stabilize this function as it is. For reference, here is the signature:
@rfcbot fcp merge
rfcbot commentedon Jan 9, 2020
Team member @Amanieu has proposed to merge 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.
CAD97 commentedon Jan 9, 2020
I went ahead and filed the stabilization PR at #68066 along with reclaimed doc improvements from the closed rename PR.
rfcbot commentedon Jan 10, 2020
🔔 This is now entering its final comment period, as per the review above. 🔔
rfcbot commentedon Jan 20, 2020
The final comment period, with a disposition to merge, 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.
The RFC will be merged soon.
Auto merge of #68066 - CAD97:stabilize-manuallydrop-take, r=Amanieu,M…