-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Tracking issue for #![feature(maybe_uninit_ref)]
#63568
Comments
The reason these are unstable is that most of the time, people should use raw pointers for as long as possible. So the question remains whether these methods carry their weight. Of course, without rust-lang/rfcs#2582 it can be hard to avoid creating references. |
…fJung Adjust tracking issues for `MaybeUninit<T>` gates cc rust-lang#63566 rust-lang#63567 rust-lang#63568 rust-lang#63569 r? @RalfJung
…fJung Adjust tracking issues for `MaybeUninit<T>` gates cc rust-lang#63566 rust-lang#63567 rust-lang#63568 rust-lang#63569 r? @RalfJung
I'll repost here something that I posted in the old tracker issue, for the sake of visibility, and because it is something that remains, imho, relevant to the topic at hand: Unstable
Because of this, I imagine There are two / three options for this, related to the
impl<T> MaybeUninit<T> {
/// # Safety
///
/// - the contents must have been initialised
unsafe
fn assume_init_with_mut<R, F> (mut self: MaybeUninit<T>, f: F) -> R
where
F : FnOnce(&mut T) -> R,
{
if mem::needs_drop::<T>().not() {
return f(unsafe { self.get_mut() });
}
let mut this = ::scopeguard::guard(self, |mut this| {
ptr::drop_in_place(this.as_mut_ptr());
});
f(unsafe { MaybeUninit::<T>::get_mut(&mut *this) })
}
} (Where These could be stabilized faster than DrawbacksIf a variant of option |
I agree that these methods are useful after the value has been fully initialized, at which points references are valid not matter which way future language decisions go. However I think that dropping the value should be an entirely separate concern, and should not be conflated in the same APIs as obtaining a reference. |
Based on my previous comment, let’s? @rfcbot fcp merge |
Team member @SimonSapin has proposed to merge this. The next step is review by the rest of the tagged team members:
Concerns:
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. |
So, despite |
NamingI basically agree with @RalfJung's point in #63567 (comment) and I feel the answer to the question in #63567 (comment) is "yes". It seems appropriate to reflect the I would propose that we rename these to:
(I've tried to pick names that are clear but also not super long at the same time.) DocumentationSeparately, I think Two aspects should I think be clarified about these methods (with examples):
These are both examples of "assuming it is initialized before it is" but examples are helpful. (I think this should happen before we stabilize as it tends not to happen for some time otherwise. It is also the quality we have for other methods in the |
After thinking about this a bit, I think I agree with stabilization (subject to the concerns raised by @Centril). In particular when it comes to docs, the big advantage of having these methods compared to letting people do |
(And also I can be the one drafting the docs if you want |
@danielhenrymantilla Please do! And submit a PR to get feedback on the wording. |
Done (#65948), waiting on review: should I/we also update |
@rfcbot reviewed I like the functionality, and I'm happy with whatever names people agree on for things here. |
What are you proposing to update? |
In terms of naming, @Centril's |
…t_ref_mut, r=RalfJung Improve MaybeUninit::get_{ref,mut} documentation As mentioned in rust-lang#63568 (comment), `MaybeUninit`'s `get_{ref,mut}` documentation is lacking, so this PR attempts to fix that. That being said, and as @RalfJung mentions in that thread, > In particular, we should clarify that all the UB rules for these methods equally apply when calling the raw ptr methods and creating a reference manually. these other docs also need to be improved, which I can do in this PR ~~(hence the `[WIP]`)~~. Finally, since all these documentations are related to clearly establishing when dealing with uninitialized memory which patterns are known to be sound and which patterns are currently UB (that is, until, if ever, the rules around references to unintialized integers get relaxed, this documentation will treat them as UB, and advise against such patterns (_e.g._, it is not possible to use uninitialized buffers with the `Read` API)), I think that adding even more examples to the main documentation of `MaybeUninit` inherent definition wouldn't hurt either. ___ - [Rendered](http://dreamy-ritchie-99d637.netlify.com/core/mem/union.maybeuninit#method.get_ref)
This is the last remaining concern blocking the stabilization of the by-ref accessors of `MaybeUninit` (rust-lang#63568). This change of name not only does align with `.into_inner()` being called `.assume_init()`, it also conveys the dangerous semantics of the method in a much clearer and more direct way, reducing the change of misuse and thus of unsoundness.
I believe all of the documentation concerns in #63568 (comment) have been resolved as of #65948. @rfcbot resolve docs |
This should be ready for a stabilization PR as soon as the rename from MaybeUninit::get_{ref,mut} to MaybeUninit::assume_init_{ref,mut} goes through (#66174). I don't think we need to start a new checklist from the beginning. I expect everyone is either ambivalent about the name, prefers the new name, or would have spoken up already. But let me know if anyone would prefer otherwise! |
I agree with the renaming to include the |
@SimonSapin did you want to resolve the docs concern? I think @dtolnay tried to but you registered them =) |
@rfcbot resolve docs Did we decide on naming? |
I think we've sorta decided on naming but it seems like #66174 was closed unmerged. Maybe someone could pick up that work or it could be done as part of the stabilization PR? |
Applying the rename in the stabilization PR sounds ok to me, as long as we don’t forget to do it. @rfcbot resolve naming |
🔔 This is now entering its final comment period, as per the review above. 🔔 |
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. |
rename get_{ref, mut} to assume_init_{ref,mut} in Maybeuninit References rust-lang#63568 Rework with comments addressed from rust-lang#66174 Have replaced most of the occurrences I've found, hopefully didn't miss out anything r? @RalfJung (thanks @danielhenrymantilla for the initial work on this)
This is a tracking issue for the RFC "Deprecate
uninitialized
in favor of a newMaybeUninit
type" (rust-lang/rfcs#1892).This issue specifically tracks the following unstable methods:
(NOTE: on current nightly, these methods are still called
get_ref
andget_mut
, but the FCP here decided a rename.)The text was updated successfully, but these errors were encountered: