Skip to content

Commit

Permalink
Auto merge of #34200 - sanxiyn:rollup, r=sanxiyn
Browse files Browse the repository at this point in the history
Rollup of 12 pull requests

- Successful merges: #34088, #34129, #34136, #34145, #34146, #34148, #34159, #34160, #34165, #34175, #34184, #34185
- Failed merges:
  • Loading branch information
bors authored Jun 10, 2016
2 parents 68241f0 + 107d423 commit a267d6c
Show file tree
Hide file tree
Showing 10 changed files with 349 additions and 262 deletions.
14 changes: 8 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,13 @@ build.
$ pacman -Sy pacman-mirrors
```
Download [MinGW from
here](http://mingw-w64.org/doku.php/download/mingw-builds), and choose the
`version=4.9.x,threads=win32,exceptions=dwarf/seh` flavor when installing. Also, make sure to install to a path without spaces in it. After installing,
add its `bin` directory to your `PATH`. This is due to [#28260](https://github.com/rust-lang/rust/issues/28260), in the future,
installing from pacman should be just fine.
Download [MinGW from
here](http://mingw-w64.org/doku.php/download/mingw-builds), and choose the
`version=4.9.x,threads=win32,exceptions=dwarf/seh` flavor when installing. Also, make sure to install to a path without spaces in it. After installing,
add its `bin` directory to your `PATH`. This is due to [#28260](https://github.com/rust-lang/rust/issues/28260), in the future,
installing from pacman should be just fine.
```
```sh
# Make git available in MSYS2 (if not already available on path)
$ pacman -S git
Expand All @@ -90,6 +90,8 @@ installing from pacman should be just fine.
3. Run `mingw32_shell.bat` or `mingw64_shell.bat` from wherever you installed
MSYS2 (i.e. `C:\msys`), depending on whether you want 32-bit or 64-bit Rust.
(As of the latest version of MSYS2 you have to run `msys2_shell.cmd -mingw32`
or `msys2_shell.cmd -mingw64` from the command line instead)
4. Navigate to Rust's source code, configure and build it:

Expand Down
20 changes: 8 additions & 12 deletions src/doc/book/error-handling.md
Original file line number Diff line number Diff line change
Expand Up @@ -1829,7 +1829,7 @@ use std::error::Error;
fn search<P: AsRef<Path>>
(file_path: P, city: &str)
-> Result<Vec<PopulationCount>, Box<Error+Send+Sync>> {
-> Result<Vec<PopulationCount>, Box<Error>> {
let mut found = vec![];
let file = try!(File::open(file_path));
let mut rdr = csv::Reader::from_reader(file);
Expand Down Expand Up @@ -1858,20 +1858,17 @@ Instead of `x.unwrap()`, we now have `try!(x)`. Since our function returns a
`Result<T, E>`, the `try!` macro will return early from the function if an
error occurs.

There is one big gotcha in this code: we used `Box<Error + Send + Sync>`
instead of `Box<Error>`. We did this so we could convert a plain string to an
error type. We need these extra bounds so that we can use the
[corresponding `From`
impls](../std/convert/trait.From.html):
At the end of `search` we also convert a plain string to an error type
by using the [corresponding `From` impls](../std/convert/trait.From.html):

```rust,ignore
// We are making use of this impl in the code above, since we call `From::from`
// on a `&'static str`.
impl<'a, 'b> From<&'b str> for Box<Error + Send + Sync + 'a>
impl<'a> From<&'a str> for Box<Error>
// But this is also useful when you need to allocate a new string for an
// error message, usually with `format!`.
impl From<String> for Box<Error + Send + Sync>
impl From<String> for Box<Error>
```

Since `search` now returns a `Result<T, E>`, `main` should use case analysis
Expand Down Expand Up @@ -1964,7 +1961,7 @@ use std::io;
fn search<P: AsRef<Path>>
(file_path: &Option<P>, city: &str)
-> Result<Vec<PopulationCount>, Box<Error+Send+Sync>> {
-> Result<Vec<PopulationCount>, Box<Error>> {
let mut found = vec![];
let input: Box<io::Read> = match *file_path {
None => Box::new(io::stdin()),
Expand Down Expand Up @@ -2175,9 +2172,8 @@ heuristics!
`unwrap`. Be warned: if it winds up in someone else's hands, don't be
surprised if they are agitated by poor error messages!
* If you're writing a quick 'n' dirty program and feel ashamed about panicking
anyway, then use either a `String` or a `Box<Error + Send + Sync>` for your
error type (the `Box<Error + Send + Sync>` type is because of the
[available `From` impls](../std/convert/trait.From.html)).
anyway, then use either a `String` or a `Box<Error>` for your
error type.
* Otherwise, in a program, define your own error types with appropriate
[`From`](../std/convert/trait.From.html)
and
Expand Down
Loading

0 comments on commit a267d6c

Please sign in to comment.