Skip to content

rustdoc doesn't render non-trivial built-in Sized impls (and calls Sized impls auto trait impls) #149467

@fmease

Description

@fmease

Since #78181, we leverage our auto trait impl synthesizer to render negative impls of Sized for types that don't implement Sized. Contrary to actual auto traits, we intentionally never render any positive Sized impls, only negative ones or none at all. Most ADTs are unconditionally Sized, so it makes sense to omit these to avoid unnecessary visual clutter and to reduce page size.

Quick aside: Sized is not an auto trait, so ideally synthetic Sized impls wouldn't appear under a section titled Auto Trait Implementations but instead under one titled Built-in Trait Implementations (modulo bikeshedding).

I take issue with the fact that we don't render "non-trivial" built-in Sized impls. Why bother? Well, Sized is fundamental (so making a type Sized is a breaking change) and under which conditions the last field of a struct is Sized is technically part of the public API and should thus be accessible in rustdoc-generated docs.

If rustdoc@main doesn't render a Sized impl for certain generic types, they are either unconditionally or conditionally sized but sadly no further information is provided. Consider these examples:

  • struct Type<T: ?Sized>
    • is Type<T> Sized for all T where T: ?Sized? (ex. body: (Box<T>))
    • is Type<T> Sized iff T is Sized (for all T …)? (ex. body: (T))
  • struct Type<T: Deref>
    • is it unconditionally sized?
    • is it Sized iff <T as Deref>::Target is Sized (for all T …)?
  • struct Type<T: ?Sized, U: ?Sized>
    • which type param is responsible if any?
  • [and so on]

Potential CON: Could increase the artifact size for certain (a lot of?) crates. Rn it's unclear to me how bad the fallout would be. Needs to be investigated.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-synthetic-implsArea: Synthetic impls, used by rustdoc to document auto traits and traits with blanket implsC-bugCategory: This is a bug.S-blockedStatus: Blocked on something else such as an RFC or other implementation work.T-rustdocRelevant to the rustdoc team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions