Skip to content

Initialization checks for fixed size arrays not initialized during declaration always fails #15885

Closed
@prajwalkman

Description

@prajwalkman

Uninitialized fixed size arrays always throw Use of possibly uninitialized variable errors, even if all the indices are allocated. Is there a way around this? If not, it shouldn't be possible to create uninitialized fixed size arrays.

struct Num {s: int}

fn main() {
    let s = box Num {s: 5};
    let mut a: [&Num, ..5];
    a[0] = &*s;    a[1] = &*s;    a[2] = &*s;    a[3] = &*s;    a[4] = &*s;

    println!("{}", a[0].s) // error: use of possibly uninitialized variable: `a[..].s`

}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions