Closed
Description
I tried this code:
fn main() {
let _ = *(0 as *const ());
}
I expected to see this happen: A compiler error, dereferencing pointers is unsafe, and no unsafe block is provided.
Instead, this happened:
Compiling playground v0.0.1 (/playground)
warning: dereferencing a null pointer
--> src/main.rs:2:13
|
2 | let _ = *(0 as *const ());
| ^^^^^^^^^^^^^^^^^ this code causes undefined behavior when executed
|
= note: `#[warn(deref_nullptr)]` on by default
warning: `playground` (bin "playground") generated 1 warning
Finished dev [unoptimized + debuginfo] target(s) in 0.97s
Running `target/debug/playground`
As far as I can tell, this code erroneously compiles for any Copy
type, so long as the pattern doesn't bind anything to an identifier. Calls to unsafe functions cause a compiler error as normal.
Meta
Works on the playground when I tested with stable-1.66.1, beta-1.67.0-beta.10, and nightly-1.69.0 (2023-01-23)