about summary refs log tree commit diff
path: root/tests/ui/layout
diff options
context:
space:
mode:
authorMatthias Krüger <matthias.krueger@famsik.de>2025-03-01 11:33:57 +0100
committerGitHub <noreply@github.com>2025-03-01 11:33:57 +0100
commitf012947bf0efb60434eaa85b439ca49999ed74f7 (patch)
tree4ac52b8fc00f2f63b4a6dfb515de1ff99428e43a /tests/ui/layout
parent002da76821d32c8807dc47da16660925d8cc9b62 (diff)
parent7d4d09eeeb7de6afae90b6cdbabed257eb77727f (diff)
downloadrust-f012947bf0efb60434eaa85b439ca49999ed74f7.tar.gz
rust-f012947bf0efb60434eaa85b439ca49999ed74f7.zip
Rollup merge of #136503 - estebank:const-panic, r=RalfJung
Tweak output of const panic diagnostic

### Shorten span of panic failures in const context

Previously, we included a redundant prefix on the panic message and a postfix of the location of the panic. The prefix didn't carry any additional information beyond "something failed", and the location of the panic is redundant with the diagnostic's span, which gets printed out even if its code is not shown.

```
error[E0080]: evaluation of constant value failed
--> $DIR/assert-type-intrinsics.rs:11:9
   |
LL |         MaybeUninit::<!>::uninit().assume_init();
   |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ panic: aborted execution: attempted to instantiate uninhabited type `!`
```

```
error[E0080]: evaluation of `Fail::<i32>::C` failed
--> $DIR/collect-in-dead-closure.rs:9:19
   |
LL |     const C: () = panic!();
   |                   ^^^^^^^^ explicit panic
   |
   = note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
```
```
error[E0080]: evaluation of constant value failed
--> $DIR/uninhabited.rs:87:9
   |
LL |         assert!(false);
   |         ^^^^^^^^^^^^^^ assertion failed: false
   |
   = note: this error originates in the macro `assert` (in Nightly builds, run with -Z macro-backtrace for more info)
```

### Remove duplicated span from const eval frame list

When the primary span for a const error is the same as the first frame in the const error report, skip it.

```
error[E0080]: evaluation of constant value failed
  --> $DIR/issue-88434-removal-index-should-be-less.rs:3:24
   |
LL | const _CONST: &[u8] = &f(&[], |_| {});
   |                        ^^^^^^^^^^^^^^ explicit panic
   |
note: inside `f::<{closure@$DIR/issue-88434-removal-index-should-be-less.rs:3:31: 3:34}>`
  --> $DIR/issue-88434-removal-index-should-be-less.rs:10:5
   |
LL |     panic!()
   |     ^^^^^^^^ the failure occurred here
   = note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
```
instead of
```
error[E0080]: evaluation of constant value failed
--> $DIR/issue-88434-removal-index-should-be-less.rs:10:5
   |
LL |     panic!()
   |     ^^^^^^^^ explicit panic
   |
note: inside `f::<{closure@$DIR/issue-88434-removal-index-should-be-less.rs:3:31: 3:34}>`
--> $DIR/issue-88434-removal-index-should-be-less.rs:10:5
   |
LL |     panic!()
   |     ^^^^^^^^
note: inside `_CONST`
--> $DIR/issue-88434-removal-index-should-be-less.rs:3:24
   |
LL | const _CONST: &[u8] = &f(&[], |_| {});
   |                        ^^^^^^^^^^^^^^
   = note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)

note: erroneous constant encountered
--> $DIR/issue-88434-removal-index-should-be-less.rs:3:23
   |
LL | const _CONST: &[u8] = &f(&[], |_| {});
   |                       ^^^^^^^^^^^^^^^
```

r? ``@oli-obk``
Diffstat (limited to 'tests/ui/layout')
-rw-r--r--tests/ui/layout/invalid-unsized-in-always-sized-tail.rs2
-rw-r--r--tests/ui/layout/invalid-unsized-in-always-sized-tail.stderr10
-rw-r--r--tests/ui/layout/unknown-when-no-type-parameter.stderr10
3 files changed, 7 insertions, 15 deletions
diff --git a/tests/ui/layout/invalid-unsized-in-always-sized-tail.rs b/tests/ui/layout/invalid-unsized-in-always-sized-tail.rs
index 5df97338710..c6d5f2bfa0e 100644
--- a/tests/ui/layout/invalid-unsized-in-always-sized-tail.rs
+++ b/tests/ui/layout/invalid-unsized-in-always-sized-tail.rs
@@ -12,6 +12,6 @@ struct P2 {
     //~^ ERROR: the size for values of type `[bool]` cannot be known at compilation time
 }
 
-static CHECK: () = assert!(align_of::<P2>() == 1);
+static CHECK: () = assert!(align_of::<P2>() == 1); //~ ERROR could not evaluate static initializer
 
 fn main() {}
diff --git a/tests/ui/layout/invalid-unsized-in-always-sized-tail.stderr b/tests/ui/layout/invalid-unsized-in-always-sized-tail.stderr
index f54e97e2a5c..3a4735e4832 100644
--- a/tests/ui/layout/invalid-unsized-in-always-sized-tail.stderr
+++ b/tests/ui/layout/invalid-unsized-in-always-sized-tail.stderr
@@ -19,17 +19,13 @@ LL | struct MySlice<T>(T);
    |                this could be changed to `T: ?Sized`...
 
 error[E0080]: could not evaluate static initializer
-  --> $SRC_DIR/core/src/mem/mod.rs:LL:COL
+  --> $DIR/invalid-unsized-in-always-sized-tail.rs:15:28
    |
-   = note: the type `MySlice<[bool]>` has an unknown layout
+LL | static CHECK: () = assert!(align_of::<P2>() == 1);
+   |                            ^^^^^^^^^^^^^^^^ the type `MySlice<[bool]>` has an unknown layout
    |
 note: inside `align_of::<P2>`
   --> $SRC_DIR/core/src/mem/mod.rs:LL:COL
-note: inside `CHECK`
-  --> $DIR/invalid-unsized-in-always-sized-tail.rs:15:28
-   |
-LL | static CHECK: () = assert!(align_of::<P2>() == 1);
-   |                            ^^^^^^^^^^^^^^^^
 
 error: aborting due to 2 previous errors
 
diff --git a/tests/ui/layout/unknown-when-no-type-parameter.stderr b/tests/ui/layout/unknown-when-no-type-parameter.stderr
index d0456e2b329..9e414d224bb 100644
--- a/tests/ui/layout/unknown-when-no-type-parameter.stderr
+++ b/tests/ui/layout/unknown-when-no-type-parameter.stderr
@@ -1,15 +1,11 @@
 error[E0080]: evaluation of constant value failed
-  --> $SRC_DIR/core/src/mem/mod.rs:LL:COL
+  --> $DIR/unknown-when-no-type-parameter.rs:11:10
    |
-   = note: the type `<() as Project>::Assoc` has an unknown layout
+LL |     [(); size_of::<<() as Project>::Assoc>()];
+   |          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the type `<() as Project>::Assoc` has an unknown layout
    |
 note: inside `std::mem::size_of::<<() as Project>::Assoc>`
   --> $SRC_DIR/core/src/mem/mod.rs:LL:COL
-note: inside `foo::{constant#0}`
-  --> $DIR/unknown-when-no-type-parameter.rs:11:10
-   |
-LL |     [(); size_of::<<() as Project>::Assoc>()];
-   |          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 
 error: aborting due to 1 previous error