Skip to content

Commit 9c2489b

Browse files
committed
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.
2 parents 6307719 + 4168e02 commit 9c2489b

File tree

2 files changed

+5
-6
lines changed

2 files changed

+5
-6
lines changed

src/doc/trpl/traits.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ won’t have its methods:
247247
[write]: ../std/io/trait.Write.html
248248

249249
```rust,ignore
250-
let mut f = std::fs::File::open("foo.txt").ok().expect("Couldn’t open foo.txt");
250+
let mut f = std::fs::File::open("foo.txt").expect("Couldn’t open foo.txt");
251251
let buf = b"whatever"; // byte string literal. buf: &[u8; 8]
252252
let result = f.write(buf);
253253
# result.unwrap(); // ignore the error
@@ -266,7 +266,7 @@ We need to `use` the `Write` trait first:
266266
```rust,ignore
267267
use std::io::Write;
268268
269-
let mut f = std::fs::File::open("foo.txt").ok().expect("Couldn’t open foo.txt");
269+
let mut f = std::fs::File::open("foo.txt").expect("Couldn’t open foo.txt");
270270
let buf = b"whatever";
271271
let result = f.write(buf);
272272
# result.unwrap(); // ignore the error

src/libcore/result.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,16 +117,15 @@
117117
//! warning (by default, controlled by the `unused_must_use` lint).
118118
//!
119119
//! You might instead, if you don't want to handle the error, simply
120-
//! panic, by converting to an `Option` with `ok`, then asserting
121-
//! success with `expect`. This will panic if the write fails, proving
122-
//! a marginally useful message indicating why:
120+
//! assert success with `expect`. This will panic if the
121+
//! write fails, providing a marginally useful message indicating why:
123122
//!
124123
//! ```{.no_run}
125124
//! use std::fs::File;
126125
//! use std::io::prelude::*;
127126
//!
128127
//! let mut file = File::create("valuable_data.txt").unwrap();
129-
//! file.write_all(b"important message").ok().expect("failed to write message");
128+
//! file.write_all(b"important message").expect("failed to write message");
130129
//! ```
131130
//!
132131
//! You might also simply assert success:

0 commit comments

Comments
 (0)