Skip to content

Document that casting &mut T to &mut MaybeUninit<T> is not safe #66699

Closed
@Shnatsel

Description

As discussed on Reddit, it turns out that casting &mut T to &mut MaybeUninit<T> is not a safe operation, since it allows UB in safe code.

Playground example demonstrating the UB: https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=93dd41cf851bfc0de2233e0a83b4b778

It is probably a good idea to explicitly point that out in MaybeUninit docs.

Metadata

Assignees

No one assigned

    Labels

    A-docsArea: Documentation for any part of the project, including the compiler, standard library, and toolsC-enhancementCategory: An issue proposing an enhancement or a PR with one.T-langRelevant to the language team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions