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(cfg(…))] doesn’t work properly with cross-crate re-exports. #88743

Open
steffahn opened this issue Sep 8, 2021 · 4 comments
Open
Labels
A-cross-crate-reexports Area: Documentation that has been re-exported from a different crate A-rustdoc-ui Area: Rustdoc UI (generated HTML) C-bug Category: This is a bug. F-doc_cfg `#![feature(doc_cfg)]` requires-nightly This issue requires a nightly compiler in some way. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.

Comments

@steffahn
Copy link
Member

steffahn commented Sep 8, 2021

Hard to put in words the kind of mess that the situation currently seems to be…

Let’s just look at an example:

#![feature(doc_cfg)]

/// A module called `local_io`
pub mod local_io {}

#[doc(cfg(feature = "foo"))]
/// A module called `local_cfg_io`
pub mod local_cfg_io {}

pub mod m {
    #[doc(inline)]
    pub use std::io as io1;
    #[doc(no_inline)]
    pub use std::io as io2;
    #[doc(cfg(feature = "foo"), inline)]
    pub use std::io as io3;
    #[doc(cfg(feature = "foo"), no_inline)]
    pub use std::io as io4;

    #[doc(inline)]
    pub use crate::local_io as local_io1;
    #[doc(no_inline)]
    pub use crate::local_io as local_io2;
    #[doc(cfg(feature = "foo"), inline)]
    pub use crate::local_io as local_io3;
    #[doc(cfg(feature = "foo"), no_inline)]
    pub use crate::local_io as local_io4;

    #[doc(inline)]
    pub use crate::local_cfg_io as local_cfg_io1;
    #[doc(no_inline)]
    pub use crate::local_cfg_io as local_cfg_io2;
    #[doc(cfg(feature = "foo"), inline)]
    pub use crate::local_cfg_io as local_cfg_io3;
    #[doc(cfg(feature = "foo"), no_inline)]
    pub use crate::local_cfg_io as local_cfg_io4;
}

Resulting docs of module m:

Screenshot_20210908_152342

Bug description

As you can see above, the cfg(feature = "foo") is mostly ignored on the pub use items. Only external items with inline take that attribute into account.

Expected behavior

I would probably expect that the rendered cfg label on a re-export only depends on cfg(doc(…)) attributes on the pub use itself. For a no_inline item, this would mean that the label in the “Re-exports” list might differ from the label you see on the item itself once you click on it; maybe we want a more clear way to distinguish the cfg of the pub use from the cfg of the used item.


@rustbot label A-rustdoc-ui, F-doc_cfg, requires-nightly

@steffahn steffahn added the C-bug Category: This is a bug. label Sep 8, 2021
@rustbot rustbot added A-rustdoc-ui Area: Rustdoc UI (generated HTML) F-doc_cfg `#![feature(doc_cfg)]` requires-nightly This issue requires a nightly compiler in some way. labels Sep 8, 2021
@jyn514
Copy link
Member

jyn514 commented Sep 9, 2021

Didn't read all the test cases, but this is probably a duplicate of #85043 or vice versa.

@steffahn
Copy link
Member Author

steffahn commented Sep 9, 2021

Thanks for the link, I hadn't seen #85043 before.

It's related but I feel like the test cases cover somewhat of a different dimension. I guess, perhaps, the issues could be grouped as a single one. The new area that this issue covers is the behavior around items from other crates.

@jyn514 jyn514 changed the title #[doc(cfg(…))] doesn’t work properly with pub use. #[doc(cfg(…))] doesn’t work properly with cross-crate re-exports. Sep 9, 2021
@jyn514 jyn514 added the A-cross-crate-reexports Area: Documentation that has been re-exported from a different crate label Sep 9, 2021
@jyn514
Copy link
Member

jyn514 commented Sep 9, 2021

I would probably expect that the rendered cfg label on a re-export only depends on cfg(doc(…)) attributes on the pub use itself. For a no_inline item, this would mean that the label in the “Re-exports” list might differ from the label you see on the item itself once you click on it; maybe we want a more clear way to distinguish the cfg of the pub use from the cfg of the used item.

Hmm, this is surprising to me - wouldn't you want to AND the conditions? Since the export will only available if both the original and new cfgs are true? I guess that could lead to trouble for facade re-exports:

#[cfg(unix)]
mod unix {
  #[doc(cfg(unix))]
  pub struct Foo {}
}

#[cfg(windows)]
mod windows {
  #[doc(cfg(windows)]
  pub struct Foo {}
}

#[cfg(unix)]
pub use unix::Foo;
#[cfg(windows)]
pub use windows::Foo;

But I don't see a way for both that and

#[cfg(unix)]
pub use inner::UnixFoo;
#[cfg(windows)]
pub use inner::WindowsFoo;

to behave as expected - the first one you don't want to show the cfg, and the second you do.

Maybe that is an argument to only use the attributes on the re-export, so you have the most flexibility.

@Kixunil
Copy link
Contributor

Kixunil commented Mar 2, 2022

This also affects pub extern crate statements.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-cross-crate-reexports Area: Documentation that has been re-exported from a different crate A-rustdoc-ui Area: Rustdoc UI (generated HTML) C-bug Category: This is a bug. F-doc_cfg `#![feature(doc_cfg)]` requires-nightly This issue requires a nightly compiler in some way. 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

5 participants