Skip to content

open_enum doesn't respect cfg(feature) because of emitted debug impl #19

@chris-oo

Description

@chris-oo

Gating say an enum variant behind the unstable feature causes open_enum to gate the derived enum correctly, but not the debug impl. This blocks us from having nice intra-doc links because it's quite annoying to then gate any doclink comments in that enum variant.

For example:

#[open_enum]
#[derive(AsBytes, FromBytes, FromZeroes, Debug, Clone, Copy, PartialEq, Eq)]
#[repr(u32)]
pub enum IgvmVariableHeaderType {
    ....
    #[cfg(feature = "unstable")]
    #[cfg_attr(docsrs, doc(cfg(feature = "unstable")))]
    IGVM_VHT_MEMORY_STATE_PARAMETER = 0x313,
}

becomes

    #[cfg(feature = "unstable")]
    #[cfg_attr(docsrs, doc(cfg(feature = "unstable")))]
    pub const IGVM_VHT_MEMORY_STATE_PARAMETER: IgvmVariableHeaderType = IgvmVariableHeaderType(787);
    ....
impl ::core::fmt::Debug for IgvmVariableHeaderType {
    fn fmt(&self, fmt: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        #![allow(unreachable_patterns)]
        let s = match *self {
        ....    
            Self::IGVM_VHT_DEVICE_TREE => stringify!(IGVM_VHT_DEVICE_TREE),
            Self::IGVM_VHT_MEMORY_STATE_PARAMETER => stringify!(IGVM_VHT_MEMORY_STATE_PARAMETER),
        ....

which doesn't compile because the type must also be cfg(feature) attr-ed in the emitted debug impl

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions