Skip to content

Indicate when an item or impl depends on a feature #35903

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

Closed
golddranks opened this issue Aug 22, 2016 · 4 comments
Closed

Indicate when an item or impl depends on a feature #35903

golddranks opened this issue Aug 22, 2016 · 4 comments
Labels
T-dev-tools Relevant to the dev-tools subteam, which will review and decide on the PR/issue. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.

Comments

@golddranks
Copy link
Contributor

golddranks commented Aug 22, 2016

Crates that have features often cause confusion. For example, the Diesel documentation shows that there exists an impl for specific trait+type combination: (in this case DB=Pg, short for PostgreSQL)
(from Diesel documentation)

impl<DB> FromSqlRow<Timestamptz, DB> for DateTime<UTC> where
    DB: Backend + HasSqlType<Timestamptz>,
    DateTime<UTC>: FromSql<Timestamptz, DB>

and again:

impl FromSql<Timestamptz, Pg> for DateTime<UTC>
impl Backend for Pg
impl HasSqlType<Timestamptz> for Pg

Yet it fails on compilation:

error[E0277]: the trait bound chrono::datetime::DateTime<chrono::offset::utc::UTC>: diesel::types::FromSqlRow<diesel::types::Timestamptz, _> is not satisfied

The problem here is that FromSql<Timestamptz, Pg> for DateTime<UTC> and thus also FromSqlRow<Timestamptz, DB> for DateTime<UTC> are implemented only when the feature "chrono" is enabled. But the docs of FromSql and FromSqlRow don't indicate this at all.

This problem is mentioned elsewhere too: #18701 (however, that issue is about the manually written doc comments on impls). Features seem to stump and baffle users.

I think that Rustdoc should clearly indicate, when an impl, or a type, trait or module, for that matter, is available only when a certain feature is enabled. That would at make the features discoverable, which they currently often aren't.

@Nemo157
Copy link
Member

Nemo157 commented Nov 15, 2016

I've been working on this a bit and have a mostly working (horrible) implementation (sneak peek).

One thing I've found is that exactly where in the documentation something appears doesn't always line up nicely with where in the source tree it's defined (e.g. inherent impls can be defined in private modules for a type defined in a different public module, if that private module is affected by a feature then the only way to surface that in the docs is on the inherent impl block on the page for the struct/enum).

So, before pushing any kind of WIP implementation I'm going to try and create a simple crate showing an example of every way in which a feature could affect the documentation. Once I've got that I'll publish the docs my current implementation generates for that and try and do some design work directly on them (15 minute cycle with rebuilding rustdoc is a little slow to iterate on ☹️), then cleanup the implementation and create a PR for it.

I'll aim to get (at least the start of) the example crate up in a day or two. If there's anyone that can think of subtle ways features might influence the docs it'd be great if they could see that there's examples covering them in the crate. Or if there are any designers that may have input on how to display the features it'd be great to have some input once I have the initial sample up (I'm definitely not a designer, so having some input on this would be very useful).

@Nemo157
Copy link
Member

Nemo157 commented Nov 16, 2016

Pushed an example crate: https://github.com/Nemo157/rustdoc-features-example you can see how my initial implementation documents the features at https://nemo157.com/rustdoc-features-example/impl1/rustdoc_features_example/index.html.

@Nemo157
Copy link
Member

Nemo157 commented Nov 27, 2016

Pushed an almost complete implementation: https://github.com/Nemo157/rust/tree/rustdoc-features-2. Also pushed a render of the diesel docs using this implementation (e.g. the FromSql trait). Now just one small todo in the algorithmic code and need to figure out how to render it nicely before opening a PR.

@Mark-Simulacrum Mark-Simulacrum added the T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. label May 16, 2017
@Mark-Simulacrum Mark-Simulacrum changed the title Rustdoc: Indicate in the documentation when a module/type/trait/implementation is dependent on a feature Indicate when an item or impl depends on a feature May 16, 2017
@frewsxcv frewsxcv added the T-dev-tools Relevant to the dev-tools subteam, which will review and decide on the PR/issue. label May 18, 2017
@Mark-Simulacrum
Copy link
Member

Closing in favor of #1998.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T-dev-tools Relevant to the dev-tools subteam, which will review and decide on the PR/issue. 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