Commit 3514a23
Isaac van Bakel
Clarify UB around immutability & mutation
I personally found this description of UB confusing, since the use of
"reached" suggests that UB only happens for read bytes, and the
definition of immutability is not given, allowing for multiple
interpretations: does the "data" have to be immutable from the first
read? From the creation of the reference? Between reads from the
immutable accessor, but not otherwise? etc.
This clarifies the actual UB conditions, based on this Zulip
interaction:
https://rust-lang.zulipchat.com/#narrow/stream/136281-t-opsem/topic/What.20exactly.20are.20.22immutable.22.20and.20.22reached.22.20in.20shared.20ref.20UB.3F
and this reference discussion:
#1227
in two ways:
* The definition of "data" is clarified to be stated in terms of
bytes, in a way that should avoid ambiguity about which bytes are
considered. Based on the GH issue, this clarification should also
allow for use of a `*mut` pointer through a shared reference, which
is not in itself UB. Based on the Zulip issue, the definition
includes padding bytes, which may be surprising.
* The definition of immutability & mutation for a set of bytes is
clarified to mean forbidding *all* non-0-byte writes.1 parent e94fb3d commit 3514a23
1 file changed
+6
-3
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
42 | 42 | | |
43 | 43 | | |
44 | 44 | | |
45 | | - | |
46 | | - | |
47 | | - | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
48 | 51 | | |
49 | 52 | | |
50 | 53 | | |
| |||
0 commit comments