Skip to content

Creating a raw reference/pointer to an extern never value claims following code is unreachable #74840

Closed

Description

I tried this code (playground):

#![feature(never_type)]
#![feature(raw_ref_macros)]
#![feature(raw_ref_op)]

extern {
    static FOO: !;
}

fn main() {
    dbg!(unsafe { core::ptr::raw_const!(FOO) });
    dbg!(unsafe { &raw const FOO });
}

I expected to see this happen: just a linker failure because FOO doesn't exist.

Instead, this happened: before the linker failure, rustc complained that code was unreachable.

warning: unreachable expression
  --> src/main.rs:10:19
   |
10 |     dbg!(unsafe { core::ptr::raw_const!(FOO) });
   |                   ^^^^^^^^^^^^^^^^^^^^^^---^
   |                   |                     |
   |                   |                     any code following this expression is unreachable
   |                   unreachable expression

warning: unreachable expression
  --> src/main.rs:11:19
   |
11 |     dbg!(unsafe { &raw const FOO });
   |                   ^^^^^^^^^^^---
   |                   |          |
   |                   |          any code following this expression is unreachable
   |                   unreachable expression

(The code should also build without the unsafe; that is caused by the same problem.)

Meta

1.47.0-nightly
(2020-07-26 6c8927b0cf80ceee1938)

cc @rust-lang/wg-unsafe-code-guidelines

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

Metadata

Assignees

No one assigned

    Labels

    A-raw-pointersArea: raw pointers, MaybeUninit, NonNullC-bugCategory: This is a bug.F-never_type`#![feature(never_type)]`F-raw_ref_op`#![feature(raw_ref_op)]`T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.requires-nightlyThis issue requires a nightly compiler in some way.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions