Skip to content

"!" is the only type that is unsafe to raw-ptr-deref into a "_" pattern #79735

Description

@RalfJung

This code compiles:

fn foo(ptr: *const bool) {
    let _ = *ptr;
}

The MIR is empty, i.e., no ptr deref happens.

But this does not:

fn foo(ptr: *const !) {
    let _ = *ptr;
}

The MIR is unreachable;, i.e., the ptr deref conceptually somehow did actually happen.

That is a very strange inconsistency -- the ! type is just yet another type, why does it behave differently here?

Curiously, this does not yield any unreachable:

fn bar(ptr: *const (i32, !)) { unsafe {
    let (x, _) = *ptr;
} }

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.F-never_type`#![feature(never_type)]`T-langRelevant to the language teamfixed-by-thir-unsafeck`-Z thir-unsafeck` handles this correctly.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions