about summary refs log tree commit diff
path: root/src/libsyntax
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2019-10-28 07:38:49 +0000
committerbors <bors@rust-lang.org>2019-10-28 07:38:49 +0000
commit03a50ae9b87021d4a166c70d2c932f1cb0aa8f28 (patch)
treedff9cfee9afb9b5dc1d48c03411ad1286fe29be8 /src/libsyntax
parent9285d401a6070094747465962bc49969b93e14c5 (diff)
parent170718c93f3defba2edee69bae7abd64d1672355 (diff)
Auto merge of #65188 - matthewjasper:stabilize-const-constructor, r=Centril
Stabilize `const_constructor`

# Stabilization proposal

I propose that we stabilize `#![feature(const_constructor)]`.

Tracking issue: https://github.com/rust-lang/rust/issues/61456
Version target: 1.40 (2019-11-05 => beta, 2019-12-19 => stable).

## What is stabilized

### User guide

Tuple struct and tuple variant constructors are now considered to be constant functions. As such a call expression where the callee has a tuple struct or variant constructor "function item" type can be called:

```rust
const fn make_options() {
    // These already work because they are special cased:
    Some(0);
    (Option::Some)(1);
    // These also work now:
    let f = Option::Some;
    f(2);
    {Option::Some}(3);
    <Option<_>>::Some(5);
}
```

### Motivation

Consistency with other `const fn`. Consistency between syntactic path forms.

This should also ensure that constructors implement `const Fn` traits and can be coerced to `const fn` function pointers, if they are introduced.

## Tests

* [ui/consts/const_constructor/const-construct-call.rs](https://github.com/rust-lang/rust/blob/0d75ab2293a106eb674ac01860910cfc1580837e/src/test/ui/consts/const_constructor/const-construct-call.rs) - Tests various syntactic forms, use in both `const fn` and `const` items, and constructors in both the current and extern crates.
* [ui/consts/const_constructor/const_constructor_qpath.rs](https://github.com/rust-lang/rust/blob/1850dfcdabf8258a1f023f26c2c59e96b869dd95/src/test/ui/consts/const_constructor/const_constructor_qpath.rs) - Tests that type qualified paths to enum variants are also considered to be `const fn`.(#64247)

r? @oli-obk

Closes #61456
Closes  #64247
Diffstat (limited to 'src/libsyntax')
-rw-r--r--src/libsyntax/feature_gate/accepted.rs2
-rw-r--r--src/libsyntax/feature_gate/active.rs3
2 files changed, 2 insertions, 3 deletions
diff --git a/src/libsyntax/feature_gate/accepted.rs b/src/libsyntax/feature_gate/accepted.rs
index 36fcab8450b..d309a17298b 100644
--- a/src/libsyntax/feature_gate/accepted.rs
+++ b/src/libsyntax/feature_gate/accepted.rs
@@ -249,6 +249,8 @@ declare_features! (
     (accepted, macros_in_extern, "1.40.0", Some(49476), None),
     /// Allows future-proofing enums/structs with the `#[non_exhaustive]` attribute (RFC 2008).
     (accepted, non_exhaustive, "1.40.0", Some(44109), None),
+    /// Allows calling constructor functions in `const fn`.
+    (accepted, const_constructor, "1.40.0", Some(61456), None),
 
     // -------------------------------------------------------------------------
     // feature-group-end: accepted features
diff --git a/src/libsyntax/feature_gate/active.rs b/src/libsyntax/feature_gate/active.rs
index f6e1d6c4224..3754a3d6fe9 100644
--- a/src/libsyntax/feature_gate/active.rs
+++ b/src/libsyntax/feature_gate/active.rs
@@ -488,9 +488,6 @@ declare_features! (
     /// Allows the user of associated type bounds.
     (active, associated_type_bounds, "1.34.0", Some(52662), None),
 
-    /// Allows calling constructor functions in `const fn`.
-    (active, const_constructor, "1.37.0", Some(61456), None),
-
     /// Allows `if/while p && let q = r && ...` chains.
     (active, let_chains, "1.37.0", Some(53667), None),