Allow specifying attributes in `impl` mode · Issue #406 · bitflags/bitflags · GitHub
Skip to content

Allow specifying attributes in impl mode #406

Closed

Description

@madsmtm

I'm considering cfg-gating the use of bitflags! in my libraries, and to that end it would be nice if it was possible to apply attributes to the generated impls as well.

The naive solution would be:

pub struct Flags(u8);

#[cfg(feature = "bitflags")]
bitflags! {
    impl Flags: u8 {
        // ...
    }
}

However, that works poorly with the doc_cfg (and doc_auto_cfg) feature, as the attribute is only applied to the macro, and isn't passed down to each output item.

Instead, I would like to be able to do the following:

#![feature(doc_cfg)]

pub struct Flags(u8);

#[cfg(feature = "bitflags")]
bitflags! {
    #[doc(cfg(feature = "bitflags"))]
    impl Flags: u8 {
        // ...
    }
}

Activity

  1. KodrAus commented on Jun 16, 2024

    @KodrAus
    Member

    Thanks for the report @madsmtm! Anywhere attributes are allowed to be specified we should support in the macros as much as possible. I think this is just a missing piece of functionality for the impl mode.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions