-
Notifications
You must be signed in to change notification settings - Fork 30
/
union-assignop.rs
56 lines (52 loc) · 1.38 KB
/
union-assignop.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
use std::ops::AddAssign;
use std::mem::ManuallyDrop;
struct NonCopy;
impl AddAssign for NonCopy {
fn add_assign(&mut self, _: Self) {}
}
union Foo {
a: u8, // non-dropping
b: ManuallyDrop<NonCopy>,
}
fn main() {
let mut foo = Foo { a: 42 };
foo.a += 5; //~ ERROR access to union field is unsafe
*foo.b += NonCopy; //~ ERROR access to union field is unsafe
*foo.b = NonCopy; //~ ERROR access to union field is unsafe
foo.b = ManuallyDrop::new(NonCopy);
foo.a; //~ ERROR access to union field is unsafe
let foo = Foo { a: 42 };
foo.b; //~ ERROR access to union field is unsafe
let mut foo = Foo { a: 42 };
foo.b = foo.b;
//~^ ERROR access to union field is unsafe
}
// ferrocene-annotations: fls_fk2m2irwpeof
// Implementations
//
// ferrocene-annotations: fls_fmdn7n7s413d
// Union Types
//
// ferrocene-annotations: fls_8tsynkj2cufj
// Struct Expressions
//
// ferrocene-annotations: fls_18k3uajrgq5f
// Field Access Expressions
//
// ferrocene-annotations: fls_290jmzfh7x4e
// Compound Assignment Expressions
//
// ferrocene-annotations: fls_5cm4gkt55hjh
// Dereference Expression
//
// ferrocene-annotations: fls_9kjpxri0axvg
// Weak Keywords
//
// ferrocene-annotations: fls_6ydylimiv553
// Place Expressions
//
// ferrocene-annotations: fls_izdv9i4spokw
// Operator Expressions
//
// ferrocene-annotations: fls_xcwfotmq2e5d
// Field Resolution