mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-27 09:14:20 +00:00
982b49494e
This is to make the diff when stabilizing it easier to review.
51 lines
1021 B
Rust
51 lines
1021 B
Rust
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 { //~ ERROR access to union field is unsafe
|
|
Foo {
|
|
pizza: Pizza {
|
|
topping: Some(PizzaTopping::Cheese) | Some(PizzaTopping::Pineapple) | None
|
|
}
|
|
} => {},
|
|
}
|
|
|
|
// MIR unsafeck incorrectly thinks that no unsafe block is needed to do these
|
|
match foo {
|
|
Foo { zst: () } => {},
|
|
}
|
|
match foo {
|
|
Foo { pizza: Pizza { .. } } => {},
|
|
}
|
|
|
|
// binding to wildcard is okay
|
|
match foo {
|
|
Foo { bar: _ } => {},
|
|
}
|
|
let Foo { bar: _ } = foo;
|
|
}
|