Skip to content

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

Closed
@golddranks

Description

@golddranks

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    T-dev-toolsRelevant to the dev-tools subteam, which will review and decide on the PR/issue.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