Skip to content

rustdoc: explicit marker trait impl bounds are not simplified #63281

@Nemo157

Description

@Nemo157

Rustdoc currently renders automatic and explicit marker trait implementation bounds differently, for automatic implementations the bounds are simplified down to their most fundamental requirements, while explicit implementations show exactly what is specified.

As an example, here are two identically defined structs (Bar and Baz), one uses the automatic implementation for Send while the other has the same implementation explicitly defined, in both cases the direct requirement is Foo<T>: Send which can be simplified down to T: Send by looking at the bounds on Foo:

pub struct Foo<T>(T);

pub struct Bar<T>(Foo<T>);

pub struct Baz<T>(Foo<T>);

unsafe impl<T> Send for Baz<T> where Foo<T>: Send {}

and the associated impl Send renderings:

bar-send

baz-send

This will become more relevant if RFC 2145 is ever implemented, that should allow bounds to refer to private types in which case there is no way to go from the impl Send for Baz in the docs to see what the actual requirements are (but it is already possible to simulate that today if Foo is moved into a private module).

This is also an issue for the proc-macro in https://github.com/taiki-e/pin-project (cc @taiki-e), that produces an explicit implementation for Unpin that must refer to the field types so that it can work generically for any struct.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-trait-systemArea: Trait systemC-enhancementCategory: An issue proposing an enhancement or a PR with one.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