diff --git a/src/libstd/option.rs b/src/libstd/option.rs index b70c8e172599886bc439554ff1e41167de51bf05..e4d843d88824d381a9aaa518725994e2ae0c2170 100644 --- a/src/libstd/option.rs +++ b/src/libstd/option.rs @@ -311,10 +311,10 @@ pub fn while_some(self, f: |v: T| -> Option) { /// Fails if the value equals `None`. #[inline] pub fn take_unwrap(&mut self) -> T { - if self.is_none() { - fail!("called `Option::take_unwrap()` on a `None` value") + match self.take() { + Some(x) => x, + None => fail!("called `Option::take_unwrap()` on a `None` value") } - self.take().unwrap() } /// Gets an immutable reference to the value inside an option.