From 37735b4d6d6e0c4acbea2351794abdcd78ff9363 Mon Sep 17 00:00:00 2001 From: Tshepang Lekhonkhobe <tshepang@gmail.com> Date: Wed, 21 Oct 2015 07:06:00 +0200 Subject: [PATCH 1/5] run rustfmt on std::path There was a bunch of manual fixes too... rustfmt isn't quite there yet --- src/libstd/path.rs | 261 ++++++++++++++++++++++++++++----------------- 1 file changed, 165 insertions(+), 96 deletions(-) diff --git a/src/libstd/path.rs b/src/libstd/path.rs index fe12b671235a2..7a4b8e9992c4e 100644 --- a/src/libstd/path.rs +++ b/src/libstd/path.rs @@ -48,7 +48,8 @@ //! The path APIs are built around the notion of "components", which roughly //! correspond to the substrings between path separators (`/` and, on Windows, //! `\`). The APIs for path parsing are largely specified in terms of the path's -//! components, so it's important to clearly understand how those are determined. +//! components, so it's important to clearly understand how those are +//! determined. //! //! A path can always be reconstructed into an *equivalent* path by //! putting together its components via `push`. Syntactically, the @@ -190,10 +191,9 @@ mod platform { // \\?\UNC\server\share path = &path[4..]; let (server, share) = match parse_two_comps(path, is_verbatim_sep) { - Some((server, share)) => (u8_slice_as_os_str(server), - u8_slice_as_os_str(share)), - None => (u8_slice_as_os_str(path), - u8_slice_as_os_str(&[])), + Some((server, share)) => + (u8_slice_as_os_str(server), u8_slice_as_os_str(share)), + None => (u8_slice_as_os_str(path), u8_slice_as_os_str(&[])), }; return Some(VerbatimUNC(server, share)); } else { @@ -206,7 +206,7 @@ mod platform { return Some(VerbatimDisk(c.to_ascii_uppercase())); } } - let slice = &path[.. idx.unwrap_or(path.len())]; + let slice = &path[..idx.unwrap_or(path.len())]; return Some(Verbatim(u8_slice_as_os_str(slice))); } } else if path.starts_with(b".\\") { @@ -219,10 +219,9 @@ mod platform { match parse_two_comps(path, is_sep_byte) { Some((server, share)) if !server.is_empty() && !share.is_empty() => { // \\server\share - return Some(UNC(u8_slice_as_os_str(server), - u8_slice_as_os_str(share))); + return Some(UNC(u8_slice_as_os_str(server), u8_slice_as_os_str(share))); } - _ => () + _ => (), } } else if path.len() > 1 && path[1] == b':' { // C: @@ -237,11 +236,11 @@ mod platform { fn parse_two_comps(mut path: &[u8], f: fn(u8) -> bool) -> Option<(&[u8], &[u8])> { let first = match path.iter().position(|x| f(*x)) { None => return None, - Some(x) => &path[.. x] + Some(x) => &path[..x], }; - path = &path[(first.len()+1)..]; + path = &path[(first.len() + 1)..]; let idx = path.iter().position(|x| f(*x)); - let second = &path[.. idx.unwrap_or(path.len())]; + let second = &path[..idx.unwrap_or(path.len())]; Some((first, second)) } } @@ -298,15 +297,25 @@ impl<'a> Prefix<'a> { } match *self { Verbatim(x) => 4 + os_str_len(x), - VerbatimUNC(x,y) => 8 + os_str_len(x) + - if os_str_len(y) > 0 { 1 + os_str_len(y) } - else { 0 }, + VerbatimUNC(x, y) => { + 8 + os_str_len(x) + + if os_str_len(y) > 0 { + 1 + os_str_len(y) + } else { + 0 + } + }, VerbatimDisk(_) => 6, - UNC(x,y) => 2 + os_str_len(x) + - if os_str_len(y) > 0 { 1 + os_str_len(y) } - else { 0 }, + UNC(x, y) => { + 2 + os_str_len(x) + + if os_str_len(y) > 0 { + 1 + os_str_len(y) + } else { + 0 + } + }, DeviceNS(x) => 4 + os_str_len(x), - Disk(_) => 2 + Disk(_) => 2, } } @@ -367,14 +376,18 @@ pub const MAIN_SEPARATOR: char = platform::MAIN_SEP; // Iterate through `iter` while it matches `prefix`; return `None` if `prefix` // is not a prefix of `iter`, otherwise return `Some(iter_after_prefix)` giving // `iter` after having exhausted `prefix`. -fn iter_after<A, I, J>(mut iter: I, mut prefix: J) -> Option<I> where - I: Iterator<Item=A> + Clone, J: Iterator<Item=A>, A: PartialEq +fn iter_after<A, I, J>(mut iter: I, mut prefix: J) -> Option<I> + where I: Iterator<Item = A> + Clone, + J: Iterator<Item = A>, + A: PartialEq { loop { let mut iter_next = iter.clone(); match (iter_next.next(), prefix.next()) { (Some(x), Some(y)) => { - if x != y { return None } + if x != y { + return None; + } } (Some(_), None) => return Some(iter), (None, None) => return Some(iter), @@ -398,14 +411,20 @@ unsafe fn u8_slice_as_os_str(s: &[u8]) -> &OsStr { /// Says whether the first byte after the prefix is a separator. fn has_physical_root(s: &[u8], prefix: Option<Prefix>) -> bool { - let path = if let Some(p) = prefix { &s[p.len()..] } else { s }; + let path = if let Some(p) = prefix { + &s[p.len()..] + } else { + s + }; !path.is_empty() && is_sep_byte(path[0]) } // basic workhorse for splitting stem and extension fn split_file_at_dot(file: &OsStr) -> (Option<&OsStr>, Option<&OsStr>) { unsafe { - if os_str_as_u8_slice(file) == b".." { return (Some(file), None) } + if os_str_as_u8_slice(file) == b".." { + return (Some(file), None); + } // The unsafety here stems from converting between &OsStr and &[u8] // and back. This is safe to do because (1) we only look at ASCII @@ -581,7 +600,7 @@ pub struct Components<'a> { #[derive(Clone)] #[stable(feature = "rust1", since = "1.0.0")] pub struct Iter<'a> { - inner: Components<'a> + inner: Components<'a>, } impl<'a> Components<'a> { @@ -609,8 +628,16 @@ impl<'a> Components<'a> { // Given the iteration so far, how much of the pre-State::Body path is left? #[inline] fn len_before_body(&self) -> usize { - let root = if self.front <= State::StartDir && self.has_physical_root { 1 } else { 0 }; - let cur_dir = if self.front <= State::StartDir && self.include_cur_dir() { 1 } else { 0 }; + let root = if self.front <= State::StartDir && self.has_physical_root { + 1 + } else { + 0 + }; + let cur_dir = if self.front <= State::StartDir && self.include_cur_dir() { + 1 + } else { + 0 + }; self.prefix_remaining() + root + cur_dir } @@ -645,28 +672,38 @@ impl<'a> Components<'a> { #[stable(feature = "rust1", since = "1.0.0")] pub fn as_path(&self) -> &'a Path { let mut comps = self.clone(); - if comps.front == State::Body { comps.trim_left(); } - if comps.back == State::Body { comps.trim_right(); } + if comps.front == State::Body { + comps.trim_left(); + } + if comps.back == State::Body { + comps.trim_right(); + } unsafe { Path::from_u8_slice(comps.path) } } /// Is the *original* path rooted? fn has_root(&self) -> bool { - if self.has_physical_root { return true } + if self.has_physical_root { + return true; + } if let Some(p) = self.prefix { - if p.has_implicit_root() { return true } + if p.has_implicit_root() { + return true; + } } false } /// Should the normalized path include a leading . ? fn include_cur_dir(&self) -> bool { - if self.has_root() { return false } + if self.has_root() { + return false; + } let mut iter = self.path[self.prefix_len()..].iter(); match (iter.next(), iter.next()) { (Some(&b'.'), None) => true, (Some(&b'.'), Some(&b)) => self.is_sep_byte(b), - _ => false + _ => false, } } @@ -679,7 +716,7 @@ impl<'a> Components<'a> { // separately via `include_cur_dir` b".." => Some(Component::ParentDir), b"" => None, - _ => Some(Component::Normal(unsafe { u8_slice_as_os_str(comp) })) + _ => Some(Component::Normal(unsafe { u8_slice_as_os_str(comp) })), } } @@ -689,7 +726,7 @@ impl<'a> Components<'a> { debug_assert!(self.front == State::Body); let (extra, comp) = match self.path.iter().position(|b| self.is_sep_byte(*b)) { None => (0, self.path), - Some(i) => (1, &self.path[.. i]), + Some(i) => (1, &self.path[..i]), }; (comp.len() + extra, self.parse_single_component(comp)) } @@ -700,8 +737,8 @@ impl<'a> Components<'a> { debug_assert!(self.back == State::Body); let start = self.len_before_body(); let (extra, comp) = match self.path[start..].iter().rposition(|b| self.is_sep_byte(*b)) { - None => (0, &self.path[start ..]), - Some(i) => (1, &self.path[start + i + 1 ..]), + None => (0, &self.path[start..]), + Some(i) => (1, &self.path[start + i + 1..]), }; (comp.len() + extra, self.parse_single_component(comp)) } @@ -713,7 +750,7 @@ impl<'a> Components<'a> { if comp.is_some() { return; } else { - self.path = &self.path[size ..]; + self.path = &self.path[size..]; } } } @@ -725,7 +762,7 @@ impl<'a> Components<'a> { if comp.is_some() { return; } else { - self.path = &self.path[.. self.path.len() - size]; + self.path = &self.path[..self.path.len() - size]; } } } @@ -799,12 +836,12 @@ impl<'a> Iterator for Components<'a> { State::Prefix if self.prefix_len() > 0 => { self.front = State::StartDir; debug_assert!(self.prefix_len() <= self.path.len()); - let raw = &self.path[.. self.prefix_len()]; - self.path = &self.path[self.prefix_len() .. ]; + let raw = &self.path[..self.prefix_len()]; + self.path = &self.path[self.prefix_len()..]; return Some(Component::Prefix(PrefixComponent { raw: unsafe { u8_slice_as_os_str(raw) }, - parsed: self.prefix.unwrap() - })) + parsed: self.prefix.unwrap(), + })); } State::Prefix => { self.front = State::StartDir; @@ -814,26 +851,28 @@ impl<'a> Iterator for Components<'a> { if self.has_physical_root { debug_assert!(!self.path.is_empty()); self.path = &self.path[1..]; - return Some(Component::RootDir) + return Some(Component::RootDir); } else if let Some(p) = self.prefix { if p.has_implicit_root() && !p.is_verbatim() { - return Some(Component::RootDir) + return Some(Component::RootDir); } } else if self.include_cur_dir() { debug_assert!(!self.path.is_empty()); self.path = &self.path[1..]; - return Some(Component::CurDir) + return Some(Component::CurDir); } } State::Body if !self.path.is_empty() => { let (size, comp) = self.parse_next_component(); - self.path = &self.path[size ..]; - if comp.is_some() { return comp } + self.path = &self.path[size..]; + if comp.is_some() { + return comp; + } } State::Body => { self.front = State::Done; } - State::Done => unreachable!() + State::Done => unreachable!(), } } None @@ -847,8 +886,10 @@ impl<'a> DoubleEndedIterator for Components<'a> { match self.back { State::Body if self.path.len() > self.len_before_body() => { let (size, comp) = self.parse_next_component_back(); - self.path = &self.path[.. self.path.len() - size]; - if comp.is_some() { return comp } + self.path = &self.path[..self.path.len() - size]; + if comp.is_some() { + return comp; + } } State::Body => { self.back = State::StartDir; @@ -856,29 +897,29 @@ impl<'a> DoubleEndedIterator for Components<'a> { State::StartDir => { self.back = State::Prefix; if self.has_physical_root { - self.path = &self.path[.. self.path.len() - 1]; - return Some(Component::RootDir) + self.path = &self.path[..self.path.len() - 1]; + return Some(Component::RootDir); } else if let Some(p) = self.prefix { if p.has_implicit_root() && !p.is_verbatim() { - return Some(Component::RootDir) + return Some(Component::RootDir); } } else if self.include_cur_dir() { - self.path = &self.path[.. self.path.len() - 1]; - return Some(Component::CurDir) + self.path = &self.path[..self.path.len() - 1]; + return Some(Component::CurDir); } } State::Prefix if self.prefix_len() > 0 => { self.back = State::Done; return Some(Component::Prefix(PrefixComponent { raw: unsafe { u8_slice_as_os_str(self.path) }, - parsed: self.prefix.unwrap() - })) + parsed: self.prefix.unwrap(), + })); } State::Prefix => { self.back = State::Done; - return None + return None; } - State::Done => unreachable!() + State::Done => unreachable!(), } } None @@ -935,7 +976,7 @@ impl<'a> cmp::Ord for Components<'a> { #[derive(Clone, Hash)] #[stable(feature = "rust1", since = "1.0.0")] pub struct PathBuf { - inner: OsString + inner: OsString, } impl PathBuf { @@ -976,10 +1017,8 @@ impl PathBuf { // in the special case of `C:` on Windows, do *not* add a separator { let comps = self.components(); - if comps.prefix_len() > 0 && - comps.prefix_len() == comps.path.len() && - comps.prefix.unwrap().is_drive() - { + if comps.prefix_len() > 0 && comps.prefix_len() == comps.path.len() && + comps.prefix.unwrap().is_drive() { need_sep = false } } @@ -1012,7 +1051,7 @@ impl PathBuf { self.as_mut_vec().truncate(len); true } - None => false + None => false, } } @@ -1059,7 +1098,9 @@ impl PathBuf { } fn _set_extension(&mut self, extension: &OsStr) -> bool { - if self.file_name().is_none() { return false; } + if self.file_name().is_none() { + return false; + } let mut stem = match self.file_stem() { Some(stem) => stem.to_os_string(), @@ -1161,7 +1202,9 @@ impl<'a> IntoCow<'a, Path> for &'a Path { #[stable(feature = "rust1", since = "1.0.0")] impl ToOwned for Path { type Owned = PathBuf; - fn to_owned(&self) -> PathBuf { self.to_path_buf() } + fn to_owned(&self) -> PathBuf { + self.to_path_buf() + } } #[stable(feature = "rust1", since = "1.0.0")] @@ -1227,7 +1270,7 @@ impl Into<OsString> for PathBuf { #[derive(Hash)] #[stable(feature = "rust1", since = "1.0.0")] pub struct Path { - inner: OsStr + inner: OsStr, } impl Path { @@ -1350,8 +1393,7 @@ impl Path { /// ``` #[stable(feature = "rust1", since = "1.0.0")] pub fn is_absolute(&self) -> bool { - self.has_root() && - (cfg!(unix) || self.prefix().is_some()) + self.has_root() && (cfg!(unix) || self.prefix().is_some()) } /// A path is *relative* if it is not absolute. @@ -1398,7 +1440,7 @@ impl Path { /// ``` #[stable(feature = "rust1", since = "1.0.0")] pub fn has_root(&self) -> bool { - self.components().has_root() + self.components().has_root() } /// The path without its final component, if any. @@ -1422,11 +1464,13 @@ impl Path { pub fn parent(&self) -> Option<&Path> { let mut comps = self.components(); let comp = comps.next_back(); - comp.and_then(|p| match p { - Component::Normal(_) | - Component::CurDir | - Component::ParentDir => Some(comps.as_path()), - _ => None + comp.and_then(|p| { + match p { + Component::Normal(_) | + Component::CurDir | + Component::ParentDir => Some(comps.as_path()), + _ => None, + } }) } @@ -1448,9 +1492,11 @@ impl Path { /// ``` #[stable(feature = "rust1", since = "1.0.0")] pub fn file_name(&self) -> Option<&OsStr> { - self.components().next_back().and_then(|p| match p { - Component::Normal(p) => Some(p.as_ref()), - _ => None + self.components().next_back().and_then(|p| { + match p { + Component::Normal(p) => Some(p.as_ref()), + _ => None, + } }) } @@ -1460,8 +1506,7 @@ impl Path { /// returns false), then `relative_from` returns `None`. #[unstable(feature = "path_relative_from", reason = "see #23284", issue = "23284")] - pub fn relative_from<'a, P: ?Sized + AsRef<Path>>(&'a self, base: &'a P) -> Option<&Path> - { + pub fn relative_from<'a, P: ?Sized + AsRef<Path>>(&'a self, base: &'a P) -> Option<&Path> { self._relative_from(base.as_ref()) } @@ -1785,7 +1830,7 @@ impl fmt::Debug for Path { /// Helper struct for safely printing paths with `format!()` and `{}` #[stable(feature = "rust1", since = "1.0.0")] pub struct Display<'a> { - path: &'a Path + path: &'a Path, } #[stable(feature = "rust1", since = "1.0.0")] @@ -1828,32 +1873,44 @@ impl cmp::Ord for Path { #[stable(feature = "rust1", since = "1.0.0")] impl AsRef<Path> for Path { - fn as_ref(&self) -> &Path { self } + fn as_ref(&self) -> &Path { + self + } } #[stable(feature = "rust1", since = "1.0.0")] impl AsRef<Path> for OsStr { - fn as_ref(&self) -> &Path { Path::new(self) } + fn as_ref(&self) -> &Path { + Path::new(self) + } } #[stable(feature = "rust1", since = "1.0.0")] impl AsRef<Path> for OsString { - fn as_ref(&self) -> &Path { Path::new(self) } + fn as_ref(&self) -> &Path { + Path::new(self) + } } #[stable(feature = "rust1", since = "1.0.0")] impl AsRef<Path> for str { - fn as_ref(&self) -> &Path { Path::new(self) } + fn as_ref(&self) -> &Path { + Path::new(self) + } } #[stable(feature = "rust1", since = "1.0.0")] impl AsRef<Path> for String { - fn as_ref(&self) -> &Path { Path::new(self) } + fn as_ref(&self) -> &Path { + Path::new(self) + } } #[stable(feature = "rust1", since = "1.0.0")] impl AsRef<Path> for PathBuf { - fn as_ref(&self) -> &Path { self } + fn as_ref(&self) -> &Path { + self + } } #[cfg(test)] @@ -2894,20 +2951,26 @@ mod tests { tp!("C:a\\b\\c", "C:d", "C:d"); tp!("C:", r"a\b\c", r"C:a\b\c"); tp!("C:", r"..\a", r"C:..\a"); - tp!("\\\\server\\share\\foo", "bar", "\\\\server\\share\\foo\\bar"); + tp!("\\\\server\\share\\foo", + "bar", + "\\\\server\\share\\foo\\bar"); tp!("\\\\server\\share\\foo", "C:baz", "C:baz"); tp!("\\\\?\\C:\\a\\b", "C:c\\d", "C:c\\d"); tp!("\\\\?\\C:a\\b", "C:c\\d", "C:c\\d"); tp!("\\\\?\\C:\\a\\b", "C:\\c\\d", "C:\\c\\d"); tp!("\\\\?\\foo\\bar", "baz", "\\\\?\\foo\\bar\\baz"); - tp!("\\\\?\\UNC\\server\\share\\foo", "bar", "\\\\?\\UNC\\server\\share\\foo\\bar"); + tp!("\\\\?\\UNC\\server\\share\\foo", + "bar", + "\\\\?\\UNC\\server\\share\\foo\\bar"); tp!("\\\\?\\UNC\\server\\share", "C:\\a", "C:\\a"); tp!("\\\\?\\UNC\\server\\share", "C:a", "C:a"); // Note: modified from old path API tp!("\\\\?\\UNC\\server", "foo", "\\\\?\\UNC\\server\\foo"); - tp!("C:\\a", "\\\\?\\UNC\\server\\share", "\\\\?\\UNC\\server\\share"); + tp!("C:\\a", + "\\\\?\\UNC\\server\\share", + "\\\\?\\UNC\\server\\share"); tp!("\\\\.\\foo\\bar", "baz", "\\\\.\\foo\\bar\\baz"); tp!("\\\\.\\foo\\bar", "C:a", "C:a"); // again, not sure about the following, but I'm assuming \\.\ should be verbatim @@ -2960,9 +3023,15 @@ mod tests { tp!("\\\\?\\C:\\a\\b", "\\\\?\\C:\\a", true); tp!("\\\\?\\C:\\a", "\\\\?\\C:\\", true); tp!("\\\\?\\C:\\", "\\\\?\\C:\\", false); - tp!("\\\\?\\UNC\\server\\share\\a\\b", "\\\\?\\UNC\\server\\share\\a", true); - tp!("\\\\?\\UNC\\server\\share\\a", "\\\\?\\UNC\\server\\share\\", true); - tp!("\\\\?\\UNC\\server\\share", "\\\\?\\UNC\\server\\share", false); + tp!("\\\\?\\UNC\\server\\share\\a\\b", + "\\\\?\\UNC\\server\\share\\a", + true); + tp!("\\\\?\\UNC\\server\\share\\a", + "\\\\?\\UNC\\server\\share\\", + true); + tp!("\\\\?\\UNC\\server\\share", + "\\\\?\\UNC\\server\\share", + false); tp!("\\\\.\\a\\b\\c", "\\\\.\\a\\b", true); tp!("\\\\.\\a\\b", "\\\\.\\a\\", true); tp!("\\\\.\\a", "\\\\.\\a", false); @@ -3028,7 +3097,7 @@ mod tests { tfe!(".", "foo", ".", false); tfe!("foo/", "bar", "foo.bar", true); tfe!("foo/.", "bar", "foo.bar", true); - tfe!("..", "foo", "..", false); + tfe!("..", "foo", "..", false); tfe!("foo/..", "bar", "foo/..", false); tfe!("/", "foo", "/", false); } From 900f36fde3c8cc78db1d889e9543aa522cd326da Mon Sep 17 00:00:00 2001 From: Amit Saha <amitsaha@users.noreply.github.com> Date: Tue, 3 Nov 2015 10:50:20 +1100 Subject: [PATCH 2/5] Specify Microsoft Windows and Mac OS X explicitly When referring to the different shared library extensions, specify the OS explicitly. --- src/doc/trpl/rust-inside-other-languages.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/doc/trpl/rust-inside-other-languages.md b/src/doc/trpl/rust-inside-other-languages.md index 5c0bde02f9605..61627c0b5a2fe 100644 --- a/src/doc/trpl/rust-inside-other-languages.md +++ b/src/doc/trpl/rust-inside-other-languages.md @@ -177,7 +177,8 @@ build deps examples libembed.so native That `libembed.so` is our ‘shared object’ library. We can use this file just like any shared object library written in C! As an aside, this may be -`embed.dll` or `libembed.dylib`, depending on the platform. +`embed.dll` (Microsoft Windows) or `libembed.dylib` (Mac OS X), depending on +your operating system. Now that we’ve got our Rust library built, let’s use it from our Ruby. From bf7c92038e56cfc66aebb9628e43150587fc8244 Mon Sep 17 00:00:00 2001 From: Bruno Tavares <connect+github@bltavares.com> Date: Tue, 3 Nov 2015 10:20:45 -0200 Subject: [PATCH 3/5] Closes #24954 --- src/test/run-pass/issue-24954.rs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 src/test/run-pass/issue-24954.rs diff --git a/src/test/run-pass/issue-24954.rs b/src/test/run-pass/issue-24954.rs new file mode 100644 index 0000000000000..f525274a1dfca --- /dev/null +++ b/src/test/run-pass/issue-24954.rs @@ -0,0 +1,22 @@ +// Copyright 2015 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +macro_rules! foo { + ($y:expr) => ({ + $y = 2; + }) +} + +#[allow(unused_variables)] +#[allow(unused_assignments)] +fn main() { + let mut x = 1; + foo!(x); +} From b0ca03923359afc8df92a802b7cc1476a72fb2d0 Mon Sep 17 00:00:00 2001 From: Jake Goulding <jake.goulding@gmail.com> Date: Tue, 3 Nov 2015 08:25:56 -0500 Subject: [PATCH 4/5] Mention what iterator terminators do with an empty iterator --- src/libcore/iter.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/libcore/iter.rs b/src/libcore/iter.rs index 262bfd5de992a..c7d01b4ec2e40 100644 --- a/src/libcore/iter.rs +++ b/src/libcore/iter.rs @@ -1565,6 +1565,8 @@ pub trait Iterator { /// as soon as it finds a `false`, given that no matter what else happens, /// the result will also be `false`. /// + /// An empty iterator returns `true`. + /// /// # Examples /// /// Basic usage: @@ -1613,6 +1615,8 @@ pub trait Iterator { /// as soon as it finds a `true`, given that no matter what else happens, /// the result will also be `true`. /// + /// An empty iterator returns `false`. + /// /// # Examples /// /// Basic usage: @@ -2071,6 +2075,8 @@ pub trait Iterator { /// /// Takes each element, adds them together, and returns the result. /// + /// An empty iterator returns the zero value of the type. + /// /// # Examples /// /// Basic usage: @@ -2094,6 +2100,8 @@ pub trait Iterator { /// Iterates over the entire iterator, multiplying all the elements /// + /// An empty iterator returns the one value of the type. + /// /// # Examples /// /// ``` From 6fb2333d7702356f8960840d41a4763bda074fe7 Mon Sep 17 00:00:00 2001 From: Toby Scrace <toby.scrace@gmail.com> Date: Wed, 4 Nov 2015 07:42:54 +0000 Subject: [PATCH 5/5] Fix #29542 Reword "Writing the logic" paragraph to prevent `unwrap` being confused for a macro. --- src/doc/trpl/error-handling.md | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/doc/trpl/error-handling.md b/src/doc/trpl/error-handling.md index b74aaef927d88..c693cceeac482 100644 --- a/src/doc/trpl/error-handling.md +++ b/src/doc/trpl/error-handling.md @@ -1605,14 +1605,11 @@ arguments. ## Writing the logic -We're all different in how we write code, but error handling is -usually the last thing we want to think about. This isn't very good -practice for good design, but it can be useful for rapidly -prototyping. In our case, because Rust forces us to be explicit about -error handling, it will also make it obvious what parts of our program -can cause errors. Why? Because Rust will make us call `unwrap`! This -can give us a nice bird's eye view of how we need to approach error -handling. +We all write code differently, but error handling is usually the last thing we +want to think about. This isn't great for the overall design of a program, but +it can be useful for rapid prototyping. Because Rust forces us to be explicit +about error handling (by making us call `unwrap`), it is easy to see which +parts of our program can cause errors. In this case study, the logic is really simple. All we need to do is parse the CSV data given to us and print out a field in matching rows. Let's do it. (Make