-
Notifications
You must be signed in to change notification settings - Fork 32
/
union.rs
85 lines (77 loc) · 1.76 KB
/
union.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
union Foo {
bar: i8,
zst: (),
pizza: Pizza,
}
#[derive(Clone, Copy)]
struct Pizza {
topping: Option<PizzaTopping>
}
#[allow(dead_code)]
#[derive(Clone, Copy)]
enum PizzaTopping {
Cheese,
Pineapple,
}
fn do_nothing(_x: &mut Foo) {}
pub fn main() {
let mut foo = Foo { bar: 5 };
do_nothing(&mut foo);
// This is UB, so this test isn't run
match foo {
Foo { bar: _a } => {}, //~ ERROR access to union field is unsafe
}
match foo {
Foo {
pizza: Pizza { //~ ERROR access to union field is unsafe
topping: Some(PizzaTopping::Cheese) | Some(PizzaTopping::Pineapple) | None
}
} => {},
}
match foo {
Foo { zst: () } => {} //~ ERROR access to union field is unsafe
}
match foo {
Foo { pizza: Pizza { .. } } => {} //~ ERROR access to union field is unsafe
}
// binding to wildcard is okay
match foo {
Foo { bar: _ } => {},
}
let Foo { bar: _ } = foo;
}
// ferrocene-annotations: fls_fmdn7n7s413d
// Union Types
//
// ferrocene-annotations: fls_9ucqbbd0s2yo
// Struct Types
//
// ferrocene-annotations: fls_szibmtfv117b
// Enum Types
//
// ferrocene-annotations: fls_8tsynkj2cufj
// Struct Expressions
//
// ferrocene-annotations: fls_a14slch83hzn
// Borrowing
//
// ferrocene-annotations: fls_qztk0bkju9u
// Borrow Expression
//
// ferrocene-annotations: fls_xa4nbfas01cj
// Call Expressions
//
// ferrocene-annotations: fls_e5td0fa92fay
// Match Expressions
//
// ferrocene-annotations: fls_7dbd5t2750ce
// Struct Patterns
//
// ferrocene-annotations: fls_nruvg0es3kx7
// Record Struct Patterns
//
// ferrocene-annotations: fls_asj8rgccvkoe
// Struct Pattern Matching
//
// ferrocene-annotations: fls_9kjpxri0axvg
// Weak Keywords