diff --git a/src/libstd/fs.rs b/src/libstd/fs.rs index 3f0acfeea2262..405edf556c6cf 100644 --- a/src/libstd/fs.rs +++ b/src/libstd/fs.rs @@ -1260,6 +1260,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 ec96157547383..c1eb4118faf7a 100644 --- a/src/libstd/path.rs +++ b/src/libstd/path.rs @@ -897,6 +897,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 d3da0fbc37192..18b7afe43aef6 100644 --- a/src/libstd/sys/cloudabi/shims/fs.rs +++ b/src/libstd/sys/cloudabi/shims/fs.rs @@ -150,6 +150,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/cloudabi/shims/net.rs b/src/libstd/sys/cloudabi/shims/net.rs index 93eaf6a9e7d69..1cfdf9b25be5b 100644 --- a/src/libstd/sys/cloudabi/shims/net.rs +++ b/src/libstd/sys/cloudabi/shims/net.rs @@ -289,6 +289,10 @@ impl Iterator for LookupHost { fn next(&mut self) -> Option { match self.0 {} } + + fn size_hint(&self) -> (usize, Option) { + (0, Some(0)) + } } pub fn lookup_host(_: &str) -> io::Result { diff --git a/src/libstd/sys/cloudabi/shims/os.rs b/src/libstd/sys/cloudabi/shims/os.rs index 1e355d9ad042e..40c6bd9b5b3da 100644 --- a/src/libstd/sys/cloudabi/shims/os.rs +++ b/src/libstd/sys/cloudabi/shims/os.rs @@ -53,6 +53,10 @@ 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/redox/fs.rs b/src/libstd/sys/redox/fs.rs index 2e2216186f1e6..0f222ac95319c 100644 --- a/src/libstd/sys/redox/fs.rs +++ b/src/libstd/sys/redox/fs.rs @@ -167,6 +167,16 @@ impl Iterator for ReadDir { } } } + + fn size_hint(&self) -> (usize, Option) { + // There's at most one entry for every newline; and there are at most + // two skipped entries. + let upper = self.data[(i + 1)..].iter() + .filter(|byte| byte == b'\n') + .count(); + let lower = upper.saturating_sub(2); + (lower, Some(upper)) + } } impl DirEntry { diff --git a/src/libstd/sys/redox/net/mod.rs b/src/libstd/sys/redox/net/mod.rs index 0291d7f0e927a..d9656b94812a9 100644 --- a/src/libstd/sys/redox/net/mod.rs +++ b/src/libstd/sys/redox/net/mod.rs @@ -36,6 +36,10 @@ impl Iterator for LookupHost { fn next(&mut self) -> Option { self.0.next() } + + fn size_hint(&self) -> (usize, Option) { + self.0.size_hint() + } } pub fn lookup_host(host: &str) -> Result { diff --git a/src/libstd/sys/unix/l4re.rs b/src/libstd/sys/unix/l4re.rs index 2121848967939..866ab46b9bd38 100644 --- a/src/libstd/sys/unix/l4re.rs +++ b/src/libstd/sys/unix/l4re.rs @@ -429,6 +429,10 @@ pub mod net { fn next(&mut self) -> Option { None } + + fn size_hint(&self) -> (usize, Option) { + (0, Some(0)) + } } unsafe impl Sync for LookupHost {} diff --git a/src/libstd/sys/wasm/fs.rs b/src/libstd/sys/wasm/fs.rs index b3c70a6685a6c..51c155874e82d 100644 --- a/src/libstd/sys/wasm/fs.rs +++ b/src/libstd/sys/wasm/fs.rs @@ -152,6 +152,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 e7476ab37f7c8..ef77315cf1c7c 100644 --- a/src/libstd/sys/wasm/net.rs +++ b/src/libstd/sys/wasm/net.rs @@ -291,6 +291,10 @@ impl Iterator for LookupHost { fn next(&mut self) -> Option { match self.0 {} } + + fn size_hint(&self) -> (usize, Option) { + (0, Some(0)) + } } pub fn lookup_host(_: &str) -> io::Result { diff --git a/src/libstd/sys/wasm/os.rs b/src/libstd/sys/wasm/os.rs index 23ca1754719be..2a67f5b127099 100644 --- a/src/libstd/sys/wasm/os.rs +++ b/src/libstd/sys/wasm/os.rs @@ -43,6 +43,10 @@ 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)] @@ -77,6 +81,10 @@ 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 b94482435597e..f5b7e01087f8f 100644 --- a/src/libstd/sys/windows/os.rs +++ b/src/libstd/sys/windows/os.rs @@ -192,6 +192,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)]