core::ptr::replace implementation is unsound since Rust 1.80 #138351
Labels
C-bug
Category: This is a bug.
I-unsound
Issue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/Soundness
needs-triage
This issue may need triage. Remove it if it has been sufficiently triaged.
T-lang
Relevant to the language team, which will review and decide on the PR/issue.
Consider the following program:
This was made a legal program in Rust 1.80, the preconditions state:
dst
must be valid for both reads and writes.dst
must be properly aligned.dst
must point to a properly initialized value of typeT
.This is because in Rust 1.80 the following line was added to valid:
Nevertheless, running the above program results in undefined behavior:
Rather than changing the implementation of
core::ptr::replace
, or an isolated change to the requirements ofcore::ptr::replace
, I would like to see the change to the definition of a valid pointer for ZSTs reverted, I've expanded more about my thoughts and provided more arguments in this T-opsem zulip thread. In short, I believe that unsoundness similar to the case here incore::ptr::replace
will keep happening as long as "dereferencing a pointer" and "reborrowing a pointer" have different requirements (which they do since Rust 1.80).The text was updated successfully, but these errors were encountered: