Skip to content

Commit 6a90e80

Browse files
committed
option: rewrite the API to use composition
1 parent f647ccc commit 6a90e80

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

80 files changed

+244
-277
lines changed

src/compiletest/compiletest.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,8 @@ pub fn parse_config(args: ~[~str]) -> config {
109109
compile_lib_path: matches.opt_str("compile-lib-path").unwrap(),
110110
run_lib_path: matches.opt_str("run-lib-path").unwrap(),
111111
rustc_path: opt_path(matches, "rustc-path"),
112-
clang_path: matches.opt_str("clang-path").map_move(|s| Path(s)),
113-
llvm_bin_path: matches.opt_str("llvm-bin-path").map_move(|s| Path(s)),
112+
clang_path: matches.opt_str("clang-path").map(|s| Path(s)),
113+
llvm_bin_path: matches.opt_str("llvm-bin-path").map(|s| Path(s)),
114114
src_base: opt_path(matches, "src-base"),
115115
build_base: opt_path(matches, "build-base"),
116116
aux_base: opt_path(matches, "aux-base"),
@@ -123,10 +123,10 @@ pub fn parse_config(args: ~[~str]) -> config {
123123
} else {
124124
None
125125
},
126-
logfile: matches.opt_str("logfile").map_move(|s| Path(s)),
127-
save_metrics: matches.opt_str("save-metrics").map_move(|s| Path(s)),
126+
logfile: matches.opt_str("logfile").map(|s| Path(s)),
127+
save_metrics: matches.opt_str("save-metrics").map(|s| Path(s)),
128128
ratchet_metrics:
129-
matches.opt_str("ratchet-metrics").map_move(|s| Path(s)),
129+
matches.opt_str("ratchet-metrics").map(|s| Path(s)),
130130
ratchet_noise_percent:
131131
matches.opt_str("ratchet-noise-percent").and_then(|s| from_str::<f64>(s)),
132132
runtool: matches.opt_str("runtool"),

src/libextra/comm.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ impl<T: Send> GenericPort<T> for SyncPort<T> {
114114
}
115115

116116
fn try_recv(&self) -> Option<T> {
117-
do self.duplex_stream.try_recv().map_move |val| {
117+
do self.duplex_stream.try_recv().map |val| {
118118
self.duplex_stream.try_send(());
119119
val
120120
}

src/libextra/dlist.rs

+18-15
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ impl<T> DList<T> {
165165
/// Remove the first Node and return it, or None if the list is empty
166166
#[inline]
167167
fn pop_front_node(&mut self) -> Option<~Node<T>> {
168-
do self.list_head.take().map_move |mut front_node| {
168+
do self.list_head.take().map |mut front_node| {
169169
self.length -= 1;
170170
match front_node.next.take() {
171171
Some(node) => self.list_head = link_with_prev(node, Rawlink::none()),
@@ -191,7 +191,7 @@ impl<T> DList<T> {
191191
/// Remove the last Node and return it, or None if the list is empty
192192
#[inline]
193193
fn pop_back_node(&mut self) -> Option<~Node<T>> {
194-
do self.list_tail.resolve().map_move_default(None) |tail| {
194+
do self.list_tail.resolve().map_default(None) |tail| {
195195
self.length -= 1;
196196
self.list_tail = tail.prev;
197197
match tail.prev.resolve() {
@@ -206,25 +206,27 @@ impl<T> Deque<T> for DList<T> {
206206
/// Provide a reference to the front element, or None if the list is empty
207207
#[inline]
208208
fn front<'a>(&'a self) -> Option<&'a T> {
209-
self.list_head.map(|head| &head.value)
209+
self.list_head.as_ref().map(|head| &head.value)
210210
}
211211

212212
/// Provide a mutable reference to the front element, or None if the list is empty
213213
#[inline]
214214
fn front_mut<'a>(&'a mut self) -> Option<&'a mut T> {
215-
self.list_head.map_mut(|head| &mut head.value)
215+
self.list_head.as_mut().map(|head| &mut head.value)
216216
}
217217

218218
/// Provide a reference to the back element, or None if the list is empty
219219
#[inline]
220220
fn back<'a>(&'a self) -> Option<&'a T> {
221-
self.list_tail.resolve_immut().map(|tail| &tail.value)
221+
let tmp = self.list_tail.resolve_immut(); // FIXME: #3511: shouldn't need variable
222+
tmp.as_ref().map(|tail| &tail.value)
222223
}
223224

224225
/// Provide a mutable reference to the back element, or None if the list is empty
225226
#[inline]
226227
fn back_mut<'a>(&'a mut self) -> Option<&'a mut T> {
227-
self.list_tail.resolve().map_mut(|tail| &mut tail.value)
228+
let mut tmp = self.list_tail.resolve(); // FIXME: #3511: shouldn't need variable
229+
tmp.as_mut().map(|tail| &mut tail.value)
228230
}
229231

230232
/// Add an element first in the list
@@ -238,7 +240,7 @@ impl<T> Deque<T> for DList<T> {
238240
///
239241
/// O(1)
240242
fn pop_front(&mut self) -> Option<T> {
241-
self.pop_front_node().map_move(|~Node{value, _}| value)
243+
self.pop_front_node().map(|~Node{value, _}| value)
242244
}
243245

244246
/// Add an element last in the list
@@ -252,7 +254,7 @@ impl<T> Deque<T> for DList<T> {
252254
///
253255
/// O(1)
254256
fn pop_back(&mut self) -> Option<T> {
255-
self.pop_back_node().map_move(|~Node{value, _}| value)
257+
self.pop_back_node().map(|~Node{value, _}| value)
256258
}
257259
}
258260

@@ -268,7 +270,7 @@ impl<T> DList<T> {
268270
/// If the list is empty, do nothing.
269271
#[inline]
270272
pub fn rotate_forward(&mut self) {
271-
do self.pop_back_node().map_move |tail| {
273+
do self.pop_back_node().map |tail| {
272274
self.push_front_node(tail)
273275
};
274276
}
@@ -278,7 +280,7 @@ impl<T> DList<T> {
278280
/// If the list is empty, do nothing.
279281
#[inline]
280282
pub fn rotate_backward(&mut self) {
281-
do self.pop_front_node().map_move |head| {
283+
do self.pop_front_node().map |head| {
282284
self.push_back_node(head)
283285
};
284286
}
@@ -442,7 +444,7 @@ impl<'self, A> Iterator<&'self A> for DListIterator<'self, A> {
442444
if self.nelem == 0 {
443445
return None;
444446
}
445-
do self.head.map |head| {
447+
do self.head.as_ref().map |head| {
446448
self.nelem -= 1;
447449
self.head = &head.next;
448450
&head.value
@@ -461,7 +463,8 @@ impl<'self, A> DoubleEndedIterator<&'self A> for DListIterator<'self, A> {
461463
if self.nelem == 0 {
462464
return None;
463465
}
464-
do self.tail.resolve().map_move |prev| {
466+
let tmp = self.tail.resolve_immut(); // FIXME: #3511: shouldn't need variable
467+
do tmp.as_ref().map |prev| {
465468
self.nelem -= 1;
466469
self.tail = prev.prev;
467470
&prev.value
@@ -477,7 +480,7 @@ impl<'self, A> Iterator<&'self mut A> for MutDListIterator<'self, A> {
477480
if self.nelem == 0 {
478481
return None;
479482
}
480-
do self.head.resolve().map_move |next| {
483+
do self.head.resolve().map |next| {
481484
self.nelem -= 1;
482485
self.head = match next.next {
483486
Some(ref mut node) => Rawlink::some(&mut **node),
@@ -499,7 +502,7 @@ impl<'self, A> DoubleEndedIterator<&'self mut A> for MutDListIterator<'self, A>
499502
if self.nelem == 0 {
500503
return None;
501504
}
502-
do self.tail.resolve().map_move |prev| {
505+
do self.tail.resolve().map |prev| {
503506
self.nelem -= 1;
504507
self.tail = prev.prev;
505508
&mut prev.value
@@ -554,7 +557,7 @@ impl<'self, A> ListInsertion<A> for MutDListIterator<'self, A> {
554557
if self.nelem == 0 {
555558
return None
556559
}
557-
self.head.resolve().map_move(|head| &mut head.value)
560+
self.head.resolve().map(|head| &mut head.value)
558561
}
559562
}
560563

src/libextra/fileinput.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -596,8 +596,7 @@ mod test {
596596
|i| format!("tmp/lib-fileinput-test-next-file-{}.tmp", i)),true);
597597
598598
for (i, filename) in filenames.iter().enumerate() {
599-
let contents =
600-
vec::from_fn(3, |j| format!("{} {}", i, j + 1));
599+
let contents = vec::from_fn(3, |j| format!("{} {}", i, j + 1));
601600
make_file(filename.get_ref(), contents);
602601
}
603602

src/libextra/num/bigint.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -698,7 +698,7 @@ impl BigUint {
698698
#[inline]
699699
pub fn new(v: ~[BigDigit]) -> BigUint {
700700
// omit trailing zeros
701-
let new_len = v.iter().rposition(|n| *n != 0).map_move_default(0, |p| p + 1);
701+
let new_len = v.iter().rposition(|n| *n != 0).map_default(0, |p| p + 1);
702702

703703
if new_len == v.len() { return BigUint { data: v }; }
704704
let mut v = v;
@@ -1417,7 +1417,7 @@ impl BigInt {
14171417
start = 1;
14181418
}
14191419
return BigUint::parse_bytes(buf.slice(start, buf.len()), radix)
1420-
.map_move(|bu| BigInt::from_biguint(sign, bu));
1420+
.map(|bu| BigInt::from_biguint(sign, bu));
14211421
}
14221422
14231423
/// Converts this `BigInt` into a `BigUint`, if it's not negative.
@@ -2507,7 +2507,7 @@ mod bigint_tests {
25072507
#[test]
25082508
fn test_from_str_radix() {
25092509
fn check(s: &str, ans: Option<int>) {
2510-
let ans = ans.map_move(|n| {
2510+
let ans = ans.map(|n| {
25112511
let x: BigInt = FromPrimitive::from_int(n).unwrap();
25122512
x
25132513
});

src/libextra/smallintmap.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ impl<V> SmallIntMap<V> {
158158
{
159159
let values = replace(&mut self.v, ~[]);
160160
values.move_iter().enumerate().filter_map(|(i, v)| {
161-
v.map_move(|v| (i, v))
161+
v.map(|v| (i, v))
162162
})
163163
}
164164
}

src/libextra/term.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ impl Terminal {
127127
let inf = ti.unwrap();
128128
let nc = if inf.strings.find_equiv(&("setaf")).is_some()
129129
&& inf.strings.find_equiv(&("setab")).is_some() {
130-
inf.numbers.find_equiv(&("colors")).map_move_default(0, |&n| n)
130+
inf.numbers.find_equiv(&("colors")).map_default(0, |&n| n)
131131
} else { 0 };
132132

133133
return Ok(Terminal {out: out, ti: inf, num_colors: nc});
@@ -220,7 +220,7 @@ impl Terminal {
220220
cap = self.ti.strings.find_equiv(&("op"));
221221
}
222222
}
223-
let s = do cap.map_move_default(Err(~"can't find terminfo capability `sgr0`")) |op| {
223+
let s = do cap.map_default(Err(~"can't find terminfo capability `sgr0`")) |op| {
224224
expand(*op, [], &mut Variables::new())
225225
};
226226
if s.is_ok() {

src/libextra/test.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -241,20 +241,20 @@ pub fn parse_opts(args: &[~str]) -> Option<OptRes> {
241241
let run_ignored = matches.opt_present("ignored");
242242

243243
let logfile = matches.opt_str("logfile");
244-
let logfile = logfile.map_move(|s| Path(s));
244+
let logfile = logfile.map(|s| Path(s));
245245

246246
let run_benchmarks = matches.opt_present("bench");
247247
let run_tests = ! run_benchmarks ||
248248
matches.opt_present("test");
249249

250250
let ratchet_metrics = matches.opt_str("ratchet-metrics");
251-
let ratchet_metrics = ratchet_metrics.map_move(|s| Path(s));
251+
let ratchet_metrics = ratchet_metrics.map(|s| Path(s));
252252

253253
let ratchet_noise_percent = matches.opt_str("ratchet-noise-percent");
254-
let ratchet_noise_percent = ratchet_noise_percent.map_move(|s| from_str::<f64>(s).unwrap());
254+
let ratchet_noise_percent = ratchet_noise_percent.map(|s| from_str::<f64>(s).unwrap());
255255

256256
let save_metrics = matches.opt_str("save-metrics");
257-
let save_metrics = save_metrics.map_move(|s| Path(s));
257+
let save_metrics = save_metrics.map(|s| Path(s));
258258

259259
let test_shard = matches.opt_str("test-shard");
260260
let test_shard = opt_shard(test_shard);

src/libextra/treemap.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -385,15 +385,15 @@ impl<'self, T> Iterator<&'self T> for TreeSetIterator<'self, T> {
385385
/// Advance the iterator to the next node (in order). If there are no more nodes, return `None`.
386386
#[inline]
387387
fn next(&mut self) -> Option<&'self T> {
388-
do self.iter.next().map_move |(value, _)| { value }
388+
do self.iter.next().map |(value, _)| { value }
389389
}
390390
}
391391

392392
impl<'self, T> Iterator<&'self T> for TreeSetRevIterator<'self, T> {
393393
/// Advance the iterator to the next node (in order). If there are no more nodes, return `None`.
394394
#[inline]
395395
fn next(&mut self) -> Option<&'self T> {
396-
do self.iter.next().map |&(value, _)| { value }
396+
do self.iter.next().map |(value, _)| { value }
397397
}
398398
}
399399

@@ -686,7 +686,7 @@ fn mutate_values<'r, K: TotalOrd, V>(node: &'r mut Option<~TreeNode<K, V>>,
686686

687687
// Remove left horizontal link by rotating right
688688
fn skew<K: TotalOrd, V>(node: &mut ~TreeNode<K, V>) {
689-
if node.left.map_default(false, |x| x.level == node.level) {
689+
if node.left.as_ref().map_default(false, |x| x.level == node.level) {
690690
let mut save = node.left.take_unwrap();
691691
swap(&mut node.left, &mut save.right); // save.right now None
692692
swap(node, &mut save);
@@ -697,8 +697,8 @@ fn skew<K: TotalOrd, V>(node: &mut ~TreeNode<K, V>) {
697697
// Remove dual horizontal link by rotating left and increasing level of
698698
// the parent
699699
fn split<K: TotalOrd, V>(node: &mut ~TreeNode<K, V>) {
700-
if node.right.map_default(false,
701-
|x| x.right.map_default(false, |y| y.level == node.level)) {
700+
if node.right.as_ref().map_default(false,
701+
|x| x.right.as_ref().map_default(false, |y| y.level == node.level)) {
702702
let mut save = node.right.take_unwrap();
703703
swap(&mut node.right, &mut save.left); // save.left now None
704704
save.level += 1;
@@ -804,8 +804,8 @@ fn remove<K: TotalOrd, V>(node: &mut Option<~TreeNode<K, V>>,
804804
};
805805

806806
if rebalance {
807-
let left_level = save.left.map_default(0, |x| x.level);
808-
let right_level = save.right.map_default(0, |x| x.level);
807+
let left_level = save.left.as_ref().map_default(0, |x| x.level);
808+
let right_level = save.right.as_ref().map_default(0, |x| x.level);
809809

810810
// re-balance, if necessary
811811
if left_level < save.level - 1 || right_level < save.level - 1 {

src/librust/rust.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ fn rustdoc_help() {
128128
fn find_cmd(command_string: &str) -> Option<Command> {
129129
do COMMANDS.iter().find |command| {
130130
command.cmd == command_string
131-
}.map_move(|x| *x)
131+
}.map(|x| *x)
132132
}
133133

134134
fn cmd_help(args: &[~str]) -> ValidUsage {

src/librustc/driver/driver.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -719,7 +719,7 @@ pub fn build_session_options(binary: @str,
719719
} else if matches.opt_present("emit-llvm") {
720720
link::output_type_bitcode
721721
} else { link::output_type_exe };
722-
let sysroot_opt = matches.opt_str("sysroot").map_move(|m| @Path(m));
722+
let sysroot_opt = matches.opt_str("sysroot").map(|m| @Path(m));
723723
let target = matches.opt_str("target").unwrap_or(host_triple());
724724
let target_cpu = matches.opt_str("target-cpu").unwrap_or(~"generic");
725725
let target_feature = matches.opt_str("target-feature").unwrap_or(~"");

src/librustc/front/config.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ fn fold_mod(cx: &Context, m: &ast::_mod) -> ast::_mod {
7272
filter_item(cx, *a).and_then(|x| cx.fold_item(x))
7373
}.collect();
7474
let filtered_view_items = do m.view_items.iter().filter_map |a| {
75-
do filter_view_item(cx, a).map_move |x| {
75+
do filter_view_item(cx, a).map |x| {
7676
cx.fold_view_item(x)
7777
}
7878
}.collect();
@@ -97,7 +97,7 @@ fn fold_foreign_mod(cx: &Context, nm: &ast::foreign_mod) -> ast::foreign_mod {
9797
.filter_map(|a| filter_foreign_item(cx, *a))
9898
.collect();
9999
let filtered_view_items = do nm.view_items.iter().filter_map |a| {
100-
do filter_view_item(cx, a).map_move |x| {
100+
do filter_view_item(cx, a).map |x| {
101101
cx.fold_view_item(x)
102102
}
103103
}.collect();
@@ -152,12 +152,12 @@ fn fold_block(cx: &Context, b: &ast::Block) -> ast::Block {
152152
filter_stmt(cx, *a).and_then(|stmt| cx.fold_stmt(stmt))
153153
}.collect();
154154
let filtered_view_items = do b.view_items.iter().filter_map |a| {
155-
filter_view_item(cx, a).map(|x| cx.fold_view_item(*x))
155+
filter_view_item(cx, a).map(|x| cx.fold_view_item(x))
156156
}.collect();
157157
ast::Block {
158158
view_items: filtered_view_items,
159159
stmts: resulting_stmts,
160-
expr: b.expr.map(|x| cx.fold_expr(*x)),
160+
expr: b.expr.map(|x| cx.fold_expr(x)),
161161
id: b.id,
162162
rules: b.rules,
163163
span: b.span,

src/librustc/lib/llvm.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1786,7 +1786,7 @@ impl TypeNames {
17861786
}
17871787

17881788
pub fn find_type(&self, s: &str) -> Option<Type> {
1789-
self.named_types.find_equiv(&s).map_move(|x| Type::from_ref(*x))
1789+
self.named_types.find_equiv(&s).map(|x| Type::from_ref(*x))
17901790
}
17911791

17921792
// We have a depth count, because we seem to make infinite types.

src/librustc/metadata/cstore.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ pub fn add_extern_mod_stmt_cnum(cstore: &mut CStore,
133133
pub fn find_extern_mod_stmt_cnum(cstore: &CStore,
134134
emod_id: ast::NodeId)
135135
-> Option<ast::CrateNum> {
136-
cstore.extern_mod_crate_map.find(&emod_id).map_move(|x| *x)
136+
cstore.extern_mod_crate_map.find(&emod_id).map(|x| *x)
137137
}
138138

139139
#[deriving(Clone)]

0 commit comments

Comments
 (0)