about summary refs log tree commit diff
path: root/tests/ui/coherence
diff options
context:
space:
mode:
authorEsteban Küber <esteban@kuber.com.ar>2025-02-03 18:43:55 +0000
committerEsteban Küber <esteban@kuber.com.ar>2025-02-28 16:28:41 +0000
commit7d4d09eeeb7de6afae90b6cdbabed257eb77727f (patch)
tree528899f3471e64e9cff25c88cc7128852b7cf1f3 /tests/ui/coherence
parentf45d4acf1bb635aa010f19f8a749eed8293203b3 (diff)
downloadrust-7d4d09eeeb7de6afae90b6cdbabed257eb77727f.tar.gz
rust-7d4d09eeeb7de6afae90b6cdbabed257eb77727f.zip
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();
   |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ evaluation panicked: 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!();
   |                   ^^^^^^^^ evaluation panicked: 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:41:9
   |
LL |         assert!(false);
   |         ^^^^^^^^^^^^^^ evaluation panicked: assertion failed: false
   |
   = note: this error originates in the macro `assert` (in Nightly builds, run with -Z macro-backtrace for more info)
```

---

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(&[], |_| {});
   |                        ^^^^^^^^^^^^^^ evaluation panicked: 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)
```

---

Revert order of constant evaluation errors

Point at the code the user wrote first and std functions last.

```
error[E0080]: evaluation of constant value failed
  --> $DIR/const-errs-dont-conflict-103369.rs:5:25
   |
LL | impl ConstGenericTrait<{my_fn(1)}> for () {}
   |                         ^^^^^^^^ evaluation panicked: Some error occurred
   |
note: called from `my_fn`
  --> $DIR/const-errs-dont-conflict-103369.rs:10:5
   |
LL |     panic!("Some error occurred");
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   = 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/const-errs-dont-conflict-103369.rs:10:5
   |
LL |     panic!("Some error occurred");
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Some error occurred
   |
note: called from `<() as ConstGenericTrait<{my_fn(1)}>>::{constant#0}`
  --> $DIR/const-errs-dont-conflict-103369.rs:5:25
   |
LL | impl ConstGenericTrait<{my_fn(1)}> for () {}
   |                         ^^^^^^^^
   = 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)
```
Diffstat (limited to 'tests/ui/coherence')
-rw-r--r--tests/ui/coherence/const-errs-dont-conflict-103369.rs7
-rw-r--r--tests/ui/coherence/const-errs-dont-conflict-103369.stderr26
2 files changed, 11 insertions, 22 deletions
diff --git a/tests/ui/coherence/const-errs-dont-conflict-103369.rs b/tests/ui/coherence/const-errs-dont-conflict-103369.rs
index c7d46a8000d..14937e0f02e 100644
--- a/tests/ui/coherence/const-errs-dont-conflict-103369.rs
+++ b/tests/ui/coherence/const-errs-dont-conflict-103369.rs
@@ -2,13 +2,12 @@
 
 pub trait ConstGenericTrait<const N: u32> {}
 
-impl ConstGenericTrait<{my_fn(1)}> for () {}
+impl ConstGenericTrait<{my_fn(1)}> for () {} //~ ERROR E0080
 
-impl ConstGenericTrait<{my_fn(2)}> for () {}
+impl ConstGenericTrait<{my_fn(2)}> for () {} //~ ERROR E0080
 
 const fn my_fn(v: u32) -> u32 {
-    panic!("Some error occurred"); //~ ERROR E0080
-    //~| ERROR E0080
+    panic!("Some error occurred");
 }
 
 fn main() {}
diff --git a/tests/ui/coherence/const-errs-dont-conflict-103369.stderr b/tests/ui/coherence/const-errs-dont-conflict-103369.stderr
index 22066d6b6bd..4acaaf22ae8 100644
--- a/tests/ui/coherence/const-errs-dont-conflict-103369.stderr
+++ b/tests/ui/coherence/const-errs-dont-conflict-103369.stderr
@@ -1,37 +1,27 @@
 error[E0080]: evaluation of constant value failed
-  --> $DIR/const-errs-dont-conflict-103369.rs:10:5
+  --> $DIR/const-errs-dont-conflict-103369.rs:5:25
    |
-LL |     panic!("Some error occurred");
-   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the evaluated program panicked at 'Some error occurred', $DIR/const-errs-dont-conflict-103369.rs:10:5
+LL | impl ConstGenericTrait<{my_fn(1)}> for () {}
+   |                         ^^^^^^^^ evaluation panicked: Some error occurred
    |
 note: inside `my_fn`
   --> $DIR/const-errs-dont-conflict-103369.rs:10:5
    |
 LL |     panic!("Some error occurred");
-   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-note: inside `<() as ConstGenericTrait<{my_fn(1)}>>::{constant#0}`
-  --> $DIR/const-errs-dont-conflict-103369.rs:5:25
-   |
-LL | impl ConstGenericTrait<{my_fn(1)}> for () {}
-   |                         ^^^^^^^^
+   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 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)
 
 error[E0080]: evaluation of constant value failed
-  --> $DIR/const-errs-dont-conflict-103369.rs:10:5
+  --> $DIR/const-errs-dont-conflict-103369.rs:7:25
    |
-LL |     panic!("Some error occurred");
-   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the evaluated program panicked at 'Some error occurred', $DIR/const-errs-dont-conflict-103369.rs:10:5
+LL | impl ConstGenericTrait<{my_fn(2)}> for () {}
+   |                         ^^^^^^^^ evaluation panicked: Some error occurred
    |
 note: inside `my_fn`
   --> $DIR/const-errs-dont-conflict-103369.rs:10:5
    |
 LL |     panic!("Some error occurred");
-   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-note: inside `<() as ConstGenericTrait<{my_fn(2)}>>::{constant#0}`
-  --> $DIR/const-errs-dont-conflict-103369.rs:7:25
-   |
-LL | impl ConstGenericTrait<{my_fn(2)}> for () {}
-   |                         ^^^^^^^^
+   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 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)
 
 error: aborting due to 2 previous errors