Skip to content

Commit 60b8c70

Browse files
committed
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.
1 parent 871de6e commit 60b8c70

File tree

1 file changed

+38
-1
lines changed

1 file changed

+38
-1
lines changed

core/src/marker.rs

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,11 +151,48 @@ unsafe impl<T: Sync + ?Sized> Send for &T {}
151151
#[rustc_specialization_trait]
152152
#[rustc_deny_explicit_impl]
153153
#[rustc_do_not_implement_via_object]
154+
// `Sized` being coinductive, despite having supertraits, is okay as there are no user-written impls,
155+
// and we know that the supertraits are always implemented if the subtrait is just by looking at
156+
// the builtin impls.
154157
#[rustc_coinductive]
155-
pub trait Sized {
158+
pub trait Sized: MetaSized {
156159
// Empty.
157160
}
158161

162+
/// Types with a size that can be determined from pointer metadata.
163+
#[unstable(feature = "sized_hierarchy", issue = "none")]
164+
#[lang = "meta_sized"]
165+
#[diagnostic::on_unimplemented(
166+
message = "the size for values of type `{Self}` cannot be known",
167+
label = "doesn't have a known size"
168+
)]
169+
#[fundamental]
170+
#[rustc_specialization_trait]
171+
#[rustc_deny_explicit_impl]
172+
#[rustc_do_not_implement_via_object]
173+
// `MetaSized` being coinductive, despite having supertraits, is okay for the same reasons as
174+
// `Sized` above.
175+
#[rustc_coinductive]
176+
pub trait MetaSized: PointeeSized {
177+
// Empty
178+
}
179+
180+
/// Types that may or may not have a size.
181+
#[unstable(feature = "sized_hierarchy", issue = "none")]
182+
#[lang = "pointee_sized"]
183+
#[diagnostic::on_unimplemented(
184+
message = "values of type `{Self}` may or may not have a size",
185+
label = "may or may not have a known size"
186+
)]
187+
#[fundamental]
188+
#[rustc_specialization_trait]
189+
#[rustc_deny_explicit_impl]
190+
#[rustc_do_not_implement_via_object]
191+
#[rustc_coinductive]
192+
pub trait PointeeSized {
193+
// Empty
194+
}
195+
159196
/// Types that can be "unsized" to a dynamically-sized type.
160197
///
161198
/// For example, the sized array type `[i8; 2]` implements `Unsize<[i8]>` and

0 commit comments

Comments
 (0)