Skip to content

No safe way to get a raw ptr to an uninitialized variable #12528

Description

@sp3d

I would argue that the following code is safe (rustc presently disagrees: "error: use of possibly uninitialized variable: a") and there should be a way to write it:

fn main(){
    let a: int;
    let b: *int = &a;
}

The analysis is correct in that obtaining an &-ptr to an uninitialized variable allows for unsafety, but there should be a way to get the address of a variable as a raw-ptr without needing a guarantee that a valid value lives at that address.

Activity

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions