Auto merge of #29507 - fhartwig:result-expect, r=Manishearth

This fixes part of #29506
These instances of `ok().expect()` have no benefit over using `Result`'s `expect` directly.
This commit is contained in:
bors 2015-11-01 23:22:22 +00:00
commit 9c2489be0c
2 changed files with 5 additions and 6 deletions

View File

@ -247,7 +247,7 @@ wont have its methods:
[write]: ../std/io/trait.Write.html
```rust,ignore
let mut f = std::fs::File::open("foo.txt").ok().expect("Couldnt open foo.txt");
let mut f = std::fs::File::open("foo.txt").expect("Couldnt open foo.txt");
let buf = b"whatever"; // byte string literal. buf: &[u8; 8]
let result = f.write(buf);
# result.unwrap(); // ignore the error
@ -266,7 +266,7 @@ We need to `use` the `Write` trait first:
```rust,ignore
use std::io::Write;
let mut f = std::fs::File::open("foo.txt").ok().expect("Couldnt open foo.txt");
let mut f = std::fs::File::open("foo.txt").expect("Couldnt open foo.txt");
let buf = b"whatever";
let result = f.write(buf);
# result.unwrap(); // ignore the error

View File

@ -117,16 +117,15 @@
//! warning (by default, controlled by the `unused_must_use` lint).
//!
//! You might instead, if you don't want to handle the error, simply
//! panic, by converting to an `Option` with `ok`, then asserting
//! success with `expect`. This will panic if the write fails, proving
//! a marginally useful message indicating why:
//! assert success with `expect`. This will panic if the
//! write fails, providing a marginally useful message indicating why:
//!
//! ```{.no_run}
//! use std::fs::File;
//! use std::io::prelude::*;
//!
//! let mut file = File::create("valuable_data.txt").unwrap();
//! file.write_all(b"important message").ok().expect("failed to write message");
//! file.write_all(b"important message").expect("failed to write message");
//! ```
//!
//! You might also simply assert success: