about summary refs log tree commit diff
path: root/library
diff options
context:
space:
mode:
authorDavid Wood <david.wood2@arm.com>2025-01-16 11:30:39 +0000
committerDavid Wood <david.wood2@arm.com>2025-06-16 15:00:22 +0000
commitd43da6f4de19ccfc6ac5a8e6b16ab8cf2893692a (patch)
treef329c84a05114bd22f78c8b97e969f7705f53be8 /library
parentd9ca9bd014074e2bac567eaa2b66bfacb2591028 (diff)
downloadrust-d43da6f4de19ccfc6ac5a8e6b16ab8cf2893692a.tar.gz
rust-d43da6f4de19ccfc6ac5a8e6b16ab8cf2893692a.zip
trait_sel: `{Meta,Pointee}Sized` on `Sized` types
Introduce the `MetaSized` and `PointeeSized` traits as supertraits of
`Sized` and initially implement it on everything that currently
implements `Sized` to isolate any changes that simply adding the
traits introduces.
Diffstat (limited to 'library')
-rw-r--r--library/core/src/marker.rs39
1 files changed, 38 insertions, 1 deletions
diff --git a/library/core/src/marker.rs b/library/core/src/marker.rs
index 9991b76cd0a..d7cf8955f26 100644
--- a/library/core/src/marker.rs
+++ b/library/core/src/marker.rs
@@ -151,11 +151,48 @@ unsafe impl<T: Sync + ?Sized> Send for &T {}
 #[rustc_specialization_trait]
 #[rustc_deny_explicit_impl]
 #[rustc_do_not_implement_via_object]
+// `Sized` being coinductive, despite having supertraits, is okay as there are no user-written impls,
+// and we know that the supertraits are always implemented if the subtrait is just by looking at
+// the builtin impls.
 #[rustc_coinductive]
-pub trait Sized {
+pub trait Sized: MetaSized {
     // Empty.
 }
 
+/// Types with a size that can be determined from pointer metadata.
+#[unstable(feature = "sized_hierarchy", issue = "none")]
+#[lang = "meta_sized"]
+#[diagnostic::on_unimplemented(
+    message = "the size for values of type `{Self}` cannot be known",
+    label = "doesn't have a known size"
+)]
+#[fundamental]
+#[rustc_specialization_trait]
+#[rustc_deny_explicit_impl]
+#[rustc_do_not_implement_via_object]
+// `MetaSized` being coinductive, despite having supertraits, is okay for the same reasons as
+// `Sized` above.
+#[rustc_coinductive]
+pub trait MetaSized: PointeeSized {
+    // Empty
+}
+
+/// Types that may or may not have a size.
+#[unstable(feature = "sized_hierarchy", issue = "none")]
+#[lang = "pointee_sized"]
+#[diagnostic::on_unimplemented(
+    message = "values of type `{Self}` may or may not have a size",
+    label = "may or may not have a known size"
+)]
+#[fundamental]
+#[rustc_specialization_trait]
+#[rustc_deny_explicit_impl]
+#[rustc_do_not_implement_via_object]
+#[rustc_coinductive]
+pub trait PointeeSized {
+    // Empty
+}
+
 /// Types that can be "unsized" to a dynamically-sized type.
 ///
 /// For example, the sized array type `[i8; 2]` implements `Unsize<[i8]>` and