3 ms·
From the documentation of Iterator.sum https://doc.rust-lang.org/std/iter/trait.Iterator.html#method.sum https://doc.rust-lang.org/std/iter/trait.Iterator.html#
by mhaymo 10y ago
From the documentation of Iterator.sum https://doc.rust-lang.org/std/iter/trait.Iterator.html#method.sum https://doc.rust-lang.org/std/iter/trait.Iterator.html#metho...
> When calling sum and a primitive integer type is being returned, this method will panic if the computation overflows.
I thought Rust's strategy for numeric overflow is to panic only in debug mode. Has that strategy changed or is this a special case?
- steveklabnik 10y agoThis _might_ just be an oversight, would you like to file a bug? If not, I can.
- mhaymo 10y agoYou go ahead.
- steveklabnik 10y agohttps://github.com/rust-lang/rust/issues/35807 https://github.com/rust-lang/rust/issues/35807
- pbsd 10y agoI don't think it's an oversight; the implementation calls `checked_add` and `checked_mul` explicitly -- https://github.com/rust-lang/rust/blob/1744c46e47434d8c0b63a839678ce45f1988bb74/src/libcore/iter/traits.rs#L587-L625 https://github.com/rust-lang/rust/blob/1744c46e47434d8c0b63a...