rp-rs / pio-rs

Support crate for Raspberry Pi's PIO architecture.
MIT License
149 stars 22 forks source link

Fix clippy warning #36

Closed jannic closed 2 years ago

jannic commented 2 years ago

The old code caused this new clippy warning since rust 1.65.0, failing the CI build:

error: boolean to int conversion using if
   --> src/lib.rs:477:26
    |
477 |             bits: bits + if opt { 1 } else { 0 },
    |                          ^^^^^^^^^^^^^^^^^^^^^^^ help: replace with from: `u8::from(opt)`
    |
    = note: `-D clippy::bool-to-int-with-if` implied by `-D warnings`
    = note: `opt as u8` or `opt.into()` can also be valid options
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#bool_to_int_with_if

The fix suggested by clippy, u8::from(opt), doesn't work in const context:

error[E0015]: cannot call non-const fn `<u8 as core::convert::From<bool>>::from` in constant functions
   --> src/lib.rs:477:26
    |
477 |             bits: bits + u8::from(opt),
    |                          ^^^^^^^^^^^^^
    |
    = note: calls in constant functions are limited to constant functions, tuple structs and tuple variants

For more information about this error, try `rustc --explain E0015`.

The alterantive, opt as u8, does work.