integer_arithmetic
and arithmetic_side_effects
trigger on user-defined types
#11220
Labels
C-bug
Category: Clippy is not doing the correct thing
I-false-positive
Issue: The lint was triggered on code it shouldn't have
Summary
As of Rust 1.71,
integer_arithmetic
started warning for arithmetic operations on user-defined types. On Rust 1.70 and earlier it did not. As far as I can tell, on earlier versions of Rust the lint was restricted to arithmetic operations on core integer types.This same problem applies to
arithemtic_side_effects
which is intended to replaceinteger_arithmetic
.User-defined types may implement
core::ops
traits in ways that always use checked and panic-free arithmetic internally. Thechecked
crate is an example. Such an approach makes it possible to use traditional arithmetic operators (which are easier to read) while still performing checked arithmetic, and perhaps more importantly deliberately don't implement unchecked arithmetic, and thus prevent you from doing the wrong thing (much in the same way this lint is intended to do).Warning for arithmetic operations on such types prevents them being from used as a strategy for mitigating this class of operations in a way that satisfies the lint.
Lint Name
integer_arithmetic
Reproducer
I tried this code:
I saw this happen:
I expected to see this happen:
Success
Version
Additional Labels
No response
The text was updated successfully, but these errors were encountered: