diff options
Diffstat (limited to '')
-rw-r--r-- | src/tools/clippy/src/docs/absurd_extreme_comparisons.txt | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/src/tools/clippy/src/docs/absurd_extreme_comparisons.txt b/src/tools/clippy/src/docs/absurd_extreme_comparisons.txt new file mode 100644 index 000000000..590bee28a --- /dev/null +++ b/src/tools/clippy/src/docs/absurd_extreme_comparisons.txt @@ -0,0 +1,25 @@ +### What it does +Checks for comparisons where one side of the relation is +either the minimum or maximum value for its type and warns if it involves a +case that is always true or always false. Only integer and boolean types are +checked. + +### Why is this bad? +An expression like `min <= x` may misleadingly imply +that it is possible for `x` to be less than the minimum. Expressions like +`max < x` are probably mistakes. + +### Known problems +For `usize` the size of the current compile target will +be assumed (e.g., 64 bits on 64 bit systems). This means code that uses such +a comparison to detect target pointer width will trigger this lint. One can +use `mem::sizeof` and compare its value or conditional compilation +attributes +like `#[cfg(target_pointer_width = "64")] ..` instead. + +### Example +``` +let vec: Vec<isize> = Vec::new(); +if vec.len() <= 0 {} +if 100 > i32::MAX {} +```
\ No newline at end of file |