Skip to content

Commit e8fe718

Browse files
committed
core: Replace map/map_default with map_ref/map_default_ref
1 parent 64de6d6 commit e8fe718

30 files changed

+79
-97
lines changed

src/compiletest/compiletest.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ fn parse_config(args: ~[~str]) -> config {
5858
} else { option::None },
5959
logfile: option::map(&getopts::opt_maybe_str(matches,
6060
~"logfile"),
61-
|s| Path(s)),
61+
|s| Path(*s)),
6262
runtool: getopts::opt_maybe_str(matches, ~"runtool"),
6363
rustcflags: getopts::opt_maybe_str(matches, ~"rustcflags"),
6464
jit: getopts::opt_present(matches, ~"jit"),

src/compiletest/header.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ fn parse_compile_flags(line: ~str) -> Option<~str> {
103103
fn parse_exec_env(line: ~str) -> Option<(~str, ~str)> {
104104
do parse_name_value_directive(line, ~"exec-env").map |nv| {
105105
// nv is either FOO or FOO=BAR
106-
let strs = str::splitn_char(nv, '=', 1u);
106+
let strs = str::splitn_char(*nv, '=', 1u);
107107
match strs.len() {
108108
1u => (strs[0], ~""),
109109
2u => (strs[0], strs[1]),

src/libcore/dlist.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -275,13 +275,13 @@ impl<T> DList<T> {
275275
/// Remove a node from the head of the list. O(1).
276276
fn pop_n() -> Option<DListNode<T>> {
277277
let hd = self.peek_n();
278-
hd.map(|nobe| self.unlink(nobe));
278+
hd.map(|nobe| self.unlink(*nobe));
279279
hd
280280
}
281281
/// Remove a node from the tail of the list. O(1).
282282
fn pop_tail_n() -> Option<DListNode<T>> {
283283
let tl = self.peek_tail_n();
284-
tl.map(|nobe| self.unlink(nobe));
284+
tl.map(|nobe| self.unlink(*nobe));
285285
tl
286286
}
287287
/// Get the node at the list's head. O(1).

src/libcore/iter.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ pure fn from_elem<T: Copy,BT: Buildable<T>>(n_elts: uint, t: T) -> BT {
290290
pure fn append<T: Copy,IT: BaseIter<T>,BT: Buildable<T>>(
291291
lhs: IT, rhs: IT) -> BT {
292292
let size_opt = lhs.size_hint().chain(
293-
|sz1| rhs.size_hint().map(|sz2| sz1+sz2));
293+
|sz1| rhs.size_hint().map(|sz2| sz1+*sz2));
294294
do build_sized_opt(size_opt) |push| {
295295
for lhs.each |x| { push(*x); }
296296
for rhs.each |x| { push(*x); }

src/libcore/option.rs

Lines changed: 5 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,7 @@ pure fn expect<T: Copy>(opt: &Option<T>, +reason: ~str) -> T {
6161
match *opt { Some(x) => x, None => fail reason }
6262
}
6363

64-
pure fn map<T, U>(opt: &Option<T>, f: fn(T) -> U) -> Option<U> {
65-
//! Maps a `some` value from one type to another
66-
67-
match *opt { Some(x) => Some(f(x)), None => None }
68-
}
69-
70-
pure fn map_ref<T, U>(opt: &Option<T>, f: fn(x: &T) -> U) -> Option<U> {
64+
pure fn map<T, U>(opt: &Option<T>, f: fn(x: &T) -> U) -> Option<U> {
7165
//! Maps a `some` value by reference from one type to another
7266
7367
match *opt { Some(ref x) => Some(f(x)), None => None }
@@ -138,14 +132,7 @@ pure fn get_default<T: Copy>(opt: &Option<T>, +def: T) -> T {
138132
match *opt { Some(x) => x, None => def }
139133
}
140134

141-
pure fn map_default<T, U>(opt: &Option<T>, +def: U, f: fn(T) -> U) -> U {
142-
//! Applies a function to the contained value or returns a default
143-
144-
match *opt { None => move def, Some(t) => f(t) }
145-
}
146-
147-
// This should replace map_default.
148-
pure fn map_default_ref<T, U>(opt: &Option<T>, +def: U,
135+
pure fn map_default<T, U>(opt: &Option<T>, +def: U,
149136
f: fn(x: &T) -> U) -> U {
150137
//! Applies a function to the contained value or returns a default
151138
@@ -200,17 +187,12 @@ impl<T> Option<T> {
200187
* function that returns an option.
201188
*/
202189
pure fn chain<U>(f: fn(T) -> Option<U>) -> Option<U> { chain(&self, f) }
203-
/// Applies a function to the contained value or returns a default
204-
pure fn map_default<U>(+def: U, f: fn(T) -> U) -> U
205-
{ map_default(&self, move def, f) }
206190
/// Performs an operation on the contained value or does nothing
207191
pure fn iter(f: fn(T)) { iter(&self, f) }
208192
/// Returns true if the option equals `none`
209193
pure fn is_none() -> bool { is_none(&self) }
210194
/// Returns true if the option contains some value
211195
pure fn is_some() -> bool { is_some(&self) }
212-
/// Maps a `some` value from one type to another
213-
pure fn map<U>(f: fn(T) -> U) -> Option<U> { map(&self, f) }
214196
}
215197

216198
impl<T> &Option<T> {
@@ -222,12 +204,12 @@ impl<T> &Option<T> {
222204
chain_ref(self, f)
223205
}
224206
/// Applies a function to the contained value or returns a default
225-
pure fn map_default_ref<U>(+def: U, f: fn(x: &T) -> U) -> U
226-
{ map_default_ref(self, move def, f) }
207+
pure fn map_default<U>(+def: U, f: fn(x: &T) -> U) -> U
208+
{ map_default(self, move def, f) }
227209
/// Performs an operation on the contained value by reference
228210
pure fn iter_ref(f: fn(x: &T)) { iter_ref(self, f) }
229211
/// Maps a `some` value from one type to another by reference
230-
pure fn map_ref<U>(f: fn(x: &T) -> U) -> Option<U> { map_ref(self, f) }
212+
pure fn map<U>(f: fn(x: &T) -> U) -> Option<U> { map(self, f) }
231213
/// Gets an immutable reference to the value inside a `some`.
232214
pure fn get_ref() -> &self/T { get_ref(self) }
233215
}

src/libcore/os.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,7 @@ fn self_exe_path() -> Option<Path> {
439439
}
440440

441441
do load_self().map |pth| {
442-
Path(pth).dir_path()
442+
Path(*pth).dir_path()
443443
}
444444
}
445445

src/libcore/task/local_data_priv.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,8 @@ unsafe fn local_data_lookup<T: Owned>(
7575
);
7676
do map_pos.map |index| {
7777
// .get() is guaranteed because of "None { false }" above.
78-
let (_, data_ptr, _) = (*map)[index].get();
79-
(index, data_ptr)
78+
let (_, data_ptr, _) = (*map)[*index].get();
79+
(*index, data_ptr)
8080
}
8181
}
8282

@@ -91,7 +91,7 @@ unsafe fn local_get_helper<T: Owned>(
9191
// was referenced in the local_data box, though, not here, so before
9292
// overwriting the local_data_box we need to give an extra reference.
9393
// We must also give an extra reference when not removing.
94-
let (index, data_ptr) = result;
94+
let (index, data_ptr) = *result;
9595
let data: @T = cast::transmute(move data_ptr);
9696
cast::bump_box_refcount(data);
9797
if do_pop {

src/libcore/task/spawn.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ fn each_ancestor(list: &mut AncestorList,
200200
// the end of the list, which doesn't make sense to coalesce.
201201
return do (**ancestors).map_default((None,false)) |ancestor_arc| {
202202
// NB: Takes a lock! (this ancestor node)
203-
do access_ancestors(&ancestor_arc) |nobe| {
203+
do access_ancestors(ancestor_arc) |nobe| {
204204
// Check monotonicity
205205
assert last_generation > nobe.generation;
206206
/*##########################################################*

src/libcore/vec.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -969,7 +969,7 @@ pure fn find<T: Copy>(v: &[T], f: fn(T) -> bool) -> Option<T> {
969969
*/
970970
pure fn find_between<T: Copy>(v: &[T], start: uint, end: uint,
971971
f: fn(T) -> bool) -> Option<T> {
972-
position_between(v, start, end, f).map(|i| v[i])
972+
position_between(v, start, end, f).map(|i| v[*i])
973973
}
974974

975975
/**
@@ -992,7 +992,7 @@ pure fn rfind<T: Copy>(v: &[T], f: fn(T) -> bool) -> Option<T> {
992992
*/
993993
pure fn rfind_between<T: Copy>(v: &[T], start: uint, end: uint,
994994
f: fn(T) -> bool) -> Option<T> {
995-
rposition_between(v, start, end, f).map(|i| v[i])
995+
rposition_between(v, start, end, f).map(|i| v[*i])
996996
}
997997

998998
/// Find the first index containing a matching value

src/libsyntax/diagnostic.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ fn highlight_lines(cm: codemap::codemap, sp: span,
262262
fn print_macro_backtrace(cm: codemap::codemap, sp: span) {
263263
do option::iter(&sp.expn_info) |ei| {
264264
let ss = option::map_default(&ei.callie.span, @~"",
265-
|span| @codemap::span_to_str(span, cm));
265+
|span| @codemap::span_to_str(*span, cm));
266266
print_diagnostic(*ss, note,
267267
fmt!("in expansion of #%s", ei.callie.name));
268268
let ss = codemap::span_to_str(ei.call_site, cm);

src/libsyntax/fold.rs

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ fn fold_mac_(m: mac, fld: ast_fold) -> mac {
114114
match m.node {
115115
mac_invoc(pth, arg, body) => {
116116
mac_invoc(fld.fold_path(pth),
117-
option::map(&arg, |x| fld.fold_expr(x)), body)
117+
option::map(&arg, |x| fld.fold_expr(*x)), body)
118118
}
119119
mac_invoc_tt(*) => m.node,
120120
mac_ellipsis => mac_ellipsis,
@@ -243,7 +243,7 @@ fn noop_fold_item_underscore(i: item_, fld: ast_fold) -> item_ {
243243
variants: vec::map(enum_definition.variants,
244244
|x| fld.fold_variant(*x)),
245245
common: option::map(&enum_definition.common,
246-
|x| fold_struct_def(x, fld))
246+
|x| fold_struct_def(*x, fld))
247247
}), fold_ty_params(typms, fld))
248248
}
249249
item_class(struct_def, typms) => {
@@ -252,7 +252,7 @@ fn noop_fold_item_underscore(i: item_, fld: ast_fold) -> item_ {
252252
}
253253
item_impl(tps, ifce, ty, methods) => {
254254
item_impl(fold_ty_params(tps, fld),
255-
ifce.map(|p| fold_trait_ref(p, fld)),
255+
ifce.map(|p| fold_trait_ref(*p, fld)),
256256
fld.fold_ty(ty),
257257
vec::map(methods, |x| fld.fold_method(*x)))
258258
}
@@ -292,7 +292,7 @@ fn fold_struct_def(struct_def: @ast::struct_def, fld: ast_fold)
292292
let dtor_id = fld.new_id(dtor.node.id);
293293
{node: {body: dtor_body,
294294
id: dtor_id,.. dtor.node},
295-
.. dtor}};
295+
.. *dtor}};
296296
return @{
297297
traits: vec::map(struct_def.traits, |p| fold_trait_ref(*p, fld)),
298298
fields: vec::map(struct_def.fields, |f| fold_struct_field(*f, fld)),
@@ -332,7 +332,7 @@ fn noop_fold_method(&&m: @method, fld: ast_fold) -> @method {
332332
fn noop_fold_block(b: blk_, fld: ast_fold) -> blk_ {
333333
return {view_items: vec::map(b.view_items, |x| fld.fold_view_item(*x)),
334334
stmts: vec::map(b.stmts, |x| fld.fold_stmt(*x)),
335-
expr: option::map(&b.expr, |x| fld.fold_expr(x)),
335+
expr: option::map(&b.expr, |x| fld.fold_expr(*x)),
336336
id: fld.new_id(b.id),
337337
rules: b.rules};
338338
}
@@ -347,7 +347,7 @@ fn noop_fold_stmt(s: stmt_, fld: ast_fold) -> stmt_ {
347347

348348
fn noop_fold_arm(a: arm, fld: ast_fold) -> arm {
349349
return {pats: vec::map(a.pats, |x| fld.fold_pat(*x)),
350-
guard: option::map(&a.guard, |x| fld.fold_expr(x)),
350+
guard: option::map(&a.guard, |x| fld.fold_expr(*x)),
351351
body: fld.fold_block(a.body)};
352352
}
353353

@@ -357,12 +357,12 @@ fn noop_fold_pat(p: pat_, fld: ast_fold) -> pat_ {
357357
pat_ident(binding_mode, pth, sub) => {
358358
pat_ident(binding_mode,
359359
fld.fold_path(pth),
360-
option::map(&sub, |x| fld.fold_pat(x)))
360+
option::map(&sub, |x| fld.fold_pat(*x)))
361361
}
362362
pat_lit(e) => pat_lit(fld.fold_expr(e)),
363363
pat_enum(pth, pats) => {
364364
pat_enum(fld.fold_path(pth), option::map(&pats,
365-
|pats| vec::map(pats, |x| fld.fold_pat(*x))))
365+
|pats| vec::map(*pats, |x| fld.fold_pat(*x))))
366366
}
367367
pat_rec(fields, etc) => {
368368
let mut fs = ~[];
@@ -432,7 +432,7 @@ fn noop_fold_expr(e: expr_, fld: ast_fold) -> expr_ {
432432
expr_repeat(fld.fold_expr(expr), fld.fold_expr(count), mutt),
433433
expr_rec(fields, maybe_expr) => {
434434
expr_rec(vec::map(fields, |x| fold_field(*x)),
435-
option::map(&maybe_expr, |x| fld.fold_expr(x)))
435+
option::map(&maybe_expr, |x| fld.fold_expr(*x)))
436436
}
437437
expr_tup(elts) => expr_tup(vec::map(elts, |x| fld.fold_expr(*x))),
438438
expr_call(f, args, blk) => {
@@ -451,14 +451,14 @@ fn noop_fold_expr(e: expr_, fld: ast_fold) -> expr_ {
451451
expr_addr_of(m, ohs) => expr_addr_of(m, fld.fold_expr(ohs)),
452452
expr_if(cond, tr, fl) => {
453453
expr_if(fld.fold_expr(cond), fld.fold_block(tr),
454-
option::map(&fl, |x| fld.fold_expr(x)))
454+
option::map(&fl, |x| fld.fold_expr(*x)))
455455
}
456456
expr_while(cond, body) => {
457457
expr_while(fld.fold_expr(cond), fld.fold_block(body))
458458
}
459459
expr_loop(body, opt_ident) => {
460460
expr_loop(fld.fold_block(body),
461-
option::map(&opt_ident, |x| fld.fold_ident(x)))
461+
option::map(&opt_ident, |x| fld.fold_ident(*x)))
462462
}
463463
expr_match(expr, arms) => {
464464
expr_match(fld.fold_expr(expr),
@@ -500,20 +500,20 @@ fn noop_fold_expr(e: expr_, fld: ast_fold) -> expr_ {
500500
expr_index(fld.fold_expr(el), fld.fold_expr(er))
501501
}
502502
expr_path(pth) => expr_path(fld.fold_path(pth)),
503-
expr_fail(e) => expr_fail(option::map(&e, |x| fld.fold_expr(x))),
503+
expr_fail(e) => expr_fail(option::map(&e, |x| fld.fold_expr(*x))),
504504
expr_break(opt_ident) =>
505-
expr_break(option::map(&opt_ident, |x| fld.fold_ident(x))),
505+
expr_break(option::map(&opt_ident, |x| fld.fold_ident(*x))),
506506
expr_again(opt_ident) =>
507-
expr_again(option::map(&opt_ident, |x| fld.fold_ident(x))),
508-
expr_ret(e) => expr_ret(option::map(&e, |x| fld.fold_expr(x))),
507+
expr_again(option::map(&opt_ident, |x| fld.fold_ident(*x))),
508+
expr_ret(e) => expr_ret(option::map(&e, |x| fld.fold_expr(*x))),
509509
expr_log(i, lv, e) => expr_log(i, fld.fold_expr(lv),
510510
fld.fold_expr(e)),
511511
expr_assert(e) => expr_assert(fld.fold_expr(e)),
512512
expr_mac(mac) => expr_mac(fold_mac(mac)),
513513
expr_struct(path, fields, maybe_expr) => {
514514
expr_struct(fld.fold_path(path),
515515
vec::map(fields, |x| fold_field(*x)),
516-
option::map(&maybe_expr, |x| fld.fold_expr(x)))
516+
option::map(&maybe_expr, |x| fld.fold_expr(*x)))
517517
}
518518
}
519519
}
@@ -577,7 +577,7 @@ fn noop_fold_variant(v: variant_, fld: ast_fold) -> variant_ {
577577
let dtor_id = fld.new_id(dtor.node.id);
578578
{node: {body: dtor_body,
579579
id: dtor_id,.. dtor.node},
580-
.. dtor}};
580+
.. *dtor}};
581581
kind = struct_variant_kind(@{
582582
traits: ~[],
583583
fields: vec::map(struct_def.fields,
@@ -593,7 +593,7 @@ fn noop_fold_variant(v: variant_, fld: ast_fold) -> variant_ {
593593
let variants = vec::map(enum_definition.variants,
594594
|x| fld.fold_variant(*x));
595595
let common = option::map(&enum_definition.common,
596-
|x| fold_struct_def(x, fld));
596+
|x| fold_struct_def(*x, fld));
597597
kind = enum_variant_kind(ast::enum_def({ variants: variants,
598598
common: common }));
599599
}

src/libsyntax/parse.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ fn parse_crate_from_crate_file(input: &Path, cfg: ast::crate_cfg,
7373
sess.chpos = rdr.chpos;
7474
sess.byte_pos = sess.byte_pos + rdr.pos;
7575
let cx = @{sess: sess, cfg: /* FIXME (#2543) */ copy p.cfg};
76-
let companionmod = input.filestem().map(|s| Path(s));
76+
let companionmod = input.filestem().map(|s| Path(*s));
7777
let (m, attrs) = eval::eval_crate_directives_to_mod(
7878
cx, cdirs, &prefix, &companionmod);
7979
let mut hi = p.span.hi;

src/libsyntax/parse/parser.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2758,7 +2758,7 @@ impl parser {
27582758
}
27592759

27602760
let actual_dtor = do the_dtor.map |dtor| {
2761-
let (d_body, d_attrs, d_s) = dtor;
2761+
let (d_body, d_attrs, d_s) = *dtor;
27622762
{node: {id: self.get_id(),
27632763
attrs: d_attrs,
27642764
self_id: self.get_id(),
@@ -3126,7 +3126,7 @@ impl parser {
31263126
}
31273127
self.bump();
31283128
let mut actual_dtor = do the_dtor.map |dtor| {
3129-
let (d_body, d_attrs, d_s) = dtor;
3129+
let (d_body, d_attrs, d_s) = *dtor;
31303130
{node: {id: self.get_id(),
31313131
attrs: d_attrs,
31323132
self_id: self.get_id(),

src/libsyntax/visit.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,7 @@ fn visit_exprs<E>(exprs: ~[@expr], e: E, v: vt<E>) {
395395
fn visit_mac<E>(m: mac, e: E, v: vt<E>) {
396396
match m.node {
397397
ast::mac_invoc(_, arg, _) => {
398-
option::map(&arg, |arg| v.visit_expr(arg, e, v)); }
398+
option::map(&arg, |arg| v.visit_expr(*arg, e, v)); }
399399
ast::mac_invoc_tt(*) => { /* no user-serviceable parts inside */ }
400400
ast::mac_ellipsis => (),
401401
ast::mac_aq(*) => { /* FIXME: maybe visit (Issue #2340) */ }

src/rustc/driver/driver.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -507,7 +507,7 @@ fn build_session_options(binary: ~str,
507507
let extra_debuginfo = opt_present(matches, ~"xg");
508508
let debuginfo = opt_present(matches, ~"g") || extra_debuginfo;
509509
let sysroot_opt = getopts::opt_maybe_str(matches, ~"sysroot");
510-
let sysroot_opt = sysroot_opt.map(|m| Path(m));
510+
let sysroot_opt = sysroot_opt.map(|m| Path(*m));
511511
let target_opt = getopts::opt_maybe_str(matches, ~"target");
512512
let save_temps = getopts::opt_present(matches, ~"save-temps");
513513
match output_type {

src/rustc/driver/rustc.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -172,14 +172,14 @@ fn run_compiler(args: ~[~str], demitter: diagnostic::emitter) {
172172
let sopts = build_session_options(binary, matches, demitter);
173173
let sess = build_session(sopts, demitter);
174174
let odir = getopts::opt_maybe_str(matches, ~"out-dir");
175-
let odir = odir.map(|o| Path(o));
175+
let odir = odir.map(|o| Path(*o));
176176
let ofile = getopts::opt_maybe_str(matches, ~"o");
177-
let ofile = ofile.map(|o| Path(o));
177+
let ofile = ofile.map(|o| Path(*o));
178178
let cfg = build_configuration(sess, binary, input);
179179
let pretty =
180180
option::map(&getopts::opt_default(matches, ~"pretty",
181181
~"normal"),
182-
|a| parse_pretty(sess, a) );
182+
|a| parse_pretty(sess, *a) );
183183
match pretty {
184184
Some::<pp_mode>(ppm) => {
185185
pretty_print_input(sess, cfg, input, ppm);

src/rustc/front/config.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ fn fold_block(cx: ctxt, b: ast::blk_, fld: fold::ast_fold) ->
104104
let filtered_stmts = vec::filter_map(b.stmts, filter);
105105
return {view_items: b.view_items,
106106
stmts: vec::map(filtered_stmts, |x| fld.fold_stmt(*x)),
107-
expr: option::map(&b.expr, |x| fld.fold_expr(x)),
107+
expr: option::map(&b.expr, |x| fld.fold_expr(*x)),
108108
id: b.id,
109109
rules: b.rules};
110110
}

src/rustc/metadata/cstore.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ fn get_dep_hashes(cstore: cstore) -> ~[~str] {
177177

178178
fn get_path(cstore: cstore, d: ast::def_id) -> ~[~str] {
179179
option::map_default(&p(cstore).mod_path_map.find(d), ~[],
180-
|ds| str::split_str(*ds, ~"::"))
180+
|ds| str::split_str(**ds, ~"::"))
181181
}
182182
// Local Variables:
183183
// mode: rust

0 commit comments

Comments
 (0)