Skip to content

Commit 66b340f

Browse files
committed
test more ways of mutably accessing a place
1 parent 97974e3 commit 66b340f

File tree

2 files changed

+45
-1
lines changed

2 files changed

+45
-1
lines changed

Diff for: src/test/ui/union/union-deref.rs

+8
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,16 @@ fn main() {
1313
let mut u : U1<Vec<i32>> = U1 { x: () };
1414
unsafe { (*u.f).0 = Vec::new() }; // explicit deref, this compiles
1515
unsafe { u.f.0 = Vec::new() }; //~ERROR not automatically applying `DerefMut` on `ManuallyDrop` union field
16+
unsafe { &mut (*u.f).0 }; // explicit deref, this compiles
17+
unsafe { &mut u.f.0 }; //~ERROR not automatically applying `DerefMut` on `ManuallyDrop` union field
18+
unsafe { (*u.f).0.push(0) }; // explicit deref, this compiles
19+
unsafe { u.f.0.push(0) }; //~ERROR not automatically applying `DerefMut` on `ManuallyDrop` union field
1620

1721
let mut u : U2<Vec<i32>> = U2 { x: () };
1822
unsafe { (*u.f.0).0 = Vec::new() }; // explicit deref, this compiles
1923
unsafe { u.f.0.0 = Vec::new() }; //~ERROR not automatically applying `DerefMut` on `ManuallyDrop` union field
24+
unsafe { &mut (*u.f.0).0 }; // explicit deref, this compiles
25+
unsafe { &mut u.f.0.0 }; //~ERROR not automatically applying `DerefMut` on `ManuallyDrop` union field
26+
unsafe { (*u.f.0).0.push(0) }; // explicit deref, this compiles
27+
unsafe { u.f.0.0.push(0) }; //~ERROR not automatically applying `DerefMut` on `ManuallyDrop` union field
2028
}

Diff for: src/test/ui/union/union-deref.stderr

+37-1
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,50 @@ LL | unsafe { u.f.0 = Vec::new() };
77
= help: writing to this reference calls the destructor for the old value
88
= help: add an explicit `*` if that is desired, or call `ptr::write` to not run the destructor
99

10+
error: not automatically applying `DerefMut` on `ManuallyDrop` union field
11+
--> $DIR/union-deref.rs:17:19
12+
|
13+
LL | unsafe { &mut u.f.0 };
14+
| ^^^
15+
|
16+
= help: writing to this reference calls the destructor for the old value
17+
= help: add an explicit `*` if that is desired, or call `ptr::write` to not run the destructor
18+
1019
error: not automatically applying `DerefMut` on `ManuallyDrop` union field
1120
--> $DIR/union-deref.rs:19:14
1221
|
22+
LL | unsafe { u.f.0.push(0) };
23+
| ^^^
24+
|
25+
= help: writing to this reference calls the destructor for the old value
26+
= help: add an explicit `*` if that is desired, or call `ptr::write` to not run the destructor
27+
28+
error: not automatically applying `DerefMut` on `ManuallyDrop` union field
29+
--> $DIR/union-deref.rs:23:14
30+
|
1331
LL | unsafe { u.f.0.0 = Vec::new() };
1432
| ^^^^^^^
1533
|
1634
= help: writing to this reference calls the destructor for the old value
1735
= help: add an explicit `*` if that is desired, or call `ptr::write` to not run the destructor
1836

19-
error: aborting due to 2 previous errors
37+
error: not automatically applying `DerefMut` on `ManuallyDrop` union field
38+
--> $DIR/union-deref.rs:25:19
39+
|
40+
LL | unsafe { &mut u.f.0.0 };
41+
| ^^^^^^^
42+
|
43+
= help: writing to this reference calls the destructor for the old value
44+
= help: add an explicit `*` if that is desired, or call `ptr::write` to not run the destructor
45+
46+
error: not automatically applying `DerefMut` on `ManuallyDrop` union field
47+
--> $DIR/union-deref.rs:27:14
48+
|
49+
LL | unsafe { u.f.0.0.push(0) };
50+
| ^^^^^^^
51+
|
52+
= help: writing to this reference calls the destructor for the old value
53+
= help: add an explicit `*` if that is desired, or call `ptr::write` to not run the destructor
54+
55+
error: aborting due to 6 previous errors
2056

0 commit comments

Comments
 (0)