diff options
| author | bors <bors@rust-lang.org> | 2015-11-10 17:30:50 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2015-11-10 17:30:50 +0000 |
| commit | ea422eb4de1720d7bcfdc0fd850dc2d048da52ed (patch) | |
| tree | d74b085de3a55d243398d65b437b79f24f08f1e9 /src | |
| parent | 05b66b8a1c74fe1182e594b330a4f5ab502eacc4 (diff) | |
| parent | 4b0503f10f19aea023337ad8e82116690a238628 (diff) | |
| download | rust-ea422eb4de1720d7bcfdc0fd850dc2d048da52ed.tar.gz rust-ea422eb4de1720d7bcfdc0fd850dc2d048da52ed.zip | |
Auto merge of #29749 - steveklabnik:rollup, r=steveklabnik
- Successful merges: #29420, #29688, #29708, #29715, #29729, #29731 - Failed merges: #29544
Diffstat (limited to 'src')
| -rw-r--r-- | src/doc/trpl/dining-philosophers.md | 2 | ||||
| -rw-r--r-- | src/doc/trpl/documentation.md | 30 | ||||
| -rw-r--r-- | src/libcollections/vec.rs | 3 | ||||
| -rw-r--r-- | src/libcore/iter.rs | 27 | ||||
| -rw-r--r-- | src/libstd/path.rs | 15 |
5 files changed, 60 insertions, 17 deletions
diff --git a/src/doc/trpl/dining-philosophers.md b/src/doc/trpl/dining-philosophers.md index 5f66a5b9e29..50d758c3a10 100644 --- a/src/doc/trpl/dining-philosophers.md +++ b/src/doc/trpl/dining-philosophers.md @@ -232,7 +232,7 @@ also called a ‘vector’, and it’s a growable array type. We then use a [`for`][for] loop to iterate through the vector, getting a reference to each philosopher in turn. -[for]: for-loops.html +[for]: loops.html#for In the body of the loop, we call `p.eat()`, which is defined above: diff --git a/src/doc/trpl/documentation.md b/src/doc/trpl/documentation.md index e101d4bc0d4..dc91c90b0fd 100644 --- a/src/doc/trpl/documentation.md +++ b/src/doc/trpl/documentation.md @@ -373,6 +373,36 @@ we can add the `#[macro_use]` attribute. Second, we’ll need to add our own `main()` as well. Finally, a judicious use of `#` to comment out those two things, so they don’t show up in the output. +Another case where the use of `#` is handy is when you want to ignore +error handling. Lets say you want the following, + +```rust,ignore +/// use std::io; +/// let mut input = String::new(); +/// try!(io::stdin().read_line(&mut input)); +``` + +The problem is that `try!` returns a `Result<T, E>` and test functions +don't return anything so this will give a mismatched types error. + +```rust,ignore +/// A doc test using try! +/// +/// ``` +/// use std::io; +/// # fn foo() -> io::Result<()> { +/// let mut input = String::new(); +/// try!(io::stdin().read_line(&mut input)); +/// # Ok(()) +/// # } +/// ``` +# fn foo() {} +``` + +You can get around this by wrapping the code in a function. This catches +and swallows the `Result<T, E>` when running tests on the docs. This +pattern appears regularly in the standard library. + ### Running documentation tests To run the tests, either: diff --git a/src/libcollections/vec.rs b/src/libcollections/vec.rs index 716a07be2b4..c4e4059429f 100644 --- a/src/libcollections/vec.rs +++ b/src/libcollections/vec.rs @@ -1220,8 +1220,7 @@ impl<T> FromIterator<T> for Vec<T> { // expanded on this iteration in every case when the iterable is not // empty, but the loop in extend_desugared() is not going to see the // vector being full in the few subsequent loop iterations. - // So we get better branch prediction and the possibility to - // construct the vector with initial estimated capacity. + // So we get better branch prediction. let mut iterator = iterable.into_iter(); let mut vector = match iterator.next() { None => return Vec::new(), diff --git a/src/libcore/iter.rs b/src/libcore/iter.rs index da7d673cd96..f8c6e3cfdd7 100644 --- a/src/libcore/iter.rs +++ b/src/libcore/iter.rs @@ -371,22 +371,21 @@ pub trait Iterator { /// /// # Implementation notes /// - /// It is not enforced that an iterator implementation yields the - /// declared number of elements. A buggy iterator may yield less - /// than the lower bound or more than the upper bound of elements. + /// It is not enforced that an iterator implementation yields the declared + /// number of elements. A buggy iterator may yield less than the lower bound + /// or more than the upper bound of elements. /// - /// `size_hint()` is primarily intended to be used for optimizations - /// such as reserving space for the elements of the iterator, but - /// must not be trusted to e.g. omit bounds checks in unsafe code. - /// An incorrect implementation of `size_hint()` should not lead to - /// memory safety violations. + /// `size_hint()` is primarily intended to be used for optimizations such as + /// reserving space for the elements of the iterator, but must not be + /// trusted to e.g. omit bounds checks in unsafe code. An incorrect + /// implementation of `size_hint()` should not lead to memory safety + /// violations. /// - /// That said, the implementation should provide a correct - /// estimation, because otherwise it would be a violation of the - /// trait's protocol. + /// That said, the implementation should provide a correct estimation, + /// because otherwise it would be a violation of the trait's protocol. /// - /// The default implementation returns `(0, None)` which is correct - /// for any iterator. + /// The default implementation returns `(0, None)` which is correct for any + /// iterator. /// /// # Examples /// @@ -2750,7 +2749,7 @@ pub trait ExactSizeIterator: Iterator { /// implementation, you can do so. See the [trait-level] docs for an /// example. /// - /// This function has the same safety guarantees as [`size_hint()`] + /// This function has the same safety guarantees as the [`size_hint()`] /// function. /// /// [trait-level]: trait.ExactSizeIterator.html diff --git a/src/libstd/path.rs b/src/libstd/path.rs index b9a58a11764..6b5e16ae113 100644 --- a/src/libstd/path.rs +++ b/src/libstd/path.rs @@ -1013,6 +1013,21 @@ impl PathBuf { /// * if `path` has a root but no prefix (e.g. `\windows`), it /// replaces everything except for the prefix (if any) of `self`. /// * if `path` has a prefix but no root, it replaces `self`. + /// + /// # Examples + /// + /// ``` + /// use std::path::PathBuf; + /// + /// let mut path = PathBuf::new(); + /// path.push("/tmp"); + /// path.push("file.bk"); + /// assert_eq!(path, PathBuf::from("/tmp/file.bk")); + /// + /// // Pushing an absolute path replaces the current path + /// path.push("/etc/passwd"); + /// assert_eq!(path, PathBuf::from("/etc/passwd")); + /// ``` #[stable(feature = "rust1", since = "1.0.0")] pub fn push<P: AsRef<Path>>(&mut self, path: P) { self._push(path.as_ref()) |
