about summary refs log tree commit diff
path: root/src/libsyntax_pos
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2019-11-23 01:13:41 +0000
committerbors <bors@rust-lang.org>2019-11-23 01:13:41 +0000
commit6d523ee501a1ae30428d22ce4fc3c1f720e896e6 (patch)
tree94b996d5eab8f40f1b541501df4ddfddd97000ce /src/libsyntax_pos
parenta449535bbc7912c4adc1bbf2ab2738d0442f212c (diff)
parentb09bb1569b23eaadcf22d7420f1ba9872c1088f7 (diff)
downloadrust-6d523ee501a1ae30428d22ce4fc3c1f720e896e6.tar.gz
rust-6d523ee501a1ae30428d22ce4fc3c1f720e896e6.zip
Auto merge of #66507 - ecstatic-morse:const-if-match, r=oli-obk
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
Diffstat (limited to 'src/libsyntax_pos')
-rw-r--r--src/libsyntax_pos/symbol.rs1
1 files changed, 1 insertions, 0 deletions
diff --git a/src/libsyntax_pos/symbol.rs b/src/libsyntax_pos/symbol.rs
index 23ee972529a..d20d520ac55 100644
--- a/src/libsyntax_pos/symbol.rs
+++ b/src/libsyntax_pos/symbol.rs
@@ -203,6 +203,7 @@ symbols! {
         const_fn,
         const_fn_union,
         const_generics,
+        const_if_match,
         const_indexing,
         const_in_array_repeat_expressions,
         const_let,