debug-assert that the size_hint is well-formed in collect
This commit is contained in:
@@ -1968,6 +1968,15 @@ pub trait Iterator {
|
|||||||
where
|
where
|
||||||
Self: Sized,
|
Self: Sized,
|
||||||
{
|
{
|
||||||
|
// This is too aggressive to turn on for everything all the time, but PR#137908
|
||||||
|
// accidentally noticed that some rustc iterators had malformed `size_hint`s,
|
||||||
|
// so this will help catch such things in debug-assertions-std runners,
|
||||||
|
// even if users won't actually ever see it.
|
||||||
|
if cfg!(debug_assertions) {
|
||||||
|
let hint = self.size_hint();
|
||||||
|
assert!(hint.1.is_none_or(|high| high >= hint.0), "Malformed size_hint {hint:?}");
|
||||||
|
}
|
||||||
|
|
||||||
FromIterator::from_iter(self)
|
FromIterator::from_iter(self)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user