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

Forbid std::mem::uninitliazed even with a justification #39

Open
nico-abram opened this issue Jun 26, 2020 · 0 comments
Open

Forbid std::mem::uninitliazed even with a justification #39

nico-abram opened this issue Jun 26, 2020 · 0 comments

Comments

@nico-abram
Copy link

The Documentation says

calling e.g. mem::uninitialized::() causes immediate undefined behavior for returning a bool that is not definitely either true or false. Worse, truly uninitialized memory like what gets returned here is special in that the compiler knows that it does not have a fixed value. This makes it undefined behavior to have uninitialized data in a variable even if that variable has an integer type. (Notice that the rules around uninitialized integers are not finalized yet, but until they are, it is advisable to avoid them.)

Despite mentioning that it is deprecated, the guide seems to equate it to MaybeUninit and allow it if justified:

The std::mem::uninitialized function (deprecated 1.38) or the std::mem::MaybeUninit type (stabilized 1.36) must not be used, or explicitly justified when necessary.

It goes on to say

std::mem::MaybeUninit is an improvement over std::mem::uninitialized. In-deed, it makes dropping uninitialized values a lot more difficult.

Which might give the impression that that is the only difference, when in fact std::mem::uninitialized is a lot more UB-happy (And I think I've heard a couple times that it cannot be used without UB (Unless it's used to make a MaybeUninit or a similar unsafe union with a unit variant))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant