Skip to content

cfg_attr(docsrs) feature hints do not propagate to in kube for re-exports #1242

Open
@clux

Description

@clux

Current and expected behavior

Currently we set up some very nice doc annotations for our optional features such as ws:

#[cfg_attr(docsrs, doc(cfg(feature = "ws")))]

These show up perfectly on docs.rs/kube-client

Available on crate features client and ws only.

However, on the facade crate docs.rs/kube it's less good.

Available on crate feature client only.

This leads people to be confused because they are browsing docs.rs/kube and are being slightly lied to about feature choices as seen from continued confusion in comments from bugs like: #1159 (comment)

The problem arises because the ws feature flag is basically a kube-client and kube-core feature, and it's just propagated down into those crates. kube just re-exports everything it can find:

macro_rules! cfg_client {
($($item:item)*) => {
$(
#[cfg_attr(docsrs, doc(cfg(feature = "client")))]
#[cfg(feature = "client")]
$item
)*
}
}
macro_rules! cfg_config {
($($item:item)*) => {
$(
#[cfg_attr(docsrs, doc(cfg(feature = "config")))]
#[cfg(feature = "config")]
$item
)*
}
}
macro_rules! cfg_error {
($($item:item)*) => {
$(
#[cfg_attr(docsrs, doc(cfg(any(feature = "config", feature = "client"))))]
#[cfg(any(feature = "config", feature = "client"))]
$item
)*
}
}
cfg_client! {
pub mod api;
pub mod discovery;
pub mod client;
#[doc(inline)]
pub use api::Api;
#[doc(inline)]
pub use client::Client;
#[doc(inline)]
pub use discovery::Discovery;
}

Possible solution

Not sure exactly the best way forward here.

We could maybe try to explicitly namespace ws stuff better, but this is pretty insidious, and hard to retrofit without breaking a lot.

We could also perhaps consider importing the crates into a module workspace instead (merge the crates in one big crate). The need for having a multi-crate split is smaller these days with a locked versioning and re-exported features.

We could also just wait and hope docsrs gets better... It's not great that it doesn't detect this across crate boundaries, but it's also understandable, and probably hard. EDIT: yes. Open bug upstream rust-lang/rust#88743 . In a similar upstream bug, they do describe why it's hard: rust-lang/rust#83428 (comment)

Environment

docs.rs

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingdocsunclear documentationquestionDirection unclear; possibly a bug, possibly could be improved.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions