Skip to content

Allow specifying attributes in impl mode #406

@madsmtm

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 {
        // ...
    }
}

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