rust/tests/ui/layout
Matthias Krüger f012947bf0
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``
2025-03-01 11:33:57 +01:00
..
aggregate-lang Remove #[cfg(test)] related stubs 2024-11-22 21:07:02 -05:00
base-layout-is-sized-ice-123078.rs Add TooGeneric variant to LayoutError and emit Unknown one 2025-01-27 00:37:34 +01:00
base-layout-is-sized-ice-123078.stderr Add TooGeneric variant to LayoutError and emit Unknown one 2025-01-27 00:37:34 +01:00
big-type-no-err.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
cannot-transmute-unnormalizable-type.rs Continue compilation after check_mod_type_wf errors 2024-02-14 11:00:30 +00:00
cannot-transmute-unnormalizable-type.stderr Continue compilation after check_mod_type_wf errors 2024-02-14 11:00:30 +00:00
debug.rs clean up layout error diagnostics 2025-02-18 13:22:45 +01:00
debug.stderr Update ui tests with LayoutData { uninhabited: ... } etc 2025-02-20 13:40:41 -06:00
enum-scalar-pair-int-ptr.rs Remove the -test suffix from normalize directives 2024-12-27 19:58:16 +11:00
enum-scalar-pair-int-ptr.stderr tests: Bless rustc_abi::Abi::Aggregate => ::Memory 2024-10-30 01:41:31 -07:00
enum.rs Remove the -test suffix from normalize directives 2024-12-27 19:58:16 +11:00
enum.stderr fix test failure due to differing u64 alignment on different targets 2024-02-28 18:48:14 -05:00
failed-to-get-layout-for-type-error-ice-92979.rs add test for ICE: failed to get layout for [type error] #92979 2024-03-25 20:35:51 +01:00
failed-to-get-layout-for-type-error-ice-92979.stderr add test for ICE: failed to get layout for [type error] #92979 2024-03-25 20:35:51 +01:00
gce-rigid-const-in-array-len.rs layout_of: put back not-so-unreachable case 2025-02-21 20:32:34 +01:00
gce-rigid-const-in-array-len.stderr layout_of: put back not-so-unreachable case 2025-02-21 20:32:34 +01:00
hexagon-enum.rs tests: use minicore more 2025-02-24 09:26:54 +00:00
hexagon-enum.stderr tests: use minicore more 2025-02-24 09:26:54 +00:00
homogeneous-aggr-transparent.rs
homogeneous-aggr-transparent.stderr
homogeneous-aggr-zero-sized-c-struct.rs
homogeneous-aggr-zero-sized-c-struct.stderr
homogeneous-aggr-zero-sized-repr-rust.rs
homogeneous-aggr-zero-sized-repr-rust.stderr
ice-non-last-unsized-field-issue-121473.rs Error out of layout calculation if a non-last struct field is unsized 2024-04-04 15:50:36 +05:30
ice-non-last-unsized-field-issue-121473.stderr Error out of layout calculation if a non-last struct field is unsized 2024-04-04 15:50:36 +05:30
ice-type-error-in-tail-124031.rs Remove the -test suffix from normalize directives 2024-12-27 19:58:16 +11:00
ice-type-error-in-tail-124031.stderr Stop being so bail-y in candidate assembly 2024-11-21 01:35:34 +00:00
invalid-unsized-const-eval.rs Add TooGeneric variant to LayoutError and emit Unknown one 2025-01-27 00:37:34 +01:00
invalid-unsized-const-eval.stderr Add TooGeneric variant to LayoutError and emit Unknown one 2025-01-27 00:37:34 +01:00
invalid-unsized-const-prop.rs get rid of an old hack 2024-09-17 00:09:21 +02:00
invalid-unsized-in-always-sized-tail.rs Shorten span of panic failures in const context 2025-02-28 16:28:41 +00:00
invalid-unsized-in-always-sized-tail.stderr Shorten span of panic failures in const context 2025-02-28 16:28:41 +00:00
issue-60431-unsized-tail-behind-projection.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
issue-84108.rs Allow type_of to return partially non-error types if the type was already tainted 2024-05-28 11:55:20 +00:00
issue-84108.stderr Allow type_of to return partially non-error types if the type was already tainted 2024-05-28 11:55:20 +00:00
issue-96158-scalarpair-payload-might-be-uninit.rs adjust UI tests 2025-01-10 02:22:57 +01:00
issue-96158-scalarpair-payload-might-be-uninit.stderr Update ui tests with LayoutData { uninhabited: ... } etc 2025-02-20 13:40:41 -06:00
issue-96185-overaligned-enum.rs adjust UI tests 2025-01-10 02:22:57 +01:00
issue-96185-overaligned-enum.stderr Update ui tests with LayoutData { uninhabited: ... } etc 2025-02-20 13:40:41 -06:00
issue-112048-unsizing-field-order.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
issue-112048-unsizing-niche.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
issue-113941.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
issue-unsized-tail-restatic-ice-122488.rs Add TooGeneric variant to LayoutError and emit Unknown one 2025-01-27 00:37:34 +01:00
issue-unsized-tail-restatic-ice-122488.stderr Add TooGeneric variant to LayoutError and emit Unknown one 2025-01-27 00:37:34 +01:00
layout-cycle.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
layout-cycle.stderr
malformed-unsized-type-in-union.rs Implement and use BikeshedGuaranteedNoDrop for union/unsafe field validity 2025-02-13 03:45:04 +00:00
malformed-unsized-type-in-union.stderr Implement and use BikeshedGuaranteedNoDrop for union/unsafe field validity 2025-02-13 03:45:04 +00:00
normalization-failure.rs document and test all LayoutError variants 2025-02-18 13:22:45 +01:00
normalization-failure.stderr document and test all LayoutError variants 2025-02-18 13:22:45 +01:00
post-mono-layout-cycle-2.rs Stabilize async closures 2024-12-13 00:04:56 +00:00
post-mono-layout-cycle-2.stderr Stabilize async closures 2024-12-13 00:04:56 +00:00
post-mono-layout-cycle.rs Emit warning when calling/declaring functions with unavailable vectors. 2024-11-01 22:24:35 +01:00
post-mono-layout-cycle.stderr Emit warning when calling/declaring functions with unavailable vectors. 2024-11-01 22:24:35 +01:00
randomize.rs test that coercions still work under randomization 2025-01-10 02:22:57 +01:00
reprc-power-alignment.rs [AIX] Lint on structs that have a different alignment in AIX's C ABI 2025-01-22 12:06:16 -05:00
reprc-power-alignment.stderr [AIX] Lint on structs that have a different alignment in AIX's C ABI 2025-01-22 12:06:16 -05:00
rust-call-abi-not-a-tuple-ice-81974.rs add test for Compiler panic using fn_traits #81974 2024-03-25 20:15:28 +01:00
rust-call-abi-not-a-tuple-ice-81974.stderr Mention type parameter in more cases and don't suggest ~const bound already there 2024-12-07 21:37:13 +00:00
size-of-val-raw-too-big.rs TL note: current means target 2024-09-20 10:02:14 -07:00
size-of-val-raw-too-big.stderr TL note: current means target 2024-09-20 10:02:14 -07:00
struct.rs Remove the -test suffix from normalize directives 2024-12-27 19:58:16 +11:00
struct.stderr tests: Bless rustc_abi::Abi::Aggregate => ::Memory 2024-10-30 01:41:31 -07:00
thaw-transmute-invalid-enum.rs use backticks instead of single quotes when reporting "use of unstable library feature" 2024-11-03 13:55:52 -08:00
thaw-transmute-invalid-enum.stderr use backticks instead of single quotes when reporting "use of unstable library feature" 2024-11-03 13:55:52 -08:00
thaw-validate-invalid-enum.rs compiler: Reject impossible reprs during enum layout 2024-10-20 02:12:58 -07:00
thaw-validate-invalid-enum.stderr compiler: Reject impossible reprs during enum layout 2024-10-20 02:12:58 -07:00
thin-meta-implies-thin-ptr.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
thumb-enum.rs tests: use minicore more 2025-02-24 09:26:54 +00:00
thumb-enum.stderr tests: use minicore more 2025-02-24 09:26:54 +00:00
too-big-with-padding.rs tests: use minicore more 2025-02-24 09:26:54 +00:00
too-big-with-padding.stderr tests: use minicore more 2025-02-24 09:26:54 +00:00
transmute-to-tail-with-err.rs
transmute-to-tail-with-err.stderr
trivial-bounds-sized.rs layout computation: eagerly error for unexpected unsized fields 2024-09-16 15:53:21 +02:00
uncomputable-due-to-trivial-bounds-ice-135138.rs Add TooGeneric variant to LayoutError and emit Unknown one 2025-01-27 00:37:34 +01:00
uncomputable-due-to-trivial-bounds-ice-135138.stderr Add TooGeneric variant to LayoutError and emit Unknown one 2025-01-27 00:37:34 +01:00
unconstrained-param-ice-137308.rs don't leave assoc const unnormalized due to unconstrained params 2025-02-21 20:32:37 +01:00
unconstrained-param-ice-137308.stderr don't leave assoc const unnormalized due to unconstrained params 2025-02-21 20:32:37 +01:00
unexpected-unsized-field-issue-135020.rs Add TooGeneric variant to LayoutError and emit Unknown one 2025-01-27 00:37:34 +01:00
unknown-when-no-type-parameter.rs Add TooGeneric variant to LayoutError and emit Unknown one 2025-01-27 00:37:34 +01:00
unknown-when-no-type-parameter.stderr Shorten span of panic failures in const context 2025-02-28 16:28:41 +00:00
unknown-when-ptr-metadata-is-DST.rs Add TooGeneric variant to LayoutError and emit Unknown one 2025-01-27 00:37:34 +01:00
unknown-when-ptr-metadata-is-DST.stderr Add TooGeneric variant to LayoutError and emit Unknown one 2025-01-27 00:37:34 +01:00
unsafe-cell-hides-niche.rs Stabilize generic NonZero. 2024-04-22 18:48:47 +02:00
unsatisfiable-sized-ungated.rs layout computation: eagerly error for unexpected unsized fields 2024-09-16 15:53:21 +02:00
valid_range_oob.rs Remove the -test suffix from normalize directives 2024-12-27 19:58:16 +11:00
valid_range_oob.stderr Properly note when query stack is being cut off 2025-01-16 19:12:22 +00:00
zero-sized-array-enum-niche.rs adjust UI tests 2025-01-10 02:22:57 +01:00
zero-sized-array-enum-niche.stderr Update ui tests with LayoutData { uninhabited: ... } etc 2025-02-20 13:40:41 -06:00
zero-sized-array-union.rs
zero-sized-array-union.stderr