Skip to content

Error of one Snippet in unsafe-rawpointer/raw-pointer.md #385

@arrowrowe

Description

@arrowrowe

unsafe-rawpointer/raw-pointer.md

$ cat sample.rs 
fn main() {
  let mut x = 2;
  let y = &x as *mut i32;
}

$ rustc sample.rs 
sample.rs:3:11: 3:25 error: casting `&i32` as `*mut i32` is invalid
sample.rs:3   let y = &x as *mut i32;
                      ^~~~~~~~~~~~~~
error: aborting due to previous error

创建一个裸指针:

let a = 1;
let b = &a as *const i32;

let mut x = 2;
let y = &x as *mut i32;

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