Skip to content

Commit aa70788

Browse files
authored
Update rustdoc for iterator.rs
Because the neutral element of `<fNN as iter::Sum>` was changed to `neg_zero`, the documentation needed to be updated, as it was reporting incorrect information about what should be expected from the return.
1 parent 64e06c0 commit aa70788

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

library/core/src/iter/traits/iterator.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3493,7 +3493,9 @@ pub trait Iterator {
34933493
///
34943494
/// Takes each element, adds them together, and returns the result.
34953495
///
3496-
/// An empty iterator returns the zero value of the type.
3496+
/// An empty iterator returns the zero value of the type except in the event
3497+
/// of summing primitive types that have negative zero values like f32 and f64.
3498+
/// An empty iterator of these types will return the negative zero value.
34973499
///
34983500
/// `sum()` can be used to sum any type implementing [`Sum`][`core::iter::Sum`],
34993501
/// including [`Option`][`Option::sum`] and [`Result`][`Result::sum`].
@@ -3511,6 +3513,10 @@ pub trait Iterator {
35113513
/// let sum: i32 = a.iter().sum();
35123514
///
35133515
/// assert_eq!(sum, 6);
3516+
///
3517+
/// let b = [];
3518+
/// let sum: f32 = b.iter().sum();
3519+
/// assert_eq!(sum_b, -0.0_f32);
35143520
/// ```
35153521
#[stable(feature = "iter_arith", since = "1.11.0")]
35163522
fn sum<S>(self) -> S

0 commit comments

Comments
 (0)