Open popematt opened 1 year ago
I suspect that removing the relationship between
CheckedAdd
andAdd
might be a breaking change,
Yes, that is a breaking change, sorry.
I wonder if the real "right" solution also involves getting checked operations into
core::ops
.
Those traits are all related to built-in language operators, so you can impl Add
to get a working +
operator on your own types. It's not impossible to think of having core traits for more numeric methods, but there's not any current precedent for that. Most of these num
traits were in the standard library before Rust 1.0, and were kicked out to live here instead.
Most of these num traits were in the standard library before Rust 1.0, and were kicked out to live here instead.
Do you know where I can find any of the history of that decision?
I found the commit history, but not much discussion. For this particular trait:
trait Int
in https://github.com/rust-lang/rust/commit/e51cc089da7f5a067d348ee48f494c5bca662f95trait Int
was deprecated in https://github.com/rust-lang/rust/commit/232424d9952700682373ccf2d578109f401ff023trait Int
was removed in https://github.com/rust-lang/rust/commit/eeb94886adccb3f13003f92f117115d17846ce1f
...and more generally, checked operation traits should not extend their unchecked counterparts.
I'd like to contribute a PR to implement
CheckedAdd
for theNonZero___
types instd::num
, but it is not possible since they do not implementcore::ops::Add
(for good reason). The way to unblock my desired change is to makeCheckedAdd
not extendAdd
.I suspect that removing the relationship between
CheckedAdd
andAdd
might be a breaking change, so I figured I'd propose the idea before I start a PR for it.The presence of an unchecked add implies that a checked add is possible, but a checked add does not imply that an unchecked add is possible. I think that, if anything,
Add
should extendCheckedAdd
(though I realize the practical difficulties of that). Given the relationship between them, I wonder if the real "right" solution also involves getting checked operations intocore::ops
. If it is, then I am willing to pursue that course of action instead of making changes tonum-traits
.