Skip to content

Compiler isn't trusting programmer in unsafe code #14903

Closed
@engstad

Description

@engstad

With the recent transmute changes, several safe cases are now reported as errors. The most trivial is:

unsafe fn f<T>(i: T) ->T { std::mem::transmute(i) }

Another is:

struct Plane<T> { values : [T, ..4] }
struct Vec4<T>  { values : [T, ..4] }
impl<T> Plane<T> {
   unsafe fn to_vec4(&self) -> Vec4<T> { 
       std::mem::transmute(self.values) 
   }
}

There are obviously workarounds, but these are examples that are safe where the type-checker gets in the way. It is also unfortunate that the code is marked as "unsafe", yet the compiler rejects the code.

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