rust/tests/ui/generics
Esteban Küber 7d4d09eeeb 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)
```
2025-02-28 16:28:41 +00:00
..
auxiliary Encode lifetime param spans too 2023-04-22 01:13:54 +00:00
autobind.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
bad-mid-path-type-params.rs diagnostics: remove inconsistent English article "this" from E0107 2023-02-23 10:27:06 -07:00
bad-mid-path-type-params.stderr Revert suggestion verbosity change 2024-07-22 22:51:53 +00:00
foreign-generic-mismatch.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
foreign-generic-mismatch.stderr Revert suggestion verbosity change 2024-07-22 22:51:53 +00:00
generic-alias-unique.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
generic-arg-mismatch-recover.rs diagnostics: remove inconsistent English article "this" from E0107 2023-02-23 10:27:06 -07:00
generic-arg-mismatch-recover.stderr Revert suggestion verbosity change 2024-07-22 22:51:53 +00:00
generic-default-type-params-cross-crate.rs tests: remove //@ pretty-expanded usages 2024-11-26 02:50:48 +08:00
generic-default-type-params.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
generic-derived-type.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
generic-exterior-unique.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
generic-extern-lifetime.rs
generic-extern-lifetime.stderr
generic-extern-mangle.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
generic-extern.rs Continue to borrowck even if there were previous errors 2024-02-08 08:10:43 +00:00
generic-extern.stderr Continue to borrowck even if there were previous errors 2024-02-08 08:10:43 +00:00
generic-fn-infer.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
generic-fn-twice.rs tests: remove //@ pretty-expanded usages 2024-11-26 02:50:48 +08:00
generic-fn-unique.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
generic-fn.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
generic-function-item-where-type.rs Automatically taint when reporting errors from ItemCtxt 2024-07-09 07:44:17 +00:00
generic-function-item-where-type.stderr Automatically taint when reporting errors from ItemCtxt 2024-07-09 07:44:17 +00:00
generic-higher-ranked-lifetime-issue-122714.rs Fix incorrect suggestion for undeclared hrtb lifetimes in where clauses. 2024-05-20 20:28:57 +08:00
generic-higher-ranked-lifetime-issue-122714.stderr Fix incorrect suggestion for undeclared hrtb lifetimes in where clauses. 2024-05-20 20:28:57 +08:00
generic-impl-less-params-with-defaults.rs diagnostics: remove inconsistent English article "this" from E0107 2023-02-23 10:27:06 -07:00
generic-impl-less-params-with-defaults.stderr Show number in error message even for one error 2023-11-24 19:15:52 +01:00
generic-impl-more-params-with-defaults.rs diagnostics: remove inconsistent English article "this" from E0107 2023-02-23 10:27:06 -07:00
generic-impl-more-params-with-defaults.stderr Revert suggestion verbosity change 2024-07-22 22:51:53 +00:00
generic-ivec-leak.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
generic-lifetime-trait-impl.rs
generic-lifetime-trait-impl.stderr Show number in error message even for one error 2023-11-24 19:15:52 +01:00
generic-newtype-struct.rs tests: remove //@ pretty-expanded usages 2024-11-26 02:50:48 +08:00
generic-no-mangle.fixed elided_named_lifetimes: bless & add tests 2024-08-31 15:35:42 +03:00
generic-no-mangle.rs elided_named_lifetimes: bless & add tests 2024-08-31 15:35:42 +03:00
generic-no-mangle.stderr
generic-non-trailing-defaults.rs
generic-non-trailing-defaults.stderr
generic-object.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
generic-param-attrs.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
generic-recursive-tag.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
generic-static-methods.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
generic-tag-corruption.rs tests: remove //@ pretty-expanded usages 2024-11-26 02:50:48 +08:00
generic-tag-local.rs tests: remove //@ pretty-expanded usages 2024-11-26 02:50:48 +08:00
generic-tag-match.rs Remove some unnecessary parens in assert! conditions 2025-02-06 22:28:44 +00:00
generic-tag-values.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
generic-tag.rs tests: remove //@ pretty-expanded usages 2024-11-26 02:50:48 +08:00
generic-temporary.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
generic-tup.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
generic-type-less-params-with-defaults.rs Test generic arg suggestion inside nested item 2024-03-17 23:40:12 +00:00
generic-type-less-params-with-defaults.stderr Test generic arg suggestion inside nested item 2024-03-17 23:40:12 +00:00
generic-type-more-params-with-defaults.rs diagnostics: remove inconsistent English article "this" from E0107 2023-02-23 10:27:06 -07:00
generic-type-more-params-with-defaults.stderr Revert suggestion verbosity change 2024-07-22 22:51:53 +00:00
generic-type-params-forward-mention.rs
generic-type-params-forward-mention.stderr Show number in error message even for one error 2023-11-24 19:15:52 +01:00
generic-type-params-name-repr.rs Modify primary span label for E0308 2023-01-30 20:12:19 +00:00
generic-type-params-name-repr.stderr Modify primary span label for E0308 2023-01-30 20:12:19 +00:00
generic-type-synonym.rs tests: remove //@ pretty-expanded usages 2024-11-26 02:50:48 +08:00
generic-type.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
generic-unique.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
generics-on-self-mod-segment.rs Store resolution for self and crate root module segments 2024-11-20 18:57:02 +00:00
generics-on-self-mod-segment.stderr Store resolution for self and crate root module segments 2024-11-20 18:57:02 +00:00
impl-block-params-declared-in-wrong-spot-issue-113073.rs Update Tests 2024-06-05 20:08:00 -04:00
impl-block-params-declared-in-wrong-spot-issue-113073.stderr More accurate span for type parameter suggestion 2024-07-18 00:10:48 +00:00
issue-333.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
issue-1112.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
issue-2936.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
issue-32498.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
issue-59508-1.rs
issue-59508-1.stderr Show number in error message even for one error 2023-11-24 19:15:52 +01:00
issue-59508.fixed [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
issue-59508.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
issue-59508.stderr Show number in error message even for one error 2023-11-24 19:15:52 +01:00
issue-61631-default-type-param-can-reference-self-in-trait.rs
issue-61631-default-type-param-can-reference-self-in-trait.stderr On E0277 be clearer about implicit Sized bounds on type params and assoc types 2024-02-01 03:30:26 +00:00
issue-61631-default-type-param-cannot-reference-self.rs
issue-61631-default-type-param-cannot-reference-self.stderr
issue-65285-incorrect-explicit-lifetime-name-needed.rs Introduce ReError 2023-02-09 10:26:49 +00:00
issue-65285-incorrect-explicit-lifetime-name-needed.stderr Use structured suggestion when telling user about for<'a> 2023-06-30 00:34:14 +00:00
issue-79605.rs add UI test for #79605 2023-04-15 17:17:46 +05:30
issue-79605.stderr Bless and add tests 2025-01-23 06:01:36 +00:00
issue-80512-param-reordering-with-defaults.rs
issue-80512-param-reordering-with-defaults.stderr Show number in error message even for one error 2023-11-24 19:15:52 +01:00
issue-83556.rs diagnostics: simpler 83556 handling by bailing out 2023-09-22 22:41:01 -07:00
issue-83556.stderr Show number in error message even for one error 2023-11-24 19:15:52 +01:00
issue-94432-garbage-ice.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
issue-94923.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
issue-95208-ignore-qself.fixed [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
issue-95208-ignore-qself.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
issue-95208-ignore-qself.stderr Show diff suggestion format on verbose replacement 2025-02-10 20:21:39 +00:00
issue-95208.fixed [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
issue-95208.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
issue-95208.stderr Show diff suggestion format on verbose replacement 2025-02-10 20:21:39 +00:00
issue-98432.rs Generalize E0401 2023-09-10 23:06:14 +02:00
issue-98432.stderr Show number in error message even for one error 2023-11-24 19:15:52 +01:00
issue-106694.rs
issue-106694.stderr
lifetime-before-type-params.rs
lifetime-before-type-params.stderr
mid-path-type-params.rs tests: remove //@ pretty-expanded usages 2024-11-26 02:50:48 +08:00
overlapping-errors-span-issue-123861.rs Use a more precise span in placeholder_type_error_diag 2024-12-13 13:07:07 +01:00
overlapping-errors-span-issue-123861.stderr Show diff suggestion format on verbose replacement 2025-02-10 20:21:39 +00:00
param-in-ct-in-ty-param-default.rs
param-in-ct-in-ty-param-default.stderr generic_const_exprs: suggest to add the feature, not use it 2023-11-30 20:59:51 +01:00
post_monomorphization_error_backtrace.rs Shorten span of panic failures in const context 2025-02-28 16:28:41 +00:00
post_monomorphization_error_backtrace.stderr Shorten span of panic failures in const context 2025-02-28 16:28:41 +00:00
single-colon-path-not-const-generics.rs Rip it out 2023-05-01 16:15:13 +08:00
single-colon-path-not-const-generics.stderr Try to recover from path sep error in parser 2025-02-15 07:44:20 +08:00
slightly-nice-generic-literal-messages.rs Move some UI tests into subdirectories 2023-04-02 19:42:30 -04:00
slightly-nice-generic-literal-messages.stderr Show number in error message even for one error 2023-11-24 19:15:52 +01:00
type-params-in-for-each.rs tests: remove //@ pretty-expanded usages 2024-11-26 02:50:48 +08:00
unclosed-generics-in-impl-def.rs Tweak unclosed generics errors 2023-12-01 20:01:39 +00:00
unclosed-generics-in-impl-def.stderr Tweak unclosed generics errors 2023-12-01 20:01:39 +00:00
wrong-number-of-args.rs Change suggestion message wording 2024-07-22 22:04:49 +00:00
wrong-number-of-args.stderr Revert suggestion verbosity change 2024-07-22 22:51:53 +00:00