diff options
| author | Lukas Markeffsky <@> | 2025-02-21 18:00:56 +0100 |
|---|---|---|
| committer | Lukas Markeffsky <@> | 2025-02-21 20:32:34 +0100 |
| commit | a825e37fe4dba0e8b33ed05611ba130d396a5509 (patch) | |
| tree | 51b9c231fb6671073d0ca3f06072792f2ada4536 /tests | |
| parent | 71e06b9c59d6af50fdc55aed75620493d29baf98 (diff) | |
| download | rust-a825e37fe4dba0e8b33ed05611ba130d396a5509.tar.gz rust-a825e37fe4dba0e8b33ed05611ba130d396a5509.zip | |
layout_of: put back not-so-unreachable case
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/ui/layout/gce-rigid-const-in-array-len.rs | 27 | ||||
| -rw-r--r-- | tests/ui/layout/gce-rigid-const-in-array-len.stderr | 17 | ||||
| -rw-r--r-- | tests/ui/layout/unconstrained-param-ice-137308.rs | 18 | ||||
| -rw-r--r-- | tests/ui/layout/unconstrained-param-ice-137308.stderr | 15 |
4 files changed, 77 insertions, 0 deletions
diff --git a/tests/ui/layout/gce-rigid-const-in-array-len.rs b/tests/ui/layout/gce-rigid-const-in-array-len.rs new file mode 100644 index 00000000000..8e57907a2c5 --- /dev/null +++ b/tests/ui/layout/gce-rigid-const-in-array-len.rs @@ -0,0 +1,27 @@ +//! With `feature(generic_const_exprs)`, anon consts (e.g. length in array types) will +//! inherit their parent's predicates. When combined with `feature(trivial_bounds)`, it +//! is possible to have an unevaluated constant that is rigid, but not generic. +//! +//! This is what happens below: `u8: A` does not hold in the global environment, but +//! with trivial bounds + GCE it it possible that `<u8 as A>::B` can appear in an array +//! length without causing a compile error. This constant is *rigid* (i.e. it cannot be +//! normalized further), but it is *not generic* (i.e. it does not depend on any generic +//! parameters). +//! +//! This test ensures that we do not ICE in layout computation when encountering such a +//! constant. + +#![feature(rustc_attrs)] +#![feature(generic_const_exprs)] //~ WARNING: the feature `generic_const_exprs` is incomplete +#![feature(trivial_bounds)] + +#![crate_type = "lib"] + +trait A { + const B: usize; +} + +#[rustc_layout(debug)] +struct S([u8; <u8 as A>::B]) //~ ERROR: the type `[u8; <u8 as A>::B]` has an unknown layout +where + u8: A; diff --git a/tests/ui/layout/gce-rigid-const-in-array-len.stderr b/tests/ui/layout/gce-rigid-const-in-array-len.stderr new file mode 100644 index 00000000000..6149debdfe8 --- /dev/null +++ b/tests/ui/layout/gce-rigid-const-in-array-len.stderr @@ -0,0 +1,17 @@ +warning: the feature `generic_const_exprs` is incomplete and may not be safe to use and/or cause compiler crashes + --> $DIR/gce-rigid-const-in-array-len.rs:15:12 + | +LL | #![feature(generic_const_exprs)] + | ^^^^^^^^^^^^^^^^^^^ + | + = note: see issue #76560 <https://github.com/rust-lang/rust/issues/76560> for more information + = note: `#[warn(incomplete_features)]` on by default + +error: the type `[u8; <u8 as A>::B]` has an unknown layout + --> $DIR/gce-rigid-const-in-array-len.rs:25:1 + | +LL | struct S([u8; <u8 as A>::B]) + | ^^^^^^^^ + +error: aborting due to 1 previous error; 1 warning emitted + diff --git a/tests/ui/layout/unconstrained-param-ice-137308.rs b/tests/ui/layout/unconstrained-param-ice-137308.rs new file mode 100644 index 00000000000..d460fc64f1f --- /dev/null +++ b/tests/ui/layout/unconstrained-param-ice-137308.rs @@ -0,0 +1,18 @@ +//! Regression test for <https://github.com/rust-lang/rust/issues/137308>. +//! +//! This used to ICE in layout computation, because `<u8 as A>::B` fails to normalize +//! due to the unconstrained param on the impl. + +#![feature(rustc_attrs)] +#![crate_type = "lib"] + +trait A { + const B: usize; +} + +impl<C: ?Sized> A for u8 { //~ ERROR: the type parameter `C` is not constrained + const B: usize = 42; +} + +#[rustc_layout(debug)] +struct S([u8; <u8 as A>::B]); //~ ERROR: the type `[u8; <u8 as A>::B]` has an unknown layout diff --git a/tests/ui/layout/unconstrained-param-ice-137308.stderr b/tests/ui/layout/unconstrained-param-ice-137308.stderr new file mode 100644 index 00000000000..03ee941d37e --- /dev/null +++ b/tests/ui/layout/unconstrained-param-ice-137308.stderr @@ -0,0 +1,15 @@ +error[E0207]: the type parameter `C` is not constrained by the impl trait, self type, or predicates + --> $DIR/unconstrained-param-ice-137308.rs:13:6 + | +LL | impl<C: ?Sized> A for u8 { + | ^ unconstrained type parameter + +error: the type `[u8; <u8 as A>::B]` has an unknown layout + --> $DIR/unconstrained-param-ice-137308.rs:18:1 + | +LL | struct S([u8; <u8 as A>::B]); + | ^^^^^^^^ + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0207`. |
