rust-lang/rust

rustdoc: doc_cfg on trait impls needs more visibility

yaahc opened this issue · 1 comments

yaahc commented

I'm trying to annotate all the parts of a crate that are available based on feature flags and I've had the following experience when annotating a trait impl.

#[cfg(feature = "registry")]
#[cfg_attr(docsrs, doc(cfg(feature = "registry")))]
impl<'a, L, S> LookupSpan<'a> for Layered<L, S>
where
    S: Subscriber + LookupSpan<'a>,
{
    type Data = S::Data;

    fn span_data(&'a self, id: &span::Id) -> Option<Self::Data> {
        self.inner.span_data(id)
    }
}

This is what it looks like with the default visibility

Screenshot from 2020-01-10 11-07-39

After expanding a single [+]

Screenshot from 2020-01-10 11-07-48

Fully expanded

Screenshot from 2020-01-10 11-08-00

Ideally the default visibility with everything minimized should still indicate that this trait impl is dependent upon the given feature.

(except I'm missing something) On the latest nightly the messages couldn't be seen at all

Cargo version

% cargo --version
cargo 1.46.0-nightly (c26576f9a 2020-06-23)

The code:

#![cfg_attr(docsrs, feature(doc_cfg))]

pub struct SomeType;

pub trait SomeTrait {
    type SomeAssoc;

    fn some_method(&self);
}

#[cfg(feature = "some_feature")]
#[cfg_attr(docsrs, doc(cfg(feature = "some_feature")))]
impl SomeTrait for SomeType {
    type SomeAssoc = i32;

    fn some_method(&self) {}
}

The command:

% RUSTDOCFLAGS="--cfg docsrs" cargo doc --features "some_feature" --open

The rendered documentation:
image

Expanded:
image