Skip to content

Commit 77aa031

Browse files
committed
Calculate capacity when collecting into Option and Result
1 parent d2652f6 commit 77aa031

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

src/libcore/option.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1267,8 +1267,7 @@ impl<A, V: FromIterator<A>> FromIterator<Option<A>> for Option<V> {
12671267
if self.found_none {
12681268
(0, Some(0))
12691269
} else {
1270-
let (_, upper) = self.iter.size_hint();
1271-
(0, upper)
1270+
self.iter.size_hint()
12721271
}
12731272
}
12741273
}

src/libcore/result.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -1176,9 +1176,13 @@ impl<A, E, V: FromIterator<A>> FromIterator<Result<A, E>> for Result<V, E> {
11761176
}
11771177
}
11781178

1179+
#[inline]
11791180
fn size_hint(&self) -> (usize, Option<usize>) {
1180-
let (_min, max) = self.iter.size_hint();
1181-
(0, max)
1181+
if self.err.is_some() {
1182+
(0, Some(0))
1183+
} else {
1184+
self.iter.size_hint()
1185+
}
11821186
}
11831187
}
11841188

0 commit comments

Comments
 (0)