about summary refs log tree commit diff
path: root/src/libsyntax
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
parenta449535bbc7912c4adc1bbf2ab2738d0442f212c (diff)
parentb09bb1569b23eaadcf22d7420f1ba9872c1088f7 (diff)
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')
-rw-r--r--src/libsyntax/feature_gate/active.rs3
1 files changed, 3 insertions, 0 deletions
diff --git a/src/libsyntax/feature_gate/active.rs b/src/libsyntax/feature_gate/active.rs
index bd029514a95..fa0ab90c702 100644
--- a/src/libsyntax/feature_gate/active.rs
+++ b/src/libsyntax/feature_gate/active.rs
@@ -529,6 +529,9 @@ declare_features! (
     /// Allows using the `#[register_attr]` attribute.
     (active, register_tool, "1.41.0", Some(66079), None),
 
+    /// Allows the use of `if` and `match` in constants.
+    (active, const_if_match, "1.41.0", Some(49146), None),
+
     // -------------------------------------------------------------------------
     // feature-group-end: actual feature gates
     // -------------------------------------------------------------------------