about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2024-02-20 09:02:34 +0000
committerbors <bors@rust-lang.org>2024-02-20 09:02:34 +0000
commitba2139afd636061fd98626be65c1700e662eb976 (patch)
treea1c37871bf7c07193898d9ad77c3e33f7e9e3472
parent16d5a2be3d938cc3a8263a88fe2229758115dbb2 (diff)
parentd136b05c1be89db5bce650b6ef5e3ae3f521bf86 (diff)
downloadrust-ba2139afd636061fd98626be65c1700e662eb976.tar.gz
rust-ba2139afd636061fd98626be65c1700e662eb976.zip
Auto merge of #121087 - oli-obk:eager_const_failures, r=lcnr
Always evaluate free constants and statics, even if previous errors occurred

work towards https://github.com/rust-lang/rust/issues/79738

We will need to evaluate static items before the `definitions.freeze()` below, as we will start creating new `DefId`s (for nested allocations) within the `eval_static_initializer` query.

But even without that motivation, this is a good change. Hard errors should always be reported and not silenced if other errors happened earlier.
-rw-r--r--tests/ui-toml/suppress_lint_in_const/test.rs5
-rw-r--r--tests/ui-toml/suppress_lint_in_const/test.stderr33
-rw-r--r--tests/ui/indexing_slicing_index.rs2
-rw-r--r--tests/ui/indexing_slicing_index.stderr47
4 files changed, 23 insertions, 64 deletions
diff --git a/tests/ui-toml/suppress_lint_in_const/test.rs b/tests/ui-toml/suppress_lint_in_const/test.rs
index 3edb3a10b76..4ae75544c60 100644
--- a/tests/ui-toml/suppress_lint_in_const/test.rs
+++ b/tests/ui-toml/suppress_lint_in_const/test.rs
@@ -13,8 +13,6 @@
 
 const ARR: [i32; 2] = [1, 2];
 const REF: &i32 = &ARR[idx()]; // Ok, should not produce stderr, since `suppress-restriction-lint-in-const` is set true.
-const REF_ERR: &i32 = &ARR[idx4()]; // Ok, let rustc handle const contexts.
-//~^ ERROR: failed
 
 const fn idx() -> usize {
     1
@@ -35,9 +33,6 @@ fn main() {
     x[const { idx() }]; // Ok, should not produce stderr.
     x[const { idx4() }]; // Ok, let rustc's `unconditional_panic` lint handle `usize` indexing on arrays.
     const { &ARR[idx()] }; // Ok, should not produce stderr, since `suppress-restriction-lint-in-const` is set true.
-    const { &ARR[idx4()] }; // Ok, should not produce stderr, since `suppress-restriction-lint-in-const` is set true.
-    //
-    //~^^ ERROR: failed
 
     let y = &x;
     y[0]; // Ok, referencing shouldn't affect this lint. See the issue 6021
diff --git a/tests/ui-toml/suppress_lint_in_const/test.stderr b/tests/ui-toml/suppress_lint_in_const/test.stderr
index 84e7eff4557..d5ce891b680 100644
--- a/tests/ui-toml/suppress_lint_in_const/test.stderr
+++ b/tests/ui-toml/suppress_lint_in_const/test.stderr
@@ -1,17 +1,5 @@
-error[E0080]: evaluation of `main::{constant#3}` failed
-  --> $DIR/test.rs:38:14
-   |
-LL |     const { &ARR[idx4()] }; // Ok, should not produce stderr, since `suppress-restriction-lint-in-const` is set true.
-   |              ^^^^^^^^^^^ index out of bounds: the length is 2 but the index is 4
-
-note: erroneous constant encountered
-  --> $DIR/test.rs:38:5
-   |
-LL |     const { &ARR[idx4()] }; // Ok, should not produce stderr, since `suppress-restriction-lint-in-const` is set true.
-   |     ^^^^^^^^^^^^^^^^^^^^^^
-
 error: indexing may panic
-  --> $DIR/test.rs:29:5
+  --> $DIR/test.rs:27:5
    |
 LL |     x[index];
    |     ^^^^^^^^
@@ -21,7 +9,7 @@ LL |     x[index];
    = help: to override `-D warnings` add `#[allow(clippy::indexing_slicing)]`
 
 error: indexing may panic
-  --> $DIR/test.rs:47:5
+  --> $DIR/test.rs:42:5
    |
 LL |     v[0];
    |     ^^^^
@@ -29,7 +17,7 @@ LL |     v[0];
    = help: consider using `.get(n)` or `.get_mut(n)` instead
 
 error: indexing may panic
-  --> $DIR/test.rs:48:5
+  --> $DIR/test.rs:43:5
    |
 LL |     v[10];
    |     ^^^^^
@@ -37,7 +25,7 @@ LL |     v[10];
    = help: consider using `.get(n)` or `.get_mut(n)` instead
 
 error: indexing may panic
-  --> $DIR/test.rs:49:5
+  --> $DIR/test.rs:44:5
    |
 LL |     v[1 << 3];
    |     ^^^^^^^^^
@@ -45,7 +33,7 @@ LL |     v[1 << 3];
    = help: consider using `.get(n)` or `.get_mut(n)` instead
 
 error: indexing may panic
-  --> $DIR/test.rs:55:5
+  --> $DIR/test.rs:50:5
    |
 LL |     v[N];
    |     ^^^^
@@ -53,19 +41,12 @@ LL |     v[N];
    = help: consider using `.get(n)` or `.get_mut(n)` instead
 
 error: indexing may panic
-  --> $DIR/test.rs:56:5
+  --> $DIR/test.rs:51:5
    |
 LL |     v[M];
    |     ^^^^
    |
    = help: consider using `.get(n)` or `.get_mut(n)` instead
 
-error[E0080]: evaluation of constant value failed
-  --> $DIR/test.rs:16:24
-   |
-LL | const REF_ERR: &i32 = &ARR[idx4()]; // Ok, let rustc handle const contexts.
-   |                        ^^^^^^^^^^^ index out of bounds: the length is 2 but the index is 4
-
-error: aborting due to 8 previous errors
+error: aborting due to 6 previous errors
 
-For more information about this error, try `rustc --explain E0080`.
diff --git a/tests/ui/indexing_slicing_index.rs b/tests/ui/indexing_slicing_index.rs
index 1ac0bb11014..2ababad7fc7 100644
--- a/tests/ui/indexing_slicing_index.rs
+++ b/tests/ui/indexing_slicing_index.rs
@@ -13,8 +13,6 @@
 const ARR: [i32; 2] = [1, 2];
 const REF: &i32 = &ARR[idx()]; // This should be linted, since `suppress-restriction-lint-in-const` default is false.
 //~^ ERROR: indexing may panic
-const REF_ERR: &i32 = &ARR[idx4()]; // Ok, let rustc handle const contexts.
-//~^ ERROR: indexing may panic
 
 const fn idx() -> usize {
     1
diff --git a/tests/ui/indexing_slicing_index.stderr b/tests/ui/indexing_slicing_index.stderr
index 6d64fa1e6cf..2996e31a1aa 100644
--- a/tests/ui/indexing_slicing_index.stderr
+++ b/tests/ui/indexing_slicing_index.stderr
@@ -9,29 +9,20 @@ LL | const REF: &i32 = &ARR[idx()]; // This should be linted, since `suppress-re
    = note: `-D clippy::indexing-slicing` implied by `-D warnings`
    = help: to override `-D warnings` add `#[allow(clippy::indexing_slicing)]`
 
-error: indexing may panic
-  --> $DIR/indexing_slicing_index.rs:16:24
-   |
-LL | const REF_ERR: &i32 = &ARR[idx4()]; // Ok, let rustc handle const contexts.
-   |                        ^^^^^^^^^^^
-   |
-   = help: consider using `.get(n)` or `.get_mut(n)` instead
-   = note: the suggestion might not be applicable in constant blocks
-
 error[E0080]: evaluation of `main::{constant#3}` failed
-  --> $DIR/indexing_slicing_index.rs:48:14
+  --> $DIR/indexing_slicing_index.rs:46:14
    |
 LL |     const { &ARR[idx4()] };
    |              ^^^^^^^^^^^ index out of bounds: the length is 2 but the index is 4
 
 note: erroneous constant encountered
-  --> $DIR/indexing_slicing_index.rs:48:5
+  --> $DIR/indexing_slicing_index.rs:46:5
    |
 LL |     const { &ARR[idx4()] };
    |     ^^^^^^^^^^^^^^^^^^^^^^
 
 error: indexing may panic
-  --> $DIR/indexing_slicing_index.rs:29:5
+  --> $DIR/indexing_slicing_index.rs:27:5
    |
 LL |     x[index];
    |     ^^^^^^^^
@@ -39,7 +30,7 @@ LL |     x[index];
    = help: consider using `.get(n)` or `.get_mut(n)` instead
 
 error: index is out of bounds
-  --> $DIR/indexing_slicing_index.rs:32:5
+  --> $DIR/indexing_slicing_index.rs:30:5
    |
 LL |     x[4];
    |     ^^^^
@@ -48,13 +39,13 @@ LL |     x[4];
    = help: to override `-D warnings` add `#[allow(clippy::out_of_bounds_indexing)]`
 
 error: index is out of bounds
-  --> $DIR/indexing_slicing_index.rs:34:5
+  --> $DIR/indexing_slicing_index.rs:32:5
    |
 LL |     x[1 << 3];
    |     ^^^^^^^^^
 
 error: indexing may panic
-  --> $DIR/indexing_slicing_index.rs:45:14
+  --> $DIR/indexing_slicing_index.rs:43:14
    |
 LL |     const { &ARR[idx()] };
    |              ^^^^^^^^^^
@@ -63,7 +54,7 @@ LL |     const { &ARR[idx()] };
    = note: the suggestion might not be applicable in constant blocks
 
 error: indexing may panic
-  --> $DIR/indexing_slicing_index.rs:48:14
+  --> $DIR/indexing_slicing_index.rs:46:14
    |
 LL |     const { &ARR[idx4()] };
    |              ^^^^^^^^^^^
@@ -72,13 +63,13 @@ LL |     const { &ARR[idx4()] };
    = note: the suggestion might not be applicable in constant blocks
 
 error: index is out of bounds
-  --> $DIR/indexing_slicing_index.rs:55:5
+  --> $DIR/indexing_slicing_index.rs:53:5
    |
 LL |     y[4];
    |     ^^^^
 
 error: indexing may panic
-  --> $DIR/indexing_slicing_index.rs:58:5
+  --> $DIR/indexing_slicing_index.rs:56:5
    |
 LL |     v[0];
    |     ^^^^
@@ -86,7 +77,7 @@ LL |     v[0];
    = help: consider using `.get(n)` or `.get_mut(n)` instead
 
 error: indexing may panic
-  --> $DIR/indexing_slicing_index.rs:60:5
+  --> $DIR/indexing_slicing_index.rs:58:5
    |
 LL |     v[10];
    |     ^^^^^
@@ -94,7 +85,7 @@ LL |     v[10];
    = help: consider using `.get(n)` or `.get_mut(n)` instead
 
 error: indexing may panic
-  --> $DIR/indexing_slicing_index.rs:62:5
+  --> $DIR/indexing_slicing_index.rs:60:5
    |
 LL |     v[1 << 3];
    |     ^^^^^^^^^
@@ -102,13 +93,13 @@ LL |     v[1 << 3];
    = help: consider using `.get(n)` or `.get_mut(n)` instead
 
 error: index is out of bounds
-  --> $DIR/indexing_slicing_index.rs:70:5
+  --> $DIR/indexing_slicing_index.rs:68:5
    |
 LL |     x[N];
    |     ^^^^
 
 error: indexing may panic
-  --> $DIR/indexing_slicing_index.rs:73:5
+  --> $DIR/indexing_slicing_index.rs:71:5
    |
 LL |     v[N];
    |     ^^^^
@@ -116,7 +107,7 @@ LL |     v[N];
    = help: consider using `.get(n)` or `.get_mut(n)` instead
 
 error: indexing may panic
-  --> $DIR/indexing_slicing_index.rs:75:5
+  --> $DIR/indexing_slicing_index.rs:73:5
    |
 LL |     v[M];
    |     ^^^^
@@ -124,17 +115,11 @@ LL |     v[M];
    = help: consider using `.get(n)` or `.get_mut(n)` instead
 
 error: index is out of bounds
-  --> $DIR/indexing_slicing_index.rs:79:13
+  --> $DIR/indexing_slicing_index.rs:77:13
    |
 LL |     let _ = x[4];
    |             ^^^^
 
-error[E0080]: evaluation of constant value failed
-  --> $DIR/indexing_slicing_index.rs:16:24
-   |
-LL | const REF_ERR: &i32 = &ARR[idx4()]; // Ok, let rustc handle const contexts.
-   |                        ^^^^^^^^^^^ index out of bounds: the length is 2 but the index is 4
-
-error: aborting due to 17 previous errors
+error: aborting due to 15 previous errors
 
 For more information about this error, try `rustc --explain E0080`.