Skip to content

Commit

Permalink
Rollup merge of rust-lang#91851 - woppopo:const_maybeuninit_zeroed, r…
Browse files Browse the repository at this point in the history
…=yaahc

Make `MaybeUninit::zeroed` `const`

Tracking issue: rust-lang#91850

```rust
// core::mem
impl<T> MaybeUninit<T> {
    pub const fn zeroed() -> MaybeUninit<T>;
}
```
  • Loading branch information
matthiaskrgr authored Dec 14, 2021
2 parents dfec47f + 2a5a668 commit 75e8d65
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion library/core/src/mem/maybe_uninit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -394,10 +394,11 @@ impl<T> MaybeUninit<T> {
/// // This is undefined behavior. ⚠️
/// ```
#[stable(feature = "maybe_uninit", since = "1.36.0")]
#[rustc_const_unstable(feature = "const_maybe_uninit_zeroed", issue = "91850")]
#[must_use]
#[inline]
#[rustc_diagnostic_item = "maybe_uninit_zeroed"]
pub fn zeroed() -> MaybeUninit<T> {
pub const fn zeroed() -> MaybeUninit<T> {
let mut u = MaybeUninit::<T>::uninit();
// SAFETY: `u.as_mut_ptr()` points to allocated memory.
unsafe {
Expand Down

0 comments on commit 75e8d65

Please sign in to comment.