We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
collect
1 parent 3ea711f commit 3c74d02Copy full SHA for 3c74d02
library/core/src/iter/traits/iterator.rs
@@ -1968,6 +1968,15 @@ pub trait Iterator {
1968
where
1969
Self: Sized,
1970
{
1971
+ // This is too aggressive to turn on for everything all the time, but PR#137908
1972
+ // accidentally noticed that some rustc iterators had malformed `size_hint`s,
1973
+ // so this will help catch such things in debug-assertions-std runners,
1974
+ // even if users won't actually ever see it.
1975
+ if cfg!(debug_assertions) {
1976
+ let hint = self.size_hint();
1977
+ assert!(hint.1.is_none_or(|high| high >= hint.0), "Malformed size_hint {hint:?}");
1978
+ }
1979
+
1980
FromIterator::from_iter(self)
1981
}
1982
0 commit comments