Robbepop / modular-bitfield

Macro to generate bitfields for structs that allow for modular use of enums.
Apache License 2.0
155 stars 40 forks source link

Feature request: Allow naming fields "Bytes" #82

Open paul1999 opened 2 years ago

paul1999 commented 2 years ago

Hello there,

I just tried to create

#[derive(BitfieldSpecifier)]
pub enum Granularity {
    Bytes = 0,
    Scale4K = 1,
}

which failes because of ambiguity:

error: ambiguous associated item
   --> libk/src/x86/structures/gdt.rs:7:1
    |
7   | / pub enum Granularity {
8   | |     Bytes = 0,
9   | |     Scale4K = 1,
10  | | }
    | |_^ help: use fully-qualified syntax: `<Granularity as Specifier>::Bytes`
    |
    = note: `#[deny(ambiguous_associated_items)]` on by default
    = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
    = note: for more information, see issue #57644 <https://github.com/rust-lang/rust/issues/57644>
note: `Bytes` could refer to the variant defined here
   --> libk/src/x86/structures/gdt.rs:8:2
    |
8   |     Bytes = 0,
    |     ^^^^^^^^^
note: `Bytes` could also refer to the associated type defined here
   --> /home/paul/.cargo/registry/src/github.com-1ecc6299db9ec823/modular-bitfield-0.11.2/src/lib.rs:462:5
    |
462 |     type Bytes;
    |     ^^^^^^^^^^^

For now, I just renamed the field to ScaleByte, but it would be nice to support naming fields this way :)

Robbepop commented 2 years ago

Thanks for this feature request. This is indeed flawed and I consider it to be a bug actually. A better codegen should help this.