Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Nemo157 opened this issue Aug 5, 2019 · 3 comments
Open

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

Nemo157 opened this issue Aug 5, 2019 · 3 comments
Labels
T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.

Comments

@Nemo157
Copy link
Member

Nemo157 commented Aug 5, 2019

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.

@jonas-schievink jonas-schievink added the T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. label Aug 5, 2019
@Aaron1011
Copy link
Member

Isn't this the correct behavior?

With the automatically generated impl, there's no user-written impl for Rustdoc to render. When a user impl is provided, however, I think it makes sense to render exactly what they wrote.

@Nemo157
Copy link
Member Author

Nemo157 commented Aug 8, 2019

If there are usecases for showing exactly how the impl was written, then maybe there could be a flag to opt-in to the behaviour of the automatically generated impl?

I have the extended problem I mentioned where it's impossible to determine what the bounds are from the docs in this crate, the Unpin impl depends on a "private" type so you would have to read the source to see what it is (and even worse there is no actual Unpin implementation on that type, it is also generated by a proc-macro so you would have to know how that macro works).

@taiki-e
Copy link
Member

taiki-e commented Aug 29, 2019

If the bounds can be simplified in any of the following cases, I think the issues with pin-project can be resolved.

  1. A structure in which #[doc(hidden)] is used.
  2. A structure generated by proc-macro.

bors bot added a commit to taiki-e/pin-project that referenced this issue Sep 4, 2019
71: Do not display UnpinStruct in the document by default r=taiki-e a=taiki-e

There are some problems as mentioned in #70 

This causes the problem that by default the actual Unpin bounds cannot be known from the document if the original struct/enum itself is public (see #53 (comment) and rust-lang/rust#63281 for more).

This can be enabled using `--cfg pin_project_show_unpin_struct` in RUSTFLAGS.

```toml
# in Cargo.toml
[package.metadata.docs.rs]
rustdoc-args = ["--cfg", "pin_project_show_unpin_struct"]
```

cc @Aaron1011 @seanmonstar @LucioFranco

Co-authored-by: Taiki Endo <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

4 participants