Tracking Issue for Sized Hierarchy (original) (raw)

This is a tracking issue for the experimental implementation of RFC "Hierarchy of Sized traits" (rust-lang/rfcs#3729).
The feature gate for the issue is #![feature(sized_hierarchy)].

Approved by the language team for experimentation on Zulip.

This feature is part of the "Scalable Vectors" project goal from 2025h1 and 2025h2 (rust-lang/rust-project-goals#270). It was discussed with the language team in the 2024/11/13 design meeting and the 2025/02/05 design meeting.

About tracking issues

Tracking issues are used to record the overall progress of implementation.

They are also used as hubs connecting to other relevant issues, e.g., bugs or open design questions. A tracking issue is however not meant for large scale discussion, questions, or bug reports about a feature. Instead, open a dedicated issue for the specific matter and add the relevant feature gate label.

Discussion comments will get marked as off-topic or deleted. Repeated discussions on the tracking issue may lead to the tracking issue getting locked.

Steps

  1. Implement non-const parts of RFC (Sized Hierarchy: Part I #137944)
    • Introduces the MetaSized and PointeeSized traits and adds an implicit MetaSized supertrait to all traits by default
      * PointeeSized is a "fake" trait which is stripped out during lowering
    • There's value in this half of the changes, as it unblocks extern type, just not scalable vectors
    • ?Sized can be rewritten to MetaSized over an edition boundary and prohibit that syntax if desired
  2. Add #[rustc_no_implicit_bounds] (add #![rustc_no_implicit_bounds] #142671)
    • Requested by t-types. Useful for type system tests for debugging or simplification.
  3. Investigate relaxing Deref::Target
    • As with any associated type, the default ?Sized bound of Deref::Target cannot be relaxed backwards compatibly:
      trait Deref {
      type Target: ?Sized;
      }
      fn needs_metasized<T: ?Sized>() {}
      fn caller<T: Deref>() -> usize {
      needs_metasized::<::Target>()
      //~^ error! the trait bound <T as Deref>::Target: MetaSized is not satisfied
      }
      This is a known limitation of the proposal and for most use cases of the new sizedness traits is unlikely to be a major issue
      However, Deref is particularly tricky because in the limited relaxations in the standard library performed so far (because of the use of extern type in a couple places), plenty of code that could have been PointeeSized ended up being MetaSized only because of Deref.
    • It is not possible to relax Deref::Target without breaking everything:
    error[E0277]: the size for values of type `<C as Deref>::Target` cannot be known  
      --> /cargo/registry/src/index.crates.io-1949cf8c6b5b557f/yoke-0.8.0/src/zero_from.rs:16:42  
       |  
    16 |     for<'a> <Y as Yokeable<'a>>::Output: ZeroFrom<'a, <C as Deref>::Target>,  
       |                                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a known size  
       |  
       = help: the trait `MetaSized` is not implemented for `<C as Deref>::Target`  
    note: required by a bound in `ZeroFrom`  
      --> /cargo/registry/src/index.crates.io-1949cf8c6b5b557f/zerofrom-0.1.6/src/zero_from.rs:57:25  
       |  
    57 | pub trait ZeroFrom<'zf, C: ?Sized>: 'zf {  
       |                         ^ required by this bound in `ZeroFrom`  
    help: consider further restricting the associated type  
       |  
    41 |     pub fn attach_to_zero_copy_cart(cart: C) -> Self where <C as Deref>::Target: MetaSized {  
       |                                                      +++++++++++++++++++++++++++++++++++++  
  4. Investigate migration strategy for sizedness supertrait
    • There is a default MetaSized supertrait which prevents traits from being implemented on extern types unless this was considered by the definition of the trait.
  5. Split RFC into non-const and const parts so non-const parts can be stabilised sooner
    • There is sufficient interest in unblocking extern types
  6. Adjust documentation (see instructions on rustc-dev-guide)
  7. Style updates for any new syntax (nightly-style-procedure)
    • Style team decision on new formatting
    • Formatting for new syntax has been added to the Style Guide
    • (non-blocking) Formatting has been implemented in rustfmt
  8. Stabilization PR for non-const Sized Hierarchy (see instructions on rustc-dev-guide)
  9. Implement const Sized Hierarchy RFC - Introduces const Sized and const MetaSized and is necessary to unblock scalable vectors
    • To maintain backwards compatibility:
      * T: const Sized is the default bound
      * Explicitly written Sized is interpreted as const Sized
      * There is no way to write a non-const Sized bound
      * Sized could be rewritten to const Sized in the next edition and then Sized would mean non-const Sized as expected
      * ?Sized is interpreted as const MetaSized
      * Default supertrait is const MetaSized
    • All default bounds would be their strictest possible, making existing code incompatible with non-const Sized types, that isn't ideal, but those scalable vectors are the only intended use for non-const Sized which are niche and localised, so is tolerable
    • Currently blocked waiting on the next solver
      * The only practical way to implement this feature is to have the sizedness traits always be const behind-the-scenes but without the user being able to refer to their constness
      * This requires an a sufficient const traits implementation in both the old and next solvers, and the old solver's implementation is not sufficient
  10. Investigate and implement edition migration for const Sized Hierarchy
  1. Update RFC following experienced gained with experimentation and discuss with t-lang
  2. Wait on stabilisation of prerequisites (i.e. const traits)
  3. Adjust documentation (see instructions on rustc-dev-guide)
  4. Style updates for any new syntax (nightly-style-procedure)
  1. Stabilization PR (see instructions on rustc-dev-guide)

Unresolved Questions

Implementation history

Known issues