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

Why use 1usize instead of 0usize in unreachable? #158

Closed
playXE opened this issue Jul 20, 2019 · 1 comment
Closed

Why use 1usize instead of 0usize in unreachable? #158

playXE opened this issue Jul 20, 2019 · 1 comment

Comments

@playXE
Copy link

playXE commented Jul 20, 2019

Why use 1usize instead of 0usize there :

#[inline]
pub unsafe fn unreachable() -> ! {
    enum Void {}
    let x: &Void = mem::transmute(1usize);
    match *x {}
}

If this function should trigger UB?

@emilio
Copy link
Member

emilio commented Oct 19, 2019

Doesn't really matter, to be clear, right?

It creates a null reference and dereferences it, so it's clearly UB regardless of the value of the reference.

Anyhow on trunk this has been replaced by std::hint::unreachable_unchecked.

@emilio emilio closed this as completed Oct 19, 2019
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

No branches or pull requests

2 participants