Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace unsafe transmute to a cast #99

Merged
merged 1 commit into from Sep 14, 2021

Conversation

vlad20012
Copy link
Contributor

unsafe { mem::transmute::<i16, u16>(exp) } as u64 is equivalent to exp as u16 as u64, this can be verified with a simple program:

fn main() {
    for i in i16::MIN ..= i16::MAX {
        assert_eq!(
            unsafe { std::mem::transmute::<i16, u16>(i) } as u64,
            i as u16 as u64
        )
    }
}

`unsafe { mem::transmute::<i16, u16>(exp) } as u64`
 is equivalent to `exp as u16 as u64`, this can be
 verified with a simple program:

```rust
fn main() {
    for i in i16::MIN ..= i16::MAX {
        assert_eq!(
            unsafe { std::mem::transmute::<i16, u16>(i) } as u64,
            i as u16 as u64
        )
    }
}
```
@mbrubeck mbrubeck merged commit 76b11cd into reem:master Sep 14, 2021
@mbrubeck
Copy link
Collaborator

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants