Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
chris-oo opened this issue Dec 13, 2023 · 1 comment
Open

Comments

@chris-oo
Copy link
Member

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

@chris-oo
Copy link
Member Author

Requires a fix in open_enum which I'll take a look at.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant