Skip to content

Commit ee84ec1

Browse files
committed
vec: Add a debug assertion where TrustedLen is used
1 parent 622f24f commit ee84ec1

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/libcollections/vec.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1578,7 +1578,13 @@ impl<I> IsTrustedLen for I where I: Iterator { }
15781578
impl<I> IsTrustedLen for I where I: TrustedLen
15791579
{
15801580
fn trusted_len(&self) -> Option<usize> {
1581-
self.size_hint().1
1581+
let (low, high) = self.size_hint();
1582+
if let Some(high_value) = high {
1583+
debug_assert_eq!(low, high_value,
1584+
"TrustedLen iterator's size hint is not exact: {:?}",
1585+
(low, high));
1586+
}
1587+
high
15821588
}
15831589
}
15841590

0 commit comments

Comments
 (0)