Skip to content

Commit a07ea73

Browse files
committed
Make moves explicit in task; also make option::unwrap take its argument by move
1 parent 04f1763 commit a07ea73

File tree

3 files changed

+58
-55
lines changed

3 files changed

+58
-55
lines changed

src/libcore/option.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ pure fn map_consume<T, U>(+opt: Option<T>, f: fn(+T) -> U) -> Option<U> {
7474
* As `map`, but consumes the option and gives `f` ownership to avoid
7575
* copying.
7676
*/
77-
if opt.is_some() { Some(f(option::unwrap(move opt))) } else { None }
77+
if opt.is_some() { Some(f(option::unwrap(opt))) } else { None }
7878
}
7979

8080
pure fn chain<T, U>(opt: Option<T>, f: fn(T) -> Option<U>) -> Option<U> {
@@ -112,7 +112,7 @@ pure fn while_some<T>(+x: Option<T>, blk: fn(+T) -> Option<T>) {
112112
113113
let mut opt <- x;
114114
while opt.is_some() {
115-
opt = blk(unwrap(move opt));
115+
opt = blk(unwrap(opt));
116116
}
117117
}
118118

@@ -160,8 +160,10 @@ pure fn iter_ref<T>(opt: &Option<T>, f: fn(x: &T)) {
160160
match *opt { None => (), Some(ref t) => f(t) }
161161
}
162162

163+
// tjc: shouldn't this be - instead of +?
164+
// then could get rid of some superfluous moves
163165
#[inline(always)]
164-
pure fn unwrap<T>(+opt: Option<T>) -> T {
166+
pure fn unwrap<T>(-opt: Option<T>) -> T {
165167
/*!
166168
* Moves a value out of an option type and returns it.
167169
*
@@ -184,7 +186,7 @@ fn swap_unwrap<T>(opt: &mut Option<T>) -> T {
184186
pure fn unwrap_expect<T>(+opt: Option<T>, reason: &str) -> T {
185187
//! As unwrap, but with a specified failure message.
186188
if opt.is_none() { fail reason.to_unique(); }
187-
unwrap(move opt)
189+
unwrap(opt)
188190
}
189191

190192
// Some of these should change to be &Option<T>, some should not. See below.

0 commit comments

Comments
 (0)