about summary refs log tree commit diff
path: root/src/test/ui/error-codes
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2020-10-01 07:38:47 +0000
committerbors <bors@rust-lang.org>2020-10-01 07:38:47 +0000
commitfc42fb8e70af6ad63998f4bfbf62451551eda073 (patch)
tree13a17a2ee45eb37c3e35980dfb9a6cfcaff70ca9 /src/test/ui/error-codes
parent00730fd0f1df0718f4e0f82298bff3bf1f44a98b (diff)
parent1301f43119f8ae564a01abd3fa306e87d635e862 (diff)
Auto merge of #77354 - ecstatic-morse:const-checking-moar-errors, r=oli-obk
Overhaul const-checking diagnostics

The primary purpose of this PR was to remove `NonConstOp::STOPS_CONST_CHECKING`, which causes any additional errors found by the const-checker to be silenced. I used this flag to preserve diagnostic parity with `qualify_min_const_fn.rs`, which has since been removed.

However, simply removing the flag caused a deluge of errors in some cases, since an error would be emitted any time a local or temporary had a wrong type. To remedy this, I added an alternative system (`DiagnosticImportance`) to silence additional error messages that were likely to distract the user from the underlying issue. When an error of the highest importance occurs, all less important errors are silenced. When no error of the highest importance occurs, all less important errors are emitted after checking is complete. Following the suggestions from the important error is usually enough to fix the less important errors, so this should lead to better UX most of the time.

There's also some unrelated diagnostics improvements in this PR isolated in their own commits. Splitting them out would be possible, but a bit of a pain. This isn't as tidy as some of my other PRs, but it should *only* affect diagnostics, never whether or not something passes const-checking. Note that there are a few trivial exceptions to this, like banning `Yield` in all const-contexts, not just `const fn`.

As always, meant to be reviewed commit-by-commit.

r? `@oli-obk`
Diffstat (limited to 'src/test/ui/error-codes')
-rw-r--r--src/test/ui/error-codes/E0010-teach.rs1
-rw-r--r--src/test/ui/error-codes/E0010-teach.stderr15
-rw-r--r--src/test/ui/error-codes/E0010.rs1
-rw-r--r--src/test/ui/error-codes/E0010.stderr13
-rw-r--r--src/test/ui/error-codes/E0017.rs2
-rw-r--r--src/test/ui/error-codes/E0017.stderr14
-rw-r--r--src/test/ui/error-codes/E0388.rs4
-rw-r--r--src/test/ui/error-codes/E0388.stderr14
8 files changed, 13 insertions, 51 deletions
diff --git a/src/test/ui/error-codes/E0010-teach.rs b/src/test/ui/error-codes/E0010-teach.rs
index da51035ab55..fc5dffb37cf 100644
--- a/src/test/ui/error-codes/E0010-teach.rs
+++ b/src/test/ui/error-codes/E0010-teach.rs
@@ -4,6 +4,5 @@
 #![allow(warnings)]
 
 const CON : Box<i32> = box 0; //~ ERROR E0010
-//~^ ERROR constant contains unimplemented expression type
 
 fn main() {}
diff --git a/src/test/ui/error-codes/E0010-teach.stderr b/src/test/ui/error-codes/E0010-teach.stderr
index c15ab5c655a..33de9fd685e 100644
--- a/src/test/ui/error-codes/E0010-teach.stderr
+++ b/src/test/ui/error-codes/E0010-teach.stderr
@@ -6,17 +6,6 @@ LL | const CON : Box<i32> = box 0;
    |
    = note: The value of statics and constants must be known at compile time, and they live for the entire lifetime of a program. Creating a boxed value allocates memory on the heap at runtime, and therefore cannot be done at compile time.
 
-error[E0019]: constant contains unimplemented expression type
-  --> $DIR/E0010-teach.rs:6:28
-   |
-LL | const CON : Box<i32> = box 0;
-   |                            ^
-   |
-   = help: add `#![feature(const_mut_refs)]` to the crate attributes to enable
-   = note: A function call isn't allowed in the const's initialization expression because the expression's value must be known at compile-time.
-   = note: Remember: you can't use a function call inside a const's initialization expression! However, you can use it anywhere else.
-
-error: aborting due to 2 previous errors
+error: aborting due to previous error
 
-Some errors have detailed explanations: E0010, E0019.
-For more information about an error, try `rustc --explain E0010`.
+For more information about this error, try `rustc --explain E0010`.
diff --git a/src/test/ui/error-codes/E0010.rs b/src/test/ui/error-codes/E0010.rs
index 3398e2c28ba..e62997640f4 100644
--- a/src/test/ui/error-codes/E0010.rs
+++ b/src/test/ui/error-codes/E0010.rs
@@ -2,6 +2,5 @@
 #![allow(warnings)]
 
 const CON : Box<i32> = box 0; //~ ERROR E0010
-//~^ ERROR constant contains unimplemented expression type
 
 fn main() {}
diff --git a/src/test/ui/error-codes/E0010.stderr b/src/test/ui/error-codes/E0010.stderr
index f49fb9c4632..0042333b98a 100644
--- a/src/test/ui/error-codes/E0010.stderr
+++ b/src/test/ui/error-codes/E0010.stderr
@@ -4,15 +4,6 @@ error[E0010]: allocations are not allowed in constants
 LL | const CON : Box<i32> = box 0;
    |                        ^^^^^ allocation not allowed in constants
 
-error[E0019]: constant contains unimplemented expression type
-  --> $DIR/E0010.rs:4:28
-   |
-LL | const CON : Box<i32> = box 0;
-   |                            ^
-   |
-   = help: add `#![feature(const_mut_refs)]` to the crate attributes to enable
-
-error: aborting due to 2 previous errors
+error: aborting due to previous error
 
-Some errors have detailed explanations: E0010, E0019.
-For more information about an error, try `rustc --explain E0010`.
+For more information about this error, try `rustc --explain E0010`.
diff --git a/src/test/ui/error-codes/E0017.rs b/src/test/ui/error-codes/E0017.rs
index 54d3cc54a84..262f7bc72c7 100644
--- a/src/test/ui/error-codes/E0017.rs
+++ b/src/test/ui/error-codes/E0017.rs
@@ -5,8 +5,8 @@ static mut M: i32 = 3;
 const CR: &'static mut i32 = &mut C; //~ ERROR E0764
                                      //~| WARN taking a mutable
 static STATIC_REF: &'static mut i32 = &mut X; //~ ERROR E0764
-                                              //~| ERROR E0019
                                               //~| ERROR cannot borrow
+
 static CONST_REF: &'static mut i32 = &mut C; //~ ERROR E0764
                                               //~| WARN taking a mutable
 static STATIC_MUT_REF: &'static mut i32 = unsafe { &mut M }; //~ ERROR E0764
diff --git a/src/test/ui/error-codes/E0017.stderr b/src/test/ui/error-codes/E0017.stderr
index 40ef6bd97b3..ea591587e6d 100644
--- a/src/test/ui/error-codes/E0017.stderr
+++ b/src/test/ui/error-codes/E0017.stderr
@@ -19,14 +19,6 @@ error[E0764]: mutable references are not allowed in constants
 LL | const CR: &'static mut i32 = &mut C;
    |                              ^^^^^^ `&mut` is only allowed in `const fn`
 
-error[E0019]: static contains unimplemented expression type
-  --> $DIR/E0017.rs:7:39
-   |
-LL | static STATIC_REF: &'static mut i32 = &mut X;
-   |                                       ^^^^^^
-   |
-   = help: add `#![feature(const_mut_refs)]` to the crate attributes to enable
-
 error[E0764]: mutable references are not allowed in statics
   --> $DIR/E0017.rs:7:39
    |
@@ -65,7 +57,7 @@ error[E0764]: mutable references are not allowed in statics
 LL | static STATIC_MUT_REF: &'static mut i32 = unsafe { &mut M };
    |                                                    ^^^^^^ `&mut` is only allowed in `const fn`
 
-error: aborting due to 6 previous errors; 2 warnings emitted
+error: aborting due to 5 previous errors; 2 warnings emitted
 
-Some errors have detailed explanations: E0019, E0596, E0764.
-For more information about an error, try `rustc --explain E0019`.
+Some errors have detailed explanations: E0596, E0764.
+For more information about an error, try `rustc --explain E0596`.
diff --git a/src/test/ui/error-codes/E0388.rs b/src/test/ui/error-codes/E0388.rs
index 8ad586bb30f..bb0c4979b9a 100644
--- a/src/test/ui/error-codes/E0388.rs
+++ b/src/test/ui/error-codes/E0388.rs
@@ -3,9 +3,9 @@ const C: i32 = 2;
 
 const CR: &'static mut i32 = &mut C; //~ ERROR E0764
                                      //~| WARN taking a mutable
-static STATIC_REF: &'static mut i32 = &mut X; //~ ERROR E0019
-                                              //~| ERROR cannot borrow
+static STATIC_REF: &'static mut i32 = &mut X; //~ ERROR cannot borrow
                                               //~| ERROR E0764
+
 static CONST_REF: &'static mut i32 = &mut C; //~ ERROR E0764
                                              //~| WARN taking a mutable
 
diff --git a/src/test/ui/error-codes/E0388.stderr b/src/test/ui/error-codes/E0388.stderr
index 39bc717ceec..73e0b139cd0 100644
--- a/src/test/ui/error-codes/E0388.stderr
+++ b/src/test/ui/error-codes/E0388.stderr
@@ -19,14 +19,6 @@ error[E0764]: mutable references are not allowed in constants
 LL | const CR: &'static mut i32 = &mut C;
    |                              ^^^^^^ `&mut` is only allowed in `const fn`
 
-error[E0019]: static contains unimplemented expression type
-  --> $DIR/E0388.rs:6:39
-   |
-LL | static STATIC_REF: &'static mut i32 = &mut X;
-   |                                       ^^^^^^
-   |
-   = help: add `#![feature(const_mut_refs)]` to the crate attributes to enable
-
 error[E0764]: mutable references are not allowed in statics
   --> $DIR/E0388.rs:6:39
    |
@@ -59,7 +51,7 @@ error[E0764]: mutable references are not allowed in statics
 LL | static CONST_REF: &'static mut i32 = &mut C;
    |                                      ^^^^^^ `&mut` is only allowed in `const fn`
 
-error: aborting due to 5 previous errors; 2 warnings emitted
+error: aborting due to 4 previous errors; 2 warnings emitted
 
-Some errors have detailed explanations: E0019, E0596, E0764.
-For more information about an error, try `rustc --explain E0019`.
+Some errors have detailed explanations: E0596, E0764.
+For more information about an error, try `rustc --explain E0596`.