Clippy doesn't correctly parse range

error: this range is empty so it will yield no values
   --> src/msgpack/
275 |         val if (32..2 ^ 16).contains(&val) => pack_i16(buf, 0xda, length as i16),
    |                ^^^^^^^^^^^^
    = note: `#[deny(clippy::reversed_empty_ranges)]` on by default
    = help: for further information visit
help: consider using the following if you are attempting to iterate over this range in reverse
275 |         val if (2 ^ 16..32).rev().contains(&val) => pack_i16(buf, 0xda, length as i16),
    |                ^^^^^^^^^^^^^^^^^^

Is this a bug or am I really not understanding what's happening here?

A few lines above this, I have the same general pattern:

        val if (16..2 ^ 16).contains(&val) => pack_i16(buf, 0xdc, length as i16),

2^16 performs bitwise xor, not exponent. You probably want 2.pow(16) or 1 << 16


Wow. Cool but not cool. Thanks so much!

For what it's worth this is the behavior in pretty much every programming language.


This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.