Skip to content

Uninit checks: false alarm reading an array of a repeated initialized MaybeUninit #5229

Backlog

Description

@feliperodri

With -Z uninit-checks, reading an element of an array built by repeating an initialized MaybeUninit is reported as an uninitialized read:

use std::mem::MaybeUninit;
#[kani::proof]
fn repeat_maybe_uninit() {
    let a = [MaybeUninit::new(1u32); 3];
    let x = unsafe { a[kani::any_where(|i: &usize| *i < 3)].assume_init() };
    assert!(x == 1);
}
Failed Checks: Undefined Behavior: Reading from an uninitialized pointer of type `*const std::mem::MaybeUninit<u32>`

Every element is initialized, so this is a false alarm. The Rvalue::Repeat assignment of a type with union bytes resets the destination's state instead of copying the state of the repeated operand into each element. Reported by @rajath-mk in the review of #5196, where [MaybeUninit<T>; N] became supported; reproduced on #5196's branch.

Activity

  1. added
    [C] Bug
    [F] Spurious Failure
    Z-UnstableFeature
    on Nov 25, 2026
  2. added theissue type on Nov 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Z-UnstableFeature[C] Bug[F] Spurious Failure

    Type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions