rust/tests/ui/structs
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 Move default-field-values tests into a subdirectory 2024-12-14 18:05:19 +00:00
default-field-values Shorten span of panic failures in const context 2025-02-28 16:28:41 +00:00
default-field-values-non_exhaustive.rs Restrict #[non_exaustive] on structs with default field values 2024-12-20 17:18:54 +00:00
default-field-values-non_exhaustive.stderr Restrict #[non_exaustive] on structs with default field values 2024-12-20 17:18:54 +00:00
field-implied-unsizing-wfcheck.rs Test more cases of WF-checking for fields 2024-08-05 17:56:50 -07:00
field-implied-unsizing-wfcheck.stderr Test more cases of WF-checking for fields 2024-08-05 17:56:50 -07:00
ice-struct-tail-normalization-113272.rs Add TooGeneric variant to LayoutError and emit Unknown one 2025-01-27 00:37:34 +01:00
ice-struct-tail-normalization-113272.stderr fix ICE with references to infinite structs in consts 2025-01-14 01:22:04 +01:00
incomplete-fn-in-struct-definition.rs
incomplete-fn-in-struct-definition.stderr
issue-80853.rs
issue-80853.stderr
large-records.rs tests: remove //@ pretty-expanded usages 2024-11-26 02:50:48 +08:00
manual-default-impl-could-be-derived.rs Implement default_overrides_default_fields lint 2024-12-25 23:25:45 +00:00
manual-default-impl-could-be-derived.stderr Provide structured suggestion for impl Default of type where all fields have defaults 2024-12-31 18:06:01 +00:00
method-chain-expression-failure.rs
method-chain-expression-failure.stderr
multi-line-fru-suggestion.rs
multi-line-fru-suggestion.stderr
rhs-type.rs tests: use needs-subprocess instead of ignore-{wasm32,emscripten,sgx} 2025-01-23 20:51:29 +08:00
struct-base-wrong-type.rs
struct-base-wrong-type.stderr
struct-duplicate-comma.fixed
struct-duplicate-comma.rs
struct-duplicate-comma.stderr Make parse error suggestions verbose and fix spans 2024-07-12 03:02:57 +00:00
struct-field-cfg.rs
struct-field-cfg.stderr Show diff suggestion format on verbose replacement 2025-02-10 20:21:39 +00:00
struct-field-init-syntax.rs
struct-field-init-syntax.stderr Make parse error suggestions verbose and fix spans 2024-07-12 03:02:57 +00:00
struct-field-privacy.rs
struct-field-privacy.stderr
struct-fields-decl-dupe.rs
struct-fields-decl-dupe.stderr
struct-fields-dupe.rs
struct-fields-dupe.stderr
struct-fields-hints-no-dupe.rs
struct-fields-hints-no-dupe.stderr Trim suggestion parts to the subset that is purely additive 2025-02-14 00:44:10 -08:00
struct-fields-hints.rs
struct-fields-hints.stderr Show diff suggestion format on verbose replacement 2025-02-10 20:21:39 +00:00
struct-fields-missing.rs
struct-fields-missing.stderr
struct-fields-shorthand-unresolved.rs
struct-fields-shorthand-unresolved.stderr
struct-fields-shorthand.rs
struct-fields-shorthand.stderr
struct-fields-too-many.rs
struct-fields-too-many.stderr
struct-fields-typo.rs
struct-fields-typo.stderr Show diff suggestion format on verbose replacement 2025-02-10 20:21:39 +00:00
struct-fn-in-definition.rs
struct-fn-in-definition.stderr
struct-missing-comma.fixed
struct-missing-comma.rs
struct-missing-comma.stderr
struct-pat-derived-error.rs
struct-pat-derived-error.stderr Trim suggestion parts to the subset that is purely additive 2025-02-14 00:44:10 -08:00
struct-path-alias-bounds.rs
struct-path-alias-bounds.stderr
struct-path-associated-type.rs
struct-path-associated-type.stderr Revert suggestion verbosity change 2024-07-22 22:51:53 +00:00
struct-path-self-type-mismatch.rs
struct-path-self-type-mismatch.stderr Show diff suggestion format on verbose replacement 2025-02-10 20:21:39 +00:00
struct-path-self.rs
struct-path-self.stderr
struct-record-suggestion.fixed
struct-record-suggestion.rs
struct-record-suggestion.stderr
struct-tuple-field-names.rs
struct-tuple-field-names.stderr Trim suggestion parts to the subset that is purely additive 2025-02-14 00:44:10 -08:00
struct-variant-privacy-xc.rs
struct-variant-privacy-xc.stderr
struct-variant-privacy.rs
struct-variant-privacy.stderr
structure-constructor-type-mismatch.rs
structure-constructor-type-mismatch.stderr Revert suggestion verbosity change 2024-07-22 22:51:53 +00:00
suggest-private-fields.rs
suggest-private-fields.stderr Show diff suggestion format on verbose replacement 2025-02-10 20:21:39 +00:00
suggest-replacing-field-when-specifying-same-type.rs
suggest-replacing-field-when-specifying-same-type.stderr Trim suggestion parts to the subset that is purely additive 2025-02-14 00:44:10 -08:00
unresolved-struct-with-fru.rs
unresolved-struct-with-fru.stderr