about summary refs log tree commit diff
path: root/src/test/ui/issues
diff options
context:
space:
mode:
authorMazdak Farrokhzad <twingoow@gmail.com>2019-01-12 10:54:56 +0100
committerGitHub <noreply@github.com>2019-01-12 10:54:56 +0100
commitbd8f46487761fe7e1d1feb301a7e45231ca2c0fe (patch)
treecba4990b610d2de89a9e87486110a5b7ab37cf60 /src/test/ui/issues
parent017f046c1371758bf4363afd4384bafb583b9710 (diff)
parent6c623224dcf6f7cf06afd46b17ce7f665e6b4fda (diff)
downloadrust-bd8f46487761fe7e1d1feb301a7e45231ca2c0fe.tar.gz
rust-bd8f46487761fe7e1d1feb301a7e45231ca2c0fe.zip
Rollup merge of #57175 - oli-obk:const_let_stabilization, r=nikomatsakis
Stabilize `let` bindings and destructuring in constants and const fn

r? @Centril

This PR stabilizes the following features in constants and `const` functions:

* irrefutable destructuring patterns (e.g. `const fn foo((x, y): (u8, u8)) { ... }`)
* `let` bindings (e.g. `let x = 1;`)
* mutable `let` bindings (e.g. `let mut x = 1;`)
* assignment (e.g. `x = y`) and assignment operator (e.g. `x += y`) expressions, even where the assignment target is a projection (e.g. a struct field or index operation like `x[3] = 42`)
* expression statements (e.g. `3;`)

This PR does explicitly *not* stabilize:

* mutable references (i.e. `&mut T`)
* dereferencing mutable references
* refutable patterns (e.g. `Some(x)`)
* operations on `UnsafeCell` types (as that would need raw pointers and mutable references and such, not because it is explicitly forbidden. We can't explicitly forbid it as such values are OK as long as they aren't mutated.)
* We are not stabilizing `let` bindings in constants that use `&&` and `||` short circuiting operations. These are treated as `&` and `|` inside `const` and `static` items right now. If we stopped treating them as `&` and `|` after stabilizing `let` bindings, we'd break code like `let mut x = false; false && { x = true; false };`. So to use `let` bindings in constants you need to change `&&` and `||` to `&` and `|` respectively.
Diffstat (limited to 'src/test/ui/issues')
-rw-r--r--src/test/ui/issues/issue-18118.nll.stderr60
-rw-r--r--src/test/ui/issues/issue-18118.rs5
-rw-r--r--src/test/ui/issues/issue-18118.stderr60
-rw-r--r--src/test/ui/issues/issue-32829-2.rs15
-rw-r--r--src/test/ui/issues/issue-32829-2.stderr83
-rw-r--r--src/test/ui/issues/issue-37550.rs4
-rw-r--r--src/test/ui/issues/issue-37550.stderr6
-rw-r--r--src/test/ui/issues/issue-7364.rs1
-rw-r--r--src/test/ui/issues/issue-7364.stderr10
9 files changed, 27 insertions, 217 deletions
diff --git a/src/test/ui/issues/issue-18118.nll.stderr b/src/test/ui/issues/issue-18118.nll.stderr
index d3084b06167..1920e1637d1 100644
--- a/src/test/ui/issues/issue-18118.nll.stderr
+++ b/src/test/ui/issues/issue-18118.nll.stderr
@@ -1,68 +1,14 @@
-error[E0658]: let bindings in constants are unstable (see issue #48821)
-  --> $DIR/issue-18118.rs:5:17
-   |
-LL |         let p = 3;
-   |                 ^
-   |
-   = help: add #![feature(const_let)] to the crate attributes to enable
-
-error[E0658]: statements in constants are unstable (see issue #48821)
-  --> $DIR/issue-18118.rs:5:17
-   |
-LL |         let p = 3;
-   |                 ^
-   |
-   = help: add #![feature(const_let)] to the crate attributes to enable
-
-error[E0658]: let bindings in constants are unstable (see issue #48821)
-  --> $DIR/issue-18118.rs:8:9
-   |
-LL |         &p //~ ERROR `p` does not live long enough
-   |         ^^
-   |
-   = help: add #![feature(const_let)] to the crate attributes to enable
-
-error[E0658]: let bindings in constants are unstable (see issue #48821)
-  --> $DIR/issue-18118.rs:2:5
-   |
-LL | /     const z: &'static isize = {
-LL | |         //~^ ERROR let bindings in constants are unstable
-LL | |         //~| ERROR statements in constants are unstable
-LL | |         let p = 3;
-...  |
-LL | |         //~^ ERROR let bindings in constants are unstable
-LL | |     };
-   | |______^
-   |
-   = help: add #![feature(const_let)] to the crate attributes to enable
-
-error[E0658]: statements in constants are unstable (see issue #48821)
-  --> $DIR/issue-18118.rs:2:5
-   |
-LL | /     const z: &'static isize = {
-LL | |         //~^ ERROR let bindings in constants are unstable
-LL | |         //~| ERROR statements in constants are unstable
-LL | |         let p = 3;
-...  |
-LL | |         //~^ ERROR let bindings in constants are unstable
-LL | |     };
-   | |______^
-   |
-   = help: add #![feature(const_let)] to the crate attributes to enable
-
 error[E0597]: `p` does not live long enough
-  --> $DIR/issue-18118.rs:8:9
+  --> $DIR/issue-18118.rs:4:9
    |
 LL |         &p //~ ERROR `p` does not live long enough
    |         ^^
    |         |
    |         borrowed value does not live long enough
    |         using this value as a constant requires that `p` is borrowed for `'static`
-LL |         //~^ ERROR let bindings in constants are unstable
 LL |     };
    |     - `p` dropped here while still borrowed
 
-error: aborting due to 6 previous errors
+error: aborting due to previous error
 
-Some errors occurred: E0597, E0658.
-For more information about an error, try `rustc --explain E0597`.
+For more information about this error, try `rustc --explain E0597`.
diff --git a/src/test/ui/issues/issue-18118.rs b/src/test/ui/issues/issue-18118.rs
index 7bbea191cd1..f58a3de281f 100644
--- a/src/test/ui/issues/issue-18118.rs
+++ b/src/test/ui/issues/issue-18118.rs
@@ -1,11 +1,6 @@
 pub fn main() {
     const z: &'static isize = {
-        //~^ ERROR let bindings in constants are unstable
-        //~| ERROR statements in constants are unstable
         let p = 3;
-        //~^ ERROR let bindings in constants are unstable
-        //~| ERROR statements in constants are unstable
         &p //~ ERROR `p` does not live long enough
-        //~^ ERROR let bindings in constants are unstable
     };
 }
diff --git a/src/test/ui/issues/issue-18118.stderr b/src/test/ui/issues/issue-18118.stderr
index 1383cdb4438..9b21ece341a 100644
--- a/src/test/ui/issues/issue-18118.stderr
+++ b/src/test/ui/issues/issue-18118.stderr
@@ -1,67 +1,13 @@
-error[E0658]: let bindings in constants are unstable (see issue #48821)
-  --> $DIR/issue-18118.rs:5:17
-   |
-LL |         let p = 3;
-   |                 ^
-   |
-   = help: add #![feature(const_let)] to the crate attributes to enable
-
-error[E0658]: statements in constants are unstable (see issue #48821)
-  --> $DIR/issue-18118.rs:5:17
-   |
-LL |         let p = 3;
-   |                 ^
-   |
-   = help: add #![feature(const_let)] to the crate attributes to enable
-
-error[E0658]: let bindings in constants are unstable (see issue #48821)
-  --> $DIR/issue-18118.rs:8:9
-   |
-LL |         &p //~ ERROR `p` does not live long enough
-   |         ^^
-   |
-   = help: add #![feature(const_let)] to the crate attributes to enable
-
-error[E0658]: let bindings in constants are unstable (see issue #48821)
-  --> $DIR/issue-18118.rs:2:5
-   |
-LL | /     const z: &'static isize = {
-LL | |         //~^ ERROR let bindings in constants are unstable
-LL | |         //~| ERROR statements in constants are unstable
-LL | |         let p = 3;
-...  |
-LL | |         //~^ ERROR let bindings in constants are unstable
-LL | |     };
-   | |______^
-   |
-   = help: add #![feature(const_let)] to the crate attributes to enable
-
-error[E0658]: statements in constants are unstable (see issue #48821)
-  --> $DIR/issue-18118.rs:2:5
-   |
-LL | /     const z: &'static isize = {
-LL | |         //~^ ERROR let bindings in constants are unstable
-LL | |         //~| ERROR statements in constants are unstable
-LL | |         let p = 3;
-...  |
-LL | |         //~^ ERROR let bindings in constants are unstable
-LL | |     };
-   | |______^
-   |
-   = help: add #![feature(const_let)] to the crate attributes to enable
-
 error[E0597]: `p` does not live long enough
-  --> $DIR/issue-18118.rs:8:10
+  --> $DIR/issue-18118.rs:4:10
    |
 LL |         &p //~ ERROR `p` does not live long enough
    |          ^ borrowed value does not live long enough
-LL |         //~^ ERROR let bindings in constants are unstable
 LL |     };
    |     - borrowed value only lives until here
    |
    = note: borrowed value must be valid for the static lifetime...
 
-error: aborting due to 6 previous errors
+error: aborting due to previous error
 
-Some errors occurred: E0597, E0658.
-For more information about an error, try `rustc --explain E0597`.
+For more information about this error, try `rustc --explain E0597`.
diff --git a/src/test/ui/issues/issue-32829-2.rs b/src/test/ui/issues/issue-32829-2.rs
index 9db9d30411d..c93c84b5fb7 100644
--- a/src/test/ui/issues/issue-32829-2.rs
+++ b/src/test/ui/issues/issue-32829-2.rs
@@ -1,11 +1,8 @@
 // ignore-tidy-linelength
 
-#![feature(const_fn)]
-
 const bad : u32 = {
     {
         5;
-        //~^ ERROR statements in constants are unstable
         0
     }
 };
@@ -13,8 +10,7 @@ const bad : u32 = {
 const bad_two : u32 = {
     {
         invalid();
-        //~^ ERROR statements in constants are unstable
-        //~^^ ERROR: calls in constants are limited to constant functions, tuple structs and tuple variants
+        //~^ ERROR: calls in constants are limited to constant functions, tuple structs and tuple variants
         0
     }
 };
@@ -22,7 +18,6 @@ const bad_two : u32 = {
 const bad_three : u32 = {
     {
         valid();
-        //~^ ERROR statements in constants are unstable
         0
     }
 };
@@ -30,7 +25,6 @@ const bad_three : u32 = {
 static bad_four : u32 = {
     {
         5;
-        //~^ ERROR statements in statics are unstable
         0
     }
 };
@@ -39,7 +33,6 @@ static bad_five : u32 = {
     {
         invalid();
         //~^ ERROR: calls in statics are limited to constant functions, tuple structs and tuple variants
-        //~| ERROR statements in statics are unstable
         0
     }
 };
@@ -47,7 +40,6 @@ static bad_five : u32 = {
 static bad_six : u32 = {
     {
         valid();
-        //~^ ERROR statements in statics are unstable
         0
     }
 };
@@ -55,7 +47,6 @@ static bad_six : u32 = {
 static mut bad_seven : u32 = {
     {
         5;
-        //~^ ERROR statements in statics are unstable
         0
     }
 };
@@ -63,8 +54,7 @@ static mut bad_seven : u32 = {
 static mut bad_eight : u32 = {
     {
         invalid();
-        //~^ ERROR statements in statics are unstable
-        //~| ERROR: calls in statics are limited to constant functions, tuple structs and tuple variants
+        //~^ ERROR: calls in statics are limited to constant functions, tuple structs and tuple variants
         0
     }
 };
@@ -72,7 +62,6 @@ static mut bad_eight : u32 = {
 static mut bad_nine : u32 = {
     {
         valid();
-        //~^ ERROR statements in statics are unstable
         0
     }
 };
diff --git a/src/test/ui/issues/issue-32829-2.stderr b/src/test/ui/issues/issue-32829-2.stderr
index 7fe02612818..8d7423f29ae 100644
--- a/src/test/ui/issues/issue-32829-2.stderr
+++ b/src/test/ui/issues/issue-32829-2.stderr
@@ -1,94 +1,21 @@
-error[E0658]: statements in constants are unstable (see issue #48821)
-  --> $DIR/issue-32829-2.rs:7:9
-   |
-LL |         5;
-   |         ^
-   |
-   = help: add #![feature(const_let)] to the crate attributes to enable
-
 error[E0015]: calls in constants are limited to constant functions, tuple structs and tuple variants
-  --> $DIR/issue-32829-2.rs:15:9
+  --> $DIR/issue-32829-2.rs:12:9
    |
 LL |         invalid();
    |         ^^^^^^^^^
 
-error[E0658]: statements in constants are unstable (see issue #48821)
-  --> $DIR/issue-32829-2.rs:15:9
-   |
-LL |         invalid();
-   |         ^^^^^^^^^
-   |
-   = help: add #![feature(const_let)] to the crate attributes to enable
-
-error[E0658]: statements in constants are unstable (see issue #48821)
-  --> $DIR/issue-32829-2.rs:24:9
-   |
-LL |         valid();
-   |         ^^^^^^^
-   |
-   = help: add #![feature(const_let)] to the crate attributes to enable
-
-error[E0658]: statements in statics are unstable (see issue #48821)
-  --> $DIR/issue-32829-2.rs:32:9
-   |
-LL |         5;
-   |         ^
-   |
-   = help: add #![feature(const_let)] to the crate attributes to enable
-
 error[E0015]: calls in statics are limited to constant functions, tuple structs and tuple variants
-  --> $DIR/issue-32829-2.rs:40:9
+  --> $DIR/issue-32829-2.rs:34:9
    |
 LL |         invalid();
    |         ^^^^^^^^^
 
-error[E0658]: statements in statics are unstable (see issue #48821)
-  --> $DIR/issue-32829-2.rs:40:9
-   |
-LL |         invalid();
-   |         ^^^^^^^^^
-   |
-   = help: add #![feature(const_let)] to the crate attributes to enable
-
-error[E0658]: statements in statics are unstable (see issue #48821)
-  --> $DIR/issue-32829-2.rs:49:9
-   |
-LL |         valid();
-   |         ^^^^^^^
-   |
-   = help: add #![feature(const_let)] to the crate attributes to enable
-
-error[E0658]: statements in statics are unstable (see issue #48821)
-  --> $DIR/issue-32829-2.rs:57:9
-   |
-LL |         5;
-   |         ^
-   |
-   = help: add #![feature(const_let)] to the crate attributes to enable
-
 error[E0015]: calls in statics are limited to constant functions, tuple structs and tuple variants
-  --> $DIR/issue-32829-2.rs:65:9
+  --> $DIR/issue-32829-2.rs:56:9
    |
 LL |         invalid();
    |         ^^^^^^^^^
 
-error[E0658]: statements in statics are unstable (see issue #48821)
-  --> $DIR/issue-32829-2.rs:65:9
-   |
-LL |         invalid();
-   |         ^^^^^^^^^
-   |
-   = help: add #![feature(const_let)] to the crate attributes to enable
-
-error[E0658]: statements in statics are unstable (see issue #48821)
-  --> $DIR/issue-32829-2.rs:74:9
-   |
-LL |         valid();
-   |         ^^^^^^^
-   |
-   = help: add #![feature(const_let)] to the crate attributes to enable
-
-error: aborting due to 12 previous errors
+error: aborting due to 3 previous errors
 
-Some errors occurred: E0015, E0658.
-For more information about an error, try `rustc --explain E0015`.
+For more information about this error, try `rustc --explain E0015`.
diff --git a/src/test/ui/issues/issue-37550.rs b/src/test/ui/issues/issue-37550.rs
index 12282f3e548..505c030b967 100644
--- a/src/test/ui/issues/issue-37550.rs
+++ b/src/test/ui/issues/issue-37550.rs
@@ -1,6 +1,6 @@
 const fn x() {
-    let t = true; //~ ERROR local variables in const fn
-    let x = || t;
+    let t = true;
+    let x = || t; //~ ERROR function pointers in const fn are unstable
 }
 
 fn main() {}
diff --git a/src/test/ui/issues/issue-37550.stderr b/src/test/ui/issues/issue-37550.stderr
index d42f72ad3fa..d2b03416cb7 100644
--- a/src/test/ui/issues/issue-37550.stderr
+++ b/src/test/ui/issues/issue-37550.stderr
@@ -1,7 +1,7 @@
-error: local variables in const fn are unstable
-  --> $DIR/issue-37550.rs:2:9
+error: function pointers in const fn are unstable
+  --> $DIR/issue-37550.rs:3:9
    |
-LL |     let t = true; //~ ERROR local variables in const fn
+LL |     let x = || t; //~ ERROR function pointers in const fn are unstable
    |         ^
 
 error: aborting due to previous error
diff --git a/src/test/ui/issues/issue-7364.rs b/src/test/ui/issues/issue-7364.rs
index 3f9c2ef48a7..52ec9e42be7 100644
--- a/src/test/ui/issues/issue-7364.rs
+++ b/src/test/ui/issues/issue-7364.rs
@@ -6,5 +6,6 @@ use std::cell::RefCell;
 static boxed: Box<RefCell<isize>> = box RefCell::new(0);
 //~^ ERROR allocations are not allowed in statics
 //~| ERROR `std::cell::RefCell<isize>` cannot be shared between threads safely [E0277]
+//~| ERROR static contains unimplemented expression type
 
 fn main() { }
diff --git a/src/test/ui/issues/issue-7364.stderr b/src/test/ui/issues/issue-7364.stderr
index 0e4d6ff1d71..52a99ce36b8 100644
--- a/src/test/ui/issues/issue-7364.stderr
+++ b/src/test/ui/issues/issue-7364.stderr
@@ -4,6 +4,12 @@ error[E0010]: allocations are not allowed in statics
 LL | static boxed: Box<RefCell<isize>> = box RefCell::new(0);
    |                                     ^^^^^^^^^^^^^^^^^^^ allocation not allowed in statics
 
+error[E0019]: static contains unimplemented expression type
+  --> $DIR/issue-7364.rs:6:41
+   |
+LL | static boxed: Box<RefCell<isize>> = box RefCell::new(0);
+   |                                         ^^^^^^^^^^^^^^^
+
 error[E0277]: `std::cell::RefCell<isize>` cannot be shared between threads safely
   --> $DIR/issue-7364.rs:6:1
    |
@@ -15,7 +21,7 @@ LL | static boxed: Box<RefCell<isize>> = box RefCell::new(0);
    = note: required because it appears within the type `std::boxed::Box<std::cell::RefCell<isize>>`
    = note: shared static variables must have a type that implements `Sync`
 
-error: aborting due to 2 previous errors
+error: aborting due to 3 previous errors
 
-Some errors occurred: E0010, E0277.
+Some errors occurred: E0010, E0019, E0277.
 For more information about an error, try `rustc --explain E0010`.