diff --git a/src/libcore/option.rs b/src/libcore/option.rs index 3b1d2079800bf..0bb3262e56927 100644 --- a/src/libcore/option.rs +++ b/src/libcore/option.rs @@ -85,16 +85,17 @@ pub pure fn get_ref(opt: &r/Option) -> &r/T { } } -pub pure fn expect(opt: Option, reason: ~str) -> T { +pub pure fn expect(opt: Option, reason: ~str) -> T { /*! - * Gets the value out of an option, printing a specified message on - * failure + * Gets the value out of an option without copying, printing a + * specified message on failure. * * # Failure * * Fails if the value equals `none` */ - match opt { Some(copy x) => x, None => fail reason } + if opt.is_some() { move option::unwrap(move opt) } + else { fail reason } } pub pure fn map(opt: &Option, f: fn(x: &T) -> U) -> Option {