about summary refs log tree commit diff
path: root/src/test
diff options
context:
space:
mode:
authorMatthew Jasper <mjjasper1@gmail.com>2019-10-07 21:08:39 +0100
committerMatthew Jasper <mjjasper1@gmail.com>2019-10-27 21:25:35 +0000
commit170718c93f3defba2edee69bae7abd64d1672355 (patch)
tree113d98102bc52d32c2d72f333a44606dcfc7114f /src/test
parent95f437b3cfb2fec966d7eaf69d7c2e36f9c274d1 (diff)
downloadrust-170718c93f3defba2edee69bae7abd64d1672355.tar.gz
rust-170718c93f3defba2edee69bae7abd64d1672355.zip
Stabilize `const_constructor`
Diffstat (limited to 'src/test')
-rw-r--r--src/test/ui/consts/const_constructor/const-construct-call.rs2
-rw-r--r--src/test/ui/consts/const_constructor/const_constructor_qpath.rs40
-rw-r--r--src/test/ui/consts/const_constructor/feature-gate-const_constructor.const_fn.stderr34
-rw-r--r--src/test/ui/consts/const_constructor/feature-gate-const_constructor.min_const_fn.stderr34
-rw-r--r--src/test/ui/consts/const_constructor/feature-gate-const_constructor.rs28
5 files changed, 40 insertions, 98 deletions
diff --git a/src/test/ui/consts/const_constructor/const-construct-call.rs b/src/test/ui/consts/const_constructor/const-construct-call.rs
index f2d2bda53c0..d883d3fa6e4 100644
--- a/src/test/ui/consts/const_constructor/const-construct-call.rs
+++ b/src/test/ui/consts/const_constructor/const-construct-call.rs
@@ -6,8 +6,6 @@
 
 #![cfg_attr(const_fn, feature(const_fn))]
 
-#![feature(const_constructor)]
-
 // Ctor(..) is transformed to Ctor { 0: ... } in HAIR lowering, so directly
 // calling constructors doesn't require them to be const.
 
diff --git a/src/test/ui/consts/const_constructor/const_constructor_qpath.rs b/src/test/ui/consts/const_constructor/const_constructor_qpath.rs
new file mode 100644
index 00000000000..18aa3d8e816
--- /dev/null
+++ b/src/test/ui/consts/const_constructor/const_constructor_qpath.rs
@@ -0,0 +1,40 @@
+// revisions: min_const_fn const_fn
+// run-pass
+
+#![cfg_attr(const_fn, feature(const_fn))]
+
+trait ConstDefault {
+    const DEFAULT: Self;
+}
+
+#[derive(PartialEq)]
+enum E {
+    V(i32),
+    W(usize),
+}
+
+impl ConstDefault for E {
+    const DEFAULT: Self = Self::V(23);
+}
+
+impl ConstDefault for Option<i32> {
+    const DEFAULT: Self = Self::Some(23);
+}
+
+impl E {
+    const NON_DEFAULT: Self = Self::W(12);
+    const fn local_fn() -> Self {
+        Self::V(23)
+    }
+}
+
+const fn explicit_qpath() -> E {
+    let _x = <Option<usize>>::Some(23);
+    <E>::W(12)
+}
+
+fn main() {
+    assert!(E::DEFAULT == E::local_fn());
+    assert!(Option::DEFAULT == Some(23));
+    assert!(E::NON_DEFAULT == explicit_qpath());
+}
diff --git a/src/test/ui/consts/const_constructor/feature-gate-const_constructor.const_fn.stderr b/src/test/ui/consts/const_constructor/feature-gate-const_constructor.const_fn.stderr
deleted file mode 100644
index fa4f83ed01e..00000000000
--- a/src/test/ui/consts/const_constructor/feature-gate-const_constructor.const_fn.stderr
+++ /dev/null
@@ -1,34 +0,0 @@
-error: `std::prelude::v1::Some` is not yet stable as a const fn
-  --> $DIR/feature-gate-const_constructor.rs:9:37
-   |
-LL | const EXTERNAL_CONST: Option<i32> = {Some}(1);
-   |                                     ^^^^^^^^^
-   |
-   = help: add `#![feature(const_constructor)]` to the crate attributes to enable
-
-error: `E::V` is not yet stable as a const fn
-  --> $DIR/feature-gate-const_constructor.rs:12:24
-   |
-LL | const LOCAL_CONST: E = {E::V}(1);
-   |                        ^^^^^^^^^
-   |
-   = help: add `#![feature(const_constructor)]` to the crate attributes to enable
-
-error: `std::prelude::v1::Some` is not yet stable as a const fn
-  --> $DIR/feature-gate-const_constructor.rs:17:13
-   |
-LL |     let _ = {Some}(1);
-   |             ^^^^^^^^^
-   |
-   = help: add `#![feature(const_constructor)]` to the crate attributes to enable
-
-error: `E::V` is not yet stable as a const fn
-  --> $DIR/feature-gate-const_constructor.rs:23:13
-   |
-LL |     let _ = {E::V}(1);
-   |             ^^^^^^^^^
-   |
-   = help: add `#![feature(const_constructor)]` to the crate attributes to enable
-
-error: aborting due to 4 previous errors
-
diff --git a/src/test/ui/consts/const_constructor/feature-gate-const_constructor.min_const_fn.stderr b/src/test/ui/consts/const_constructor/feature-gate-const_constructor.min_const_fn.stderr
deleted file mode 100644
index fa4f83ed01e..00000000000
--- a/src/test/ui/consts/const_constructor/feature-gate-const_constructor.min_const_fn.stderr
+++ /dev/null
@@ -1,34 +0,0 @@
-error: `std::prelude::v1::Some` is not yet stable as a const fn
-  --> $DIR/feature-gate-const_constructor.rs:9:37
-   |
-LL | const EXTERNAL_CONST: Option<i32> = {Some}(1);
-   |                                     ^^^^^^^^^
-   |
-   = help: add `#![feature(const_constructor)]` to the crate attributes to enable
-
-error: `E::V` is not yet stable as a const fn
-  --> $DIR/feature-gate-const_constructor.rs:12:24
-   |
-LL | const LOCAL_CONST: E = {E::V}(1);
-   |                        ^^^^^^^^^
-   |
-   = help: add `#![feature(const_constructor)]` to the crate attributes to enable
-
-error: `std::prelude::v1::Some` is not yet stable as a const fn
-  --> $DIR/feature-gate-const_constructor.rs:17:13
-   |
-LL |     let _ = {Some}(1);
-   |             ^^^^^^^^^
-   |
-   = help: add `#![feature(const_constructor)]` to the crate attributes to enable
-
-error: `E::V` is not yet stable as a const fn
-  --> $DIR/feature-gate-const_constructor.rs:23:13
-   |
-LL |     let _ = {E::V}(1);
-   |             ^^^^^^^^^
-   |
-   = help: add `#![feature(const_constructor)]` to the crate attributes to enable
-
-error: aborting due to 4 previous errors
-
diff --git a/src/test/ui/consts/const_constructor/feature-gate-const_constructor.rs b/src/test/ui/consts/const_constructor/feature-gate-const_constructor.rs
deleted file mode 100644
index b37fd2fd243..00000000000
--- a/src/test/ui/consts/const_constructor/feature-gate-const_constructor.rs
+++ /dev/null
@@ -1,28 +0,0 @@
-// revisions: min_const_fn const_fn
-
-#![cfg_attr(const_fn, feature(const_fn))]
-
-enum E {
-    V(i32),
-}
-
-const EXTERNAL_CONST: Option<i32> = {Some}(1);
-//[min_const_fn]~^ ERROR is not yet stable as a const fn
-//[const_fn]~^^ ERROR is not yet stable as a const fn
-const LOCAL_CONST: E = {E::V}(1);
-//[min_const_fn]~^ ERROR is not yet stable as a const fn
-//[const_fn]~^^ ERROR is not yet stable as a const fn
-
-const fn external_fn() {
-    let _ = {Some}(1);
-    //[min_const_fn]~^ ERROR is not yet stable as a const fn
-    //[const_fn]~^^ ERROR is not yet stable as a const fn
-}
-
-const fn local_fn() {
-    let _ = {E::V}(1);
-    //[min_const_fn]~^ ERROR is not yet stable as a const fn
-    //[const_fn]~^^ ERROR is not yet stable as a const fn
-}
-
-fn main() {}