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
|
||
|---|---|---|
| .. | ||
| attr | ||
| diagnostics | ||
| ext | ||
| parse | ||
| util | ||
| ast.rs | ||
| build.rs | ||
| Cargo.toml | ||
| codemap.rs | ||
| config.rs | ||
| diagnostic_list.rs | ||
| early_buffered_lints.rs | ||
| entry.rs | ||
| feature_gate.rs | ||
| fold.rs | ||
| json.rs | ||
| lib.rs | ||
| ptr.rs | ||
| README.md | ||
| show_span.rs | ||
| std_inject.rs | ||
| str.rs | ||
| test.rs | ||
| test_snippet.rs | ||
| tokenstream.rs | ||
| visit.rs | ||
The syntax crate contains those things concerned purely with syntax
– that is, the AST ("abstract syntax tree"), parser, pretty-printer,
lexer, macro expander, and utilities for traversing ASTs.
For more information about how these things work in rustc, see the rustc guide: