Documentation for abs() on signed integers doesn't mention unsigned_abs() #124152
Labels
A-docs
Area: documentation for any part of the project, including the compiler, standard library, and tools
T-libs-api
Relevant to the library API team, which will review and decide on the PR/issue.
Location
https://doc.rust-lang.org/std/primitive.i8.html#method.abs
https://doc.rust-lang.org/std/primitive.i16.html#method.abs
https://doc.rust-lang.org/std/primitive.i32.html#method.abs
https://doc.rust-lang.org/std/primitive.i64.html#method.abs
https://doc.rust-lang.org/std/primitive.i128.html#method.abs
Summary
The documentation mentions that the
abs
method could cause undesired behavior in case aMIN
value of the type is passed.It could use a mention of the
unsigned_abs
method after this, which can fit all possible return values at cost of converting the value to an unsigned integer instead, which may have been the behavior one wanted when looking for this function in the documentation.It doesn't help that alphabetically
unsigned_abs
is sorted all the way down, whileabs
sits all the way up. A programmer could end up seeing onlyabs
, and assume that they need to either specially handleMIN
value, or use the immediately visibleabs_diff
function below that, with second parameter set to0
to achieve the wanted effect. (the latter could use a clippy lint? lol)The text was updated successfully, but these errors were encountered: