Regression in v2: flag constants no longer appear in cargo doc output #320

Closed
opened 2023-03-18 13:10:24 -05:00 by nicholasbishop · 3 comments
nicholasbishop commented 2023-03-18 13:10:24 -05:00 (Migrated from github.com)

Steps to reproduce:

cargo new --lib bitflags-missing-docs
cd bitflags-missing-docs
cargo add bitflags

Replace src/lib.rs with:

bitflags::bitflags! {
    pub struct Flags: u32 {
        /// Hello.
        const HELLO = 1;
    }
}

Run cargo doc --open and search for "hello". It doesn't find anything of that name, and if you go to the Flags page it indeed has no documented constants.

image

If you change Cargo.toml to use bitflags = "1" and re-run cargo doc, the constant is there as expected:

image

Steps to reproduce: ``` cargo new --lib bitflags-missing-docs cd bitflags-missing-docs cargo add bitflags ``` Replace `src/lib.rs` with: ```rust bitflags::bitflags! { pub struct Flags: u32 { /// Hello. const HELLO = 1; } } ``` Run `cargo doc --open` and search for "hello". It doesn't find anything of that name, and if you go to the `Flags` page it indeed has no documented constants. ![image](https://user-images.githubusercontent.com/1023208/226126074-30b4abeb-0fcf-41a6-8eef-9bce0857993f.png) If you change `Cargo.toml` to use `bitflags = "1"` and re-run `cargo doc`, the constant is there as expected: ![image](https://user-images.githubusercontent.com/1023208/226126123-7e9076d3-5551-40d6-ac64-05db76a4de37.png)
nicholasbishop commented 2023-03-18 13:15:46 -05:00 (Migrated from github.com)

I think this is due to https://github.com/bitflags/bitflags/pull/282, as demonstrated with this example:

pub struct A;
pub struct B;

impl A {
    pub const VAL: u32 = 0;
}

const _: () = {
    impl B {
        pub const VAL: u32 = 0;
    }
};

pub const B2: u32 = B::VAL;

Running cargo doc on that shows A::VAL but not B::VAL.

I think this is due to https://github.com/bitflags/bitflags/pull/282, as demonstrated with this example: ```rust pub struct A; pub struct B; impl A { pub const VAL: u32 = 0; } const _: () = { impl B { pub const VAL: u32 = 0; } }; pub const B2: u32 = B::VAL; ``` Running `cargo doc` on that shows `A::VAL` but not `B::VAL`.
KodrAus commented 2023-03-23 16:49:36 -05:00 (Migrated from github.com)

This issue is fixed upstream, but won't make it to a stable release until April 20th so it might be worth us mitigating it here anyways. It should be fairly straightforward. We can split the impl block that defines those constants from the one that implements other methods and move the constants to outside the const _: () { .. } block.

This issue is fixed upstream, but won't make it to a stable release until April 20th so it might be worth us mitigating it here anyways. It should be fairly straightforward. We can split the `impl` block that defines those constants from the one that implements other methods and move the constants to outside the `const _: () { .. }` block.
nicholasbishop commented 2023-04-03 11:38:48 -05:00 (Migrated from github.com)

Thanks for the fix :)

Thanks for the fix :)
Sign in to join this conversation.
No labels
bug
good first issue
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
gh-bitflags/bitflags#320
No description provided.