What it does
This lint is would suggest rewrite the not quite correct (a + b) / 2 expression to the (recently stabilized) uN::midpoint/iN::midpoint/fN::midpoint functions, in order to prevent overflow of a + b, which the midpoint functions handle appropriately.
Advantage
- Eliminate a potential source of overflow
- Bring awareness to the surprisingly subtleness of midpoint
Drawbacks
- Introduce a function call (but at the same the implementation is very small and the functions are inlined 🤷)
Example
let a = 10_i32;
let b = 10_000_i32;
let mid = (a + b) / 2;
Should be written as:
let a = 10_i32;
let b = 10_000_i32;
let mid = a.midpoint(b);
What it does
This lint is would suggest rewrite the not quite correct
(a + b) / 2expression to the (recently stabilized)uN::midpoint/iN::midpoint/fN::midpointfunctions, in order to prevent overflow ofa + b, which themidpointfunctions handle appropriately.Advantage
Drawbacks
Example
Should be written as: