Skip to content

Expand doc comments to attributes before macro expansion #14197

Closed
@brendanzab

Description

@brendanzab

This would allow doc comments to parse them as $_:meta elements in macro invocations. This is useful for example with bitflags!:

bitflags! {
    #[doc = "Some flags"]
    #[doc = ""]
    #[doc = "A new line"]
    #[deriving(Show)]
    flags Flags: u32 {
        #[doc = "Flag A"]
        static FlagA = 0x00000001,
        #[doc = "Flag B"]
        static FlagB = 0x00000010
    }
}

vs:

bitflags! {
    /// Some flags
    ///
    /// A new line
    #[deriving(Show)]
    flags Flags: u32 {
        /// Flag A
        static FlagA = 0x00000001,
        /// Flag B
        static FlagB = 0x00000010
    }
}

Where the bitflags! match rule is defined as:

($(#[$attr:meta])* flags $BitFlags:ident: $T:ty {
    $($(#[$Flag_attr:meta])* static $Flag:ident = $value:expr),+
})

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-parserArea: The lexing & parsing of Rust source code to an ASTA-syntaxextArea: Syntax extensionsI-compiletimeIssue: Problems and improvements with respect to compile times.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions