about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMatthias Krüger <matthias.krueger@famsik.de>2024-04-06 23:34:46 +0200
committerMatthias Krüger <matthias.krueger@famsik.de>2024-04-06 23:34:46 +0200
commit7d9e1067fdbd200729440044ae91037e644a9f55 (patch)
tree462ba9662d3a3fc8c79aad5e13d8294863dd335a
parent5dc7fe473be6ece4d91de87def58accd9bf168fb (diff)
downloadrust-7d9e1067fdbd200729440044ae91037e644a9f55.tar.gz
rust-7d9e1067fdbd200729440044ae91037e644a9f55.zip
add test for ICE: Unexpected unsized type tail: &ReStatic [u8] #122488
Fixes https://github.com/rust-lang/rust/issues/122488
-rw-r--r--tests/ui/layout/issue-unsized-tail-restatic-ice-122488.rs10
-rw-r--r--tests/ui/layout/issue-unsized-tail-restatic-ice-122488.stderr27
2 files changed, 37 insertions, 0 deletions
diff --git a/tests/ui/layout/issue-unsized-tail-restatic-ice-122488.rs b/tests/ui/layout/issue-unsized-tail-restatic-ice-122488.rs
new file mode 100644
index 00000000000..96c993035ef
--- /dev/null
+++ b/tests/ui/layout/issue-unsized-tail-restatic-ice-122488.rs
@@ -0,0 +1,10 @@
+// ICE Unexpected unsized type tail: &ReStatic [u8]
+// issue: rust-lang/rust#122488
+use std::ops::Deref;
+
+struct ArenaSet<U: Deref, V: ?Sized = <U as Deref>::Target>(V, U);
+//~^ ERROR the size for values of type `V` cannot be known at compilation time
+
+const DATA: *const ArenaSet<Vec<u8>> = std::ptr::null_mut();
+
+pub fn main() {}
diff --git a/tests/ui/layout/issue-unsized-tail-restatic-ice-122488.stderr b/tests/ui/layout/issue-unsized-tail-restatic-ice-122488.stderr
new file mode 100644
index 00000000000..f39cb29868a
--- /dev/null
+++ b/tests/ui/layout/issue-unsized-tail-restatic-ice-122488.stderr
@@ -0,0 +1,27 @@
+error[E0277]: the size for values of type `V` cannot be known at compilation time
+  --> $DIR/issue-unsized-tail-restatic-ice-122488.rs:5:61
+   |
+LL | struct ArenaSet<U: Deref, V: ?Sized = <U as Deref>::Target>(V, U);
+   |                           --------------------------------  ^ doesn't have a size known at compile-time
+   |                           |
+   |                           this type parameter needs to be `Sized`
+   |
+   = note: only the last field of a struct may have a dynamically sized type
+   = help: change the field's type to have a statically known size
+help: consider removing the `?Sized` bound to make the type parameter `Sized`
+   |
+LL - struct ArenaSet<U: Deref, V: ?Sized = <U as Deref>::Target>(V, U);
+LL + struct ArenaSet<U: Deref, V = <U as Deref>::Target>(V, U);
+   |
+help: borrowed types always have a statically known size
+   |
+LL | struct ArenaSet<U: Deref, V: ?Sized = <U as Deref>::Target>(&V, U);
+   |                                                             +
+help: the `Box` type always has a statically known size and allocates its contents in the heap
+   |
+LL | struct ArenaSet<U: Deref, V: ?Sized = <U as Deref>::Target>(Box<V>, U);
+   |                                                             ++++ +
+
+error: aborting due to 1 previous error
+
+For more information about this error, try `rustc --explain E0277`.