]> git.lizzy.rs Git - rust.git/commitdiff
Auto merge of #66507 - ecstatic-morse:const-if-match, r=oli-obk
authorbors <bors@rust-lang.org>
Sat, 23 Nov 2019 01:13:41 +0000 (01:13 +0000)
committerbors <bors@rust-lang.org>
Sat, 23 Nov 2019 01:13:41 +0000 (01:13 +0000)
Enable `if` and `match` in constants behind a feature flag

This PR is an initial implementation of #49146. It introduces a `const_if_match` feature flag and does the following if it is enabled:
- Allows `Downcast` projections, `SwitchInt` terminators and `FakeRead`s for matched places through the MIR const-checker.
- Allows `if` and `match` expressions through the HIR const-checker.
- Stops converting `&&` to `&` and `||` to `|` in `const` and `static` items.

As a result, the following operations are now allowed in a const context behind the feature flag:
- `if` and `match`
- short circuiting logic operators (`&&` and `||`)
- the `assert` and `debug_assert` macros (if the `const_panic` feature flag is also enabled)

However, the following operations remain forbidden:
- `while`, `loop` and `for` (see #52000)
- the `?` operator (calls `From::from` on its error variant)
- the `assert_eq` and `assert_ne` macros, along with their `debug` variants (calls `fmt::Debug`)

This PR is possible now that we use dataflow for const qualification (see #64470 and #66385).

r? @oli-obk
cc @rust-lang/wg-const-eval @eddyb

1  2 
src/librustc/hir/mod.rs
src/librustc_mir/hair/cx/expr.rs
src/librustc_mir/transform/qualify_min_const_fn.rs
src/libsyntax_pos/symbol.rs

Simple merge
Simple merge
Simple merge