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

doc_auto_cfg doesn't notice when a trait is impl'd in a module gated by a feature #101129

Closed
nicholasbishop opened this issue Aug 28, 2022 · 1 comment · Fixed by #101279
Closed
Labels
C-bug Category: This is a bug. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.

Comments

@nicholasbishop
Copy link
Contributor

nicholasbishop commented Aug 28, 2022

I noticed that after enabling doc_auto_cfg on a crate on docs.rs, some impls are missing the badge showing that a feature flag is needed to get that impl. For example, this impl is only available with the std feature enabled.

I think this is due to those impls being in a separate module, where the whole module is gated with a cfg(feature = "std"). Here's a minimalish example:

# In Cargo.toml:
[features]
coolstuff = []
// In src/lib.rs:
#![feature(doc_auto_cfg)]

pub struct S;
pub trait MyTrait1 {}
pub trait MyTrait2 {}

#[cfg(feature = "coolstuff")]
impl MyTrait1 for S {}

#[cfg(feature = "coolstuff")]
mod submod {
    use crate::{S, MyTrait2};
    impl MyTrait2 for S {}
}

Build with cargo +nightly doc -F coolstuff --open, then navigate to the page for struct S.

Under the "Trait Implementations" section, I see both impl MyTrait1 for S and impl MyTrait2 for S as expected. I also expect both to have a badge saying "Available on crate feature coolstuff only", but instead only MyTrait1 shows this badge.

image

Meta

rustc +nightly --version --verbose:

rustc 1.65.0-nightly (eaadb8947 2022-08-27)
binary: rustc
commit-hash: eaadb8947b850a025404082f6297766c4680a42a
commit-date: 2022-08-27
host: x86_64-unknown-linux-gnu
release: 1.65.0-nightly
LLVM version: 15.0.0
@nicholasbishop nicholasbishop added the C-bug Category: This is a bug. label Aug 28, 2022
@GuillaumeGomez GuillaumeGomez added the T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. label Sep 1, 2022
@GuillaumeGomez
Copy link
Member

This is an interesting case indeed! It seems to be very close to what was fixed in #101006. I'll send a PR shortly.

GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this issue Sep 1, 2022
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Sep 1, 2022
…_impl, r=notriddle

Fix doc_auto_cfg for impl blocks in different modules with different `cfg`

Fixes rust-lang#101129.

Just like reexports, impl blocks don't necessarily share the same "space" as the item they implement so we need to merge attributes from its parents as well.

r? `@notriddle`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants