Skip to content

Commit ac30830

Browse files
authored
Merge pull request #101 from tatsuya6502/union-fix
It is safe to write to a union field
2 parents 6f7aff0 + 1432cf6 commit ac30830

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

src/rust-2018/data-types/union-for-an-unsafe-form-of-enum.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@ that stores which variant is the correct one at runtime; unions don't have
1616
this tag.
1717

1818
Since we can interpret the data held in the union using the wrong variant and
19-
Rust can’t check this for us, that means reading or writing a union’s field
20-
is unsafe:
19+
Rust can’t check this for us, that means reading a union’s field is unsafe:
2120

2221
```rust
2322
# union MyUnion {
@@ -26,7 +25,7 @@ is unsafe:
2625
# }
2726
let mut u = MyUnion { f1: 1 };
2827

29-
unsafe { u.f1 = 5 };
28+
u.f1 = 5;
3029

3130
let value = unsafe { u.f1 };
3231
```

0 commit comments

Comments
 (0)