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

It is possible to write to a field of an uninitialized struct #31947

Closed
matklad opened this issue Feb 28, 2016 · 1 comment
Closed

It is possible to write to a field of an uninitialized struct #31947

matklad opened this issue Feb 28, 2016 · 1 comment

Comments

@matklad
Copy link
Member

matklad commented Feb 28, 2016

It is impossible to read a filed of uninitialized struct, but for some reason the write is allowed (but you can't read it back later):

struct S {x: i32, y: i32}

fn main() {
    let mut s: S;
    s.x = 32;           // why I don't get an error here,
    s.y = 12;
    println!("{}", s.x) // but get it here instead?
}

Originally reported at https://users.rust-lang.org/t/use-of-possibly-uninitialized-variable-on-an-initialized-variable/4799/4

@Aatch
Copy link
Contributor

Aatch commented Feb 28, 2016

This is fundamentally the same issue as #21232, as the analysis treats uninitialized variables and moved ones essentially the same way.

Closing as a duplicate of that.

@Aatch Aatch closed this as completed Feb 28, 2016
@mbrubeck mbrubeck changed the title It is possible to write to a filed of uninitialized struct It is possible to write to a field of an uninitialized struct Oct 5, 2017
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