stream: fix overflow in StreamMap::size_hint (#8216)

This commit is contained in:
Minh Vu
2026-06-23 09:49:54 +02:00
committed by GitHub
parent dc3a883b99
commit f59aae423e
2 changed files with 27 additions and 3 deletions
+24
View File
@@ -225,6 +225,30 @@ fn size_hint_without_upper() {
assert_eq!(size_hint, (3, None));
}
#[test]
fn size_hint_overflow() {
struct Monster;
impl Stream for Monster {
type Item = ();
fn poll_next(self: Pin<&mut Self>, _cx: &mut std::task::Context<'_>) -> Poll<Option<()>> {
panic!()
}
fn size_hint(&self) -> (usize, Option<usize>) {
(usize::MAX, Some(usize::MAX))
}
}
let mut map = StreamMap::new();
map.insert("a", Monster);
map.insert("b", Monster);
assert_eq!(map.size_hint(), (usize::MAX, None));
}
#[test]
fn new_capacity_zero() {
let map = StreamMap::<&str, stream::Pending<()>>::new();