Skip to content

assume_init: warn about valid != safe #63298

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

Merged
merged 3 commits into from
Aug 6, 2019
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion src/libcore/mem/maybe_uninit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ use crate::mem::ManuallyDrop;
///
/// On top of that, remember that most types have additional invariants beyond merely
/// being considered initialized at the type level. For example, a `1`-initialized [`Vec<T>`]
/// is considered initialized because the only requirement the compiler knows about it
/// is considered initialized (under the current implementation, this does not constitute
/// a stable guarantee) because the only requirement the compiler knows about it
/// is that the data pointer must be non-null. Creating such a `Vec<T>` does not cause
/// *immediate* undefined behavior, but will cause undefined behavior with most
/// safe operations (including dropping it).
Expand Down Expand Up @@ -402,6 +403,14 @@ impl<T> MaybeUninit<T> {
///
/// [inv]: #initialization-invariant
///
/// On top of that, remember that most types have additional invariants beyond merely
/// being considered initialized at the type level. For example, a `1`-initialized [`Vec<T>`]
/// is considered initialized (under the current implementation, this does not constitute
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Grammatical note: there are two possible interpretations with the comma here. If you change the comma to a semicolon ; or double dash --, is it the meaning you intended? If so, it will be better to change it. If not, it will be better to rephrase.

Another option is to drop the "this does not constitute a stable guarantee" part of the sentence because it is redundant with "under the current implementation".

Copy link
Contributor

@Centril Centril Aug 6, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another option is to drop the "this does not constitute a stable guarantee" part of the sentence because it is redundant with "under the current implementation".

It's not redundant; it is making the point that the current implementation is not a stable guarantee, but I'd rephrase as: "under the current implementation, which does not constitute a stable guarantee".

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bluetech thanks! Turned it into a ;

/// a stable guarantee) because the only requirement the compiler knows about it
/// is that the data pointer must be non-null. Creating such a `Vec<T>` does not cause
/// *immediate* undefined behavior, but will cause undefined behavior with most
/// safe operations (including dropping it).
///
/// # Examples
///
/// Correct usage of this method:
Expand Down