You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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)
The text was updated successfully, but these errors were encountered:
Edit: Maybe it isn't an exact duplicate, but the behavior is one that's sufficiently tracked in that other issue already.
Edit2: Actually, it isn't sufficiently tracked in the other issue. The code here gives a warning claiming "undefined behavior", so in case the code is considered safe, we would still have a diagnostic issue.
That warning feels like it's coming from const evaluation (rvalue promotion). I don't know if it actually is, but I would not be surprised if promotion/promotability is involved here somehow.
This is in fact fixed by #102256 on the latest stable:
error[E0133]: dereference of raw pointer is unsafe and requires unsafe function or block
--> src/main.rs:2:13
|
2 | let _ = *(0 as *const ());
| ^^^^^^^^^^^^^^^^^ dereference of raw pointer
|
= note: raw pointers may be null, dangling or unaligned; they can violate aliasing rules and cause data races: all of these are undefined behavior
I tried this code:
playground
I expected to see this happen: A compiler error, dereferencing pointers is unsafe, and no unsafe block is provided.
Instead, this happened:
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)
The text was updated successfully, but these errors were encountered: