diff --git a/src/libstd/fs.rs b/src/libstd/fs.rs index 119bdfcb0f442..6f63dec91d865 100644 --- a/src/libstd/fs.rs +++ b/src/libstd/fs.rs @@ -1370,6 +1370,10 @@ impl Iterator for ReadDir { fn next(&mut self) -> Option> { self.0.next().map(|entry| entry.map(DirEntry)) } + + fn size_hint(&self) -> (usize, Option) { + self.0.size_hint() + } } impl DirEntry { diff --git a/src/libstd/path.rs b/src/libstd/path.rs index b8361d3e82599..53d3ad62f5ec6 100644 --- a/src/libstd/path.rs +++ b/src/libstd/path.rs @@ -846,6 +846,10 @@ impl<'a> Iterator for Iter<'a> { fn next(&mut self) -> Option<&'a OsStr> { self.inner.next().map(Component::as_os_str) } + + fn size_hint(&self) -> (usize, Option) { + self.inner.size_hint() + } } #[stable(feature = "rust1", since = "1.0.0")] diff --git a/src/libstd/sys/cloudabi/shims/fs.rs b/src/libstd/sys/cloudabi/shims/fs.rs index e6160d1457d26..f2a960b16d3ba 100644 --- a/src/libstd/sys/cloudabi/shims/fs.rs +++ b/src/libstd/sys/cloudabi/shims/fs.rs @@ -140,6 +140,7 @@ impl Iterator for ReadDir { fn next(&mut self) -> Option> { match self.0 {} } + } impl DirEntry { diff --git a/src/libstd/sys/cloudabi/shims/net.rs b/src/libstd/sys/cloudabi/shims/net.rs index 67c436fa7955d..a5f0407f414e9 100644 --- a/src/libstd/sys/cloudabi/shims/net.rs +++ b/src/libstd/sys/cloudabi/shims/net.rs @@ -299,6 +299,9 @@ impl Iterator for LookupHost { fn next(&mut self) -> Option { match self.0 {} } + fn size_hint(&self) -> (usize, Option) { + (0, Some(0)) + } } impl TryFrom<&str> for LookupHost { diff --git a/src/libstd/sys/cloudabi/shims/os.rs b/src/libstd/sys/cloudabi/shims/os.rs index 779e6d54b7c9f..25eb80aaf189d 100644 --- a/src/libstd/sys/cloudabi/shims/os.rs +++ b/src/libstd/sys/cloudabi/shims/os.rs @@ -43,6 +43,9 @@ impl<'a> Iterator for SplitPaths<'a> { fn next(&mut self) -> Option { match *self.0 {} } + fn size_hint(&self) -> (usize, Option) { + (0, Some(0)) + } } #[derive(Debug)] diff --git a/src/libstd/sys/wasm/fs.rs b/src/libstd/sys/wasm/fs.rs index e6160d1457d26..25d3c6f10f3dc 100644 --- a/src/libstd/sys/wasm/fs.rs +++ b/src/libstd/sys/wasm/fs.rs @@ -140,6 +140,10 @@ impl Iterator for ReadDir { fn next(&mut self) -> Option> { match self.0 {} } + + fn size_hint(&self) -> (usize, Option) { + (0, Some(0)) + } } impl DirEntry { diff --git a/src/libstd/sys/wasm/net.rs b/src/libstd/sys/wasm/net.rs index b7c3108f172f6..bd2e6b0eb9140 100644 --- a/src/libstd/sys/wasm/net.rs +++ b/src/libstd/sys/wasm/net.rs @@ -296,6 +296,9 @@ impl Iterator for LookupHost { fn next(&mut self) -> Option { match self.0 {} } + fn size_hint(&self) -> (usize, Option) { + (0, Some(0)) + } } impl TryFrom<&str> for LookupHost { diff --git a/src/libstd/sys/wasm/os.rs b/src/libstd/sys/wasm/os.rs index 91afdc8a5a0cc..fd8f9cc8e1496 100644 --- a/src/libstd/sys/wasm/os.rs +++ b/src/libstd/sys/wasm/os.rs @@ -33,6 +33,9 @@ impl<'a> Iterator for SplitPaths<'a> { fn next(&mut self) -> Option { match *self.0 {} } + fn size_hint(&self) -> (usize, Option) { + (0, Some(0)) + } } #[derive(Debug)] @@ -70,6 +73,9 @@ impl Iterator for Env { fn next(&mut self) -> Option<(OsString, OsString)> { match self.0 {} } + fn size_hint(&self) -> (usize, Option) { + (0, Some(0)) + } } pub fn env() -> Env { diff --git a/src/libstd/sys/windows/os.rs b/src/libstd/sys/windows/os.rs index a0da2498bb7e0..68fcec0ff8d1d 100644 --- a/src/libstd/sys/windows/os.rs +++ b/src/libstd/sys/windows/os.rs @@ -185,6 +185,15 @@ impl<'a> Iterator for SplitPaths<'a> { Some(super::os2path(&in_progress)) } } + + fn size_hint(&self) -> (usize, Option) { + // There will be at most N + 1 entries, where N is the number of + // remaining semicolons. + let data = self.data.clone(); + let semicolons = data.filter(|&b| b == (';' as u16)).count(); + + (0, Some(semicolons + 1)) + } } #[derive(Debug)]