Skip to content

Commit d4d6e38

Browse files
committed
fix code typo, and make unions more consistent
1 parent 5cff374 commit d4d6e38

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

text/0000-union-initialization-and-drop.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ u.f1 = ManuallyDrop::new(Vec::new());
112112
{ let _x = &u.f2.0; }
113113

114114
// Equivalently, we can assign the entire union:
115-
u = U { f2: S(42) };
115+
u = U { f2: (S(42), S(23) };
116116
// Now `u` is still initialized.
117117

118118
// Copying does not change anything:
@@ -144,7 +144,7 @@ and it is not possible to move out of a field. For example:
144144

145145
struct S(i32); // not `Copy`, no drop glue
146146

147-
union U { f1: ManuallyDrop<Vec<i32>>, f2: S, f3: u32 }
147+
union U { f1: ManuallyDrop<Vec<i32>>, f2: (S, S), f3: u32 }
148148
impl Drop for U {
149149
fn drop(&mut self) {
150150
println!("Goodbye!");
@@ -153,7 +153,7 @@ impl Drop for U {
153153

154154
let mut u: U;
155155
// `u.f1 = ...;` gets rejected: Cannot initialize a union with `Drop` by assigning a field.
156-
u = U { f2: S(42) };
156+
u = U { f2: (S(42), S(1)) };
157157
// Now `u` is initialized.
158158

159159
// `let v = u.f1;` gets rejected: Cannot move out of union that implements `Drop`.
@@ -166,7 +166,7 @@ When a union implementing `Drop` goes out of scope, its destructor gets called i
166166

167167
```rust
168168
{
169-
let u = U { f2: S(42) };
169+
let u = U { f2: (S(0), S(1)) };
170170
// drop gets called
171171
}
172172
{

0 commit comments

Comments
 (0)