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

Help: CheckFillsUnalignedBits unsatisfied #80

Closed vadixidav closed 2 years ago

vadixidav commented 2 years ago

I am having an issue which can be found in this CI run (and below): https://github.com/uarc/uarc/runs/4735458638?check_suite_focus=true#step:5:29

error[E0277]: the trait bound `False: FillsUnalignedBits` is not satisfied
Error:    --> uarc-ll-emu/src/cpu.rs:33:1
    |
33  | struct Instruction {
    | ^^^^^^ the trait `FillsUnalignedBits` is not implemented for `False`
    |
note: required by a bound in `CheckFillsUnalignedBits`
   --> /home/runner/.cargo/registry/src/github.com-1ecc6299db9ec823/modular-bitfield-0.11.2/src/private/checks.rs:154:50
    |
154 |     <Self::CheckType as DispatchTrueFalse>::Out: FillsUnalignedBits,
    |                                                  ^^^^^^^^^^^^^^^^^^ required by this bound in `CheckFillsUnalignedBits`

Relevant code:

#[bitfield(bits = 16)]
struct Instruction {
    data0_mux: DataCounterMux,
    data_stack_pop: bool,
    data_stack_push: bool,
    branch: bool,
    data_counter_mux: DataCounterMux,
    call_stack_pop: bool,
    call_stack_push: bool,
    write: bool,
    carry_mux: CarryMux,
    carry_in_mux: CarryInMux,
    carry_in: bool,
    unused: B3,
}

#[derive(BitfieldSpecifier)]
#[bits = 3]
pub enum Data0Mux {
    D0,
    D1,
    Add,
    Nand,
    MainMemory,
    Immediate,
    Unused6,
    Unused7,
}

#[derive(BitfieldSpecifier)]
#[bits = 1]
pub enum DataCounterMux {
    DataCounter,
    Decrement,
}

#[derive(BitfieldSpecifier)]
#[bits = 1]
pub enum CarryMux {
    Carry,
    Add,
}

#[derive(BitfieldSpecifier)]
#[bits = 1]
pub enum CarryInMux {
    Carry,
    Instruction,
}

I haven't been able to figure out from the docs what it is trying to tell me. My bitfield has 16 bits in it, so it is a power of two. I am not quite sure what to do to continue debugging this aside from expanding the macros and looking into their code. It seems to be complaining about unaligned bits in some way, but it didn't seem like that was a requirement specified in the docs, and it uses bits in unaligned situations on several occasions. Any help would be greatly appreciated :+1:.

vadixidav commented 2 years ago

~I just ran cargo test on the master branch of this repository. It gives the same error for several of the tests among many others. It looks like this repository might need to be updated to support the newest Rust version.~

Nevermind, I was mistaken. It doesn't seem this happens in the tests.

vadixidav commented 2 years ago

Okay, I figured it out. It was actually a bug with my code. The first item was actually the wrong type 😅.