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

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

Closed
prajwalkman opened this issue Jul 21, 2014 · 1 comment

Comments

@prajwalkman
Copy link

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`

}
@prajwalkman prajwalkman changed the title Exhaustiveness checks for unintialized fixed size arrays Exhaustiveness checks for unintialized fixed size arrays always errors out Jul 21, 2014
@prajwalkman prajwalkman changed the title Exhaustiveness checks for unintialized fixed size arrays always errors out Exhaustiveness checks for unintialized fixed size arrays always fails Jul 22, 2014
@prajwalkman prajwalkman changed the title Exhaustiveness checks for unintialized fixed size arrays always fails Initialization checks for fixed size arrays not initialized during declaration always fails Jul 22, 2014
@alexcrichton
Copy link
Member

Closing as working as intended. In Rust you generally can't deal with uninitialized memory. If Num had a destructor then it would destruct invalid memory if one of the initializations initiated task failure.

For fixed size arrays you'll have to explicitly assign each element upon creation.

bors added a commit to rust-lang-ci/rust that referenced this issue Nov 27, 2023
Fix typo in highlight_related.rs

While reading the user manual, I noticed a random tick, so I went ahead and fixed it. The `await` keyword should be properly rendered as inline code.

![image](https://github.com/rust-lang/rust-analyzer/assets/20878432/f134a4c9-e539-4635-97ac-506790893869)
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

2 participants