bitvec icon indicating copy to clipboard operation
bitvec copied to clipboard

(with nightly rust): src/slice/tests/api.rs: error[E0308]: mismatched types

Open krasimirgg opened this issue 4 months ago • 1 comments

Using a recent rustc 1.91.0-nightly (05f5a58e8 2025-08-19), building the tests fails:

% cargo +nightly test
error[E0308]: mismatched types
  --> src/slice/tests/api.rs:30:10
   |
30 |     assert!(bits.last().unwrap());
   |             ^^^^^^^^^^^^^^^^^^^^ expected `bool`, found `BitRef<'_>`
   |
   = note: expected struct `bool`
                found type `BitRef<'_>`
help: you might have meant to use field `data` whose type is `bool`
   |
30 |     assert!(bits.last().unwrap().data);
   |                                 +++++
help: consider dereferencing to access the inner value using the Deref trait
   |
30 |     assert!(*bits.last().unwrap());
   |             +

krasimirgg avatar Aug 20 '25 12:08 krasimirgg

Note that according to the doc, assert!() first argument is supposed to be a boolean, even though it accepted any type whose ! returned a bool.

Would using assert!(!!bits.last().unwrap()); be an acceptable workaround which would work in any case?

samueltardieu avatar Aug 23 '25 21:08 samueltardieu