Skip to content

rustc considers casting to violate lifetime analysis #19716

Closed
@stouset

Description

@stouset
extern crate alloc;
extern crate libc;

fn main() {
    let ptr = alloc::heap::EMPTY as *const libc::c_void;

    let ptrref1 : &*const libc::c_void;
    let ptrref2 : &*const u8;

    {
        ptrref1 = &ptr;
        ptrref2 = &(ptr as *const u8);
    }
}

In this case, ptrref1 is able to be assigned to a ref of the pointer. However, ptrref2 cannot because of the cast. It appears the only way to work around this currently is with transmute:

ptrref2 : &*const u8 = std::mem::transmute(&ptr);

Try it yourself.

$ rustc --version=verbose
rustc 0.13.0-nightly (8bca470c5 2014-12-08 00:12:30 +0000)
binary: rustc
commit-hash: 8bca470c5acf13aa20022a2c462a89f72de721fc
commit-date: 2014-12-08 00:12:30 +0000
host: x86_64-apple-darwin
release: 0.13.0-nightly

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-type-systemArea: Type systemT-langRelevant to the language team

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions