Skip to content

Issue checking duplicate variant indexes when using #[bitflags] #692

Closed
@serban300

Description

@serban300

Related to #691 and #690

This will lead to a compilation error:

#[bitflags]
#[repr(u64)]
#[derive(Copy, Clone, DeriveEncode, DeriveDecode)]
pub enum EnumWithU64Repr {
	/// This item is transferable.
	Transferable,
	/// The metadata of this item can be modified.
	UnlockedMetadata,
	/// Attributes of this item can be modified.
	UnlockedAttributes,
}

That's because #[bitflags] does:

pub enum EnumWithU64Repr {
    /// This item is transferable.
    Transferable = 1,
    /// The metadata of this item can be modified.
    UnlockedMetadata =
        ::enumflags2::_internal::next_bit(EnumWithU64Repr::Transferable as u128) as u64,
    /// Attributes of this item can be modified.
    UnlockedAttributes = ::enumflags2::_internal::next_bit(
        EnumWithU64Repr::Transferable as u128 | EnumWithU64Repr::UnlockedMetadata as u128,
    ) as u64,
}

And this will not work well with the duplicate variant indexes checking logic introduced in #653 and #687

Example of polkadot-sdk structure using #[bitflags]: ItemSettings

Metadata

Metadata

Assignees

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