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

Conditionally derived traits using cfg_attr are not documented as being behind a feature flag. #103300

Open
cobward opened this issue Oct 20, 2022 · 3 comments
Labels
T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.

Comments

@cobward
Copy link

cobward commented Oct 20, 2022

When conditionally deriving a trait using cfg_attr, the doc_cfg feature gate is not documented. A minimal example can be found here, but is summarised below:

Example:

 #![feature(doc_auto_cfg)]
 #[cfg_attr(feature = "debug", derive(Debug))]
 pub struct Test();

Generates:

generated

Expectation:

expected

@GuillaumeGomez GuillaumeGomez added the T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. label Oct 20, 2022
@GuillaumeGomez
Copy link
Member

It's because the cfg information isn't kept. When I use macro expansion, here's what we get:

#![feature(prelude_import)]
#[prelude_import]
use std::prelude::rust_2021::*;
#[macro_use]
extern crate std;
pub struct Test();
#[automatically_derived]
impl ::core::fmt::Debug for Test {
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        ::core::fmt::Formatter::write_str(f, "Test")
    }
}

@GuillaumeGomez
Copy link
Member

It's much more complicated than what I originally imagined: when the function to generate the implementation is called, the provided item doesn't have the attribute around the derive at all. I'm investigating to see if there is a way to do it without breaking everything but the deeper I go, the less hope for that I have...

@mkroening
Copy link
Contributor

There is no way to work around this manually with #[doc(cfg(...))] in affected code currently, is there?

Thank you so much for your work!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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

3 participants