1ec22171e6
Implement constant support in MIR. All of the intended features in `trans::consts` are now supported by `mir::constant`. The implementation is considered a temporary measure until `miri` replaces it. A `-Z orbit` bootstrap build will only translate LLVM IR from AST for `#[rustc_no_mir]` functions. Furthermore, almost all checks of constant expressions have been moved to MIR. In non-`const` functions, trees of temporaries are promoted, as per RFC 1414 (rvalue promotion). Promotion before MIR borrowck would allow reasoning about promoted values' lifetimes. The improved checking comes at the cost of four `[breaking-change]`s: * repeat counts must contain a constant expression, e.g.: `let arr = [0; { println!("foo"); 5 }];` used to be allowed (it behaved like `let arr = [0; 5];`) * dereference of a reference to a `static` cannot be used in another `static`, e.g.: `static X: [u8; 1] = [1]; static Y: u8 = (&X)[0];` was unintentionally allowed before * the type of a `static` *must* be `Sync`, irrespective of the initializer, e.g. `static FOO: *const T = &BAR;` worked as `&T` is `Sync`, but it shouldn't because `*const T` isn't * a `static` cannot wrap `UnsafeCell` around a type that *may* need drop, e.g. `static X: MakeSync<UnsafeCell<Option<String>>> = MakeSync(UnsafeCell::new(None));` was previously allowed based on the fact `None` alone doesn't need drop, but in `UnsafeCell` it can be later changed to `Some(String)` which *does* need dropping The drop restrictions are relaxed by RFC 1440 (#33156), which is implemented, but feature-gated. However, creating `UnsafeCell` from constants is unstable, so users can just enable the feature gate. |
||
---|---|---|
.. | ||
cfg | ||
clean.mk | ||
crates.mk | ||
ctags.mk | ||
debuggers.mk | ||
dist.mk | ||
docs.mk | ||
grammar.mk | ||
host.mk | ||
install.mk | ||
llvm.mk | ||
main.mk | ||
platform.mk | ||
prepare.mk | ||
reconfig.mk | ||
rt.mk | ||
rustllvm.mk | ||
stage0.mk | ||
target.mk | ||
tests.mk | ||
util.mk |