Skip to content

Can cast an unusable value to a raw pointer #20791

Closed
@wthrowe

Description

@wthrowe
fn main() {
    let x: &i32;
    //x; // error: use of possibly uninitialized variable: `x`
    println!("{:?}", x as *const _);
}

This is accepted and prints 0x0 everywhere I've tested (rustc 0.13.0-dev (496dc4e) and the playpen). A similar access is allowed to moved values and mutably borrowed values.

I assume I should not be able to access uninitialized values without some unsafe code, although I am new to the language and might be missing something.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions