Skip to content

Commit 9e89ffc

Browse files
committed
auto merge of #12931 : aochagavia/rust/option-take_unwrap, r=cmr
Using pattern matching instead of is_some + unwrap
2 parents 7647849 + ea8da6e commit 9e89ffc

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/libstd/option.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -311,10 +311,10 @@ impl<T> Option<T> {
311311
/// Fails if the value equals `None`.
312312
#[inline]
313313
pub fn take_unwrap(&mut self) -> T {
314-
if self.is_none() {
315-
fail!("called `Option::take_unwrap()` on a `None` value")
314+
match self.take() {
315+
Some(x) => x,
316+
None => fail!("called `Option::take_unwrap()` on a `None` value")
316317
}
317-
self.take().unwrap()
318318
}
319319

320320
/// Gets an immutable reference to the value inside an option.

0 commit comments

Comments
 (0)