Skip to content

Conversation

@davidtwco
Copy link
Member

@davidtwco davidtwco commented Oct 25, 2025

Part of #144404.

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::<<T as Deref>::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 seems unlikely enough that much code is relying solely on Deref::Target's ?Sized bound, so attempt to relax this to find out if it will break any code.

This is technically a breaking change so will need a crater run to determine whether it actually breaks anyone in practice.

r? @ghost

This is technically a breaking change so will need a crater run to
determine whether it actually breaks anyone in practice.
@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Oct 25, 2025
@rust-log-analyzer
Copy link
Collaborator

The job aarch64-gnu-llvm-20-1 failed! Check out the build log: (web) (plain enhanced) (plain)

Click to see the possible cause of the failure (guessed by this bot)
   Compiling yoke v0.8.0
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
   |
18 |     <C as Deref>::Target: 'static, <C as Deref>::Target: MetaSized
   |                                    +++++++++++++++++++++++++++++++

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 {
   |                                                      +++++++++++++++++++++++++++++++++++++

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:42:83
   |
42 |         Yoke::<Y, C>::attach_to_cart(cart, |c| <Y as Yokeable>::Output::zero_from(c))
   |                                                ---------------------------------- ^ the trait `MetaSized` is not implemented for `<C as Deref>::Target`
   |                                                |
   |                                                required by a bound introduced by this call
   |
   = note: the trait bound `<C as Deref>::Target: MetaSized` is not satisfied
note: required by a bound in `zero_from`
  --> /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::zero_from`
58 |     /// Clone the other `C` into a struct that may retain references into `C`.
59 |     fn zero_from(other: &'zf C) -> Self;
   |        --------- required by a bound in this associated function
help: consider borrowing here
   |
42 |         Yoke::<Y, C>::attach_to_cart(cart, |c| <Y as Yokeable>::Output::zero_from(&c))
   |                                                                                   +
42 |         Yoke::<Y, C>::attach_to_cart(cart, |c| <Y as Yokeable>::Output::zero_from(&mut c))
   |                                                                                   ++++

For more information about this error, try `rustc --explain E0277`.
[RUSTC-TIMING] yoke test:false 0.288
error: could not compile `yoke` (lib) due to 3 previous errors
warning: build failed, waiting for other jobs to finish...
[RUSTC-TIMING] zerovec_derive test:false 1.628
[RUSTC-TIMING] aho_corasick test:false 7.469
[RUSTC-TIMING] regex_syntax test:false 7.879
Bootstrap failed while executing `--stage 2 test --skip compiler --skip src`

@davidtwco
Copy link
Member Author

I guess that answers that question.

@davidtwco davidtwco closed this Oct 25, 2025
@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Oct 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

T-libs Relevant to the library team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants