Skip to content

Commit 9430002

Browse files
committed
Clarify why reading and writing to union fields is unsafe
1 parent 7f62c3c commit 9430002

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

_posts/2017-07-20-Rust-1.19.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@ union MyUnion {
4242
Unions are kind of like `enum`s, but they are "untagged". Enums have a "tag"
4343
that stores which variant is the correct one at runtime; unions elide this tag.
4444

45-
That means that reading or writing a union's field is unsafe:
45+
Since we can interpret the data held in the union using the wrong variant and
46+
Rust can't check this for us, that means reading or writing a union's field is
47+
unsafe:
4648

4749
```rust
4850
let u = MyUnion { f1: 1 };

0 commit comments

Comments
 (0)