Skip to content

Recommended way to avoid clippy error? #42

@bramp

Description

@bramp

I have the following code:

const INITIAL_BIAS: u32 = 72;
const BASE: u32         = 36;
const TMIN: u32         = 1;

const_assert!(INITIAL_BIAS % BASE <= BASE - TMIN); 
error: this comparison involving the minimum or maximum element for this type contains a case that is always true or always false
  --> src/punycode.rs:18:15
   |
18 | const_assert!(INITIAL_BIAS % BASE <= BASE - TMIN);
   |               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = note: `#[deny(clippy::absurd_extreme_comparisons)]` on by default
   = help: because `INITIAL_BIAS % BASE` is the minimum value for this type, this comparison is always true
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#absurd_extreme_comparisons

Basically in this example the constant expression INITIAL_BIAS % BASE = 0, and for unsigned ints 0 is always the smallest value, thus doing <= is always true.

I can disable the clippy warning for my file, but I'm curious if there is some way for const_assert to suppress this error? Otherwise is reduces the value of these const_assert a little bit, without disabling the clippy warning.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions