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