]> git.lizzy.rs Git - rust.git/commit
Auto merge of #51990 - oli-obk:unstable_union, r=nikomatsakis
authorbors <bors@rust-lang.org>
Tue, 7 Aug 2018 13:14:37 +0000 (13:14 +0000)
committerbors <bors@rust-lang.org>
Tue, 7 Aug 2018 13:14:37 +0000 (13:14 +0000)
commit39e95165323f76042dfab65772a8411dd85fe088
treefa86b133eeb4f43d7a7b741578332bd117607c0d
parent18925dee25ce649562d203e72068e3a57b60b153
parent4b731a908b3df2a926eae5fb5233dbc73b098276
Auto merge of #51990 - oli-obk:unstable_union, r=nikomatsakis

Place unions, pointer casts and pointer derefs behind extra feature gates

To ensure we don't stabilize these things together with const fn stabilization (or any other stabilization)

This PR moves union field accesses inside `const fn` behind a feature gate. It was possible without a feature gate before, but since `const fn` was behind a feature gate we can do this change.

While "dereferencing raw pointers" and "casting raw pointers to usize" were hard errors before this PR, one could work around them by abusing unions:

```rust
// deref
union Foo<T> {
    x: &'static T,
    y: *const T,
}
const FOO: u32 = unsafe { *Foo { y: 42 as *const T }.x };

// as usize cast
union Bar<T> {
    x: usize,
    y: *const T,
}
const BAR: usize = unsafe { Bar { y: &1u8 }.x };
```

r? @eddyb

cc @nikomatsakis
src/librustc_mir/diagnostics.rs
src/libsyntax/feature_gate.rs