Skip to content

Commit 9d274ec

Browse files
committed
Re-rename option functions
get_with_default (nee from_maybe) => get_default with_option (nee maybe) => map_default with_option_do (nee may) => iter As per discussion of 21be137
1 parent fc202ca commit 9d274ec

28 files changed

+58
-58
lines changed

doc/tutorial.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1538,7 +1538,7 @@ programs that just can't be typed.
15381538

15391539
~~~~
15401540
let n = option::none;
1541-
# option::with_option_do(n, fn&(&&x:int) {})
1541+
# option::iter(n, fn&(&&x:int) {})
15421542
~~~~
15431543

15441544
If you never do anything else with `n`, the compiler will not be able

src/compiletest/header.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ fn load_props(testfile: str) -> test_props {
4040
pp_exact = parse_pp_exact(ln, testfile);
4141
}
4242

43-
option::with_option_do(parse_aux_build(ln)) {|ab|
43+
option::iter(parse_aux_build(ln)) {|ab|
4444
aux_builds += [ab];
4545
}
4646
};

src/libcore/iter.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ impl<A> of iterable<A> for [A] {
2929

3030
impl<A> of iterable<A> for option<A> {
3131
fn iter(blk: fn(A)) {
32-
option::with_option_do(self, blk)
32+
option::iter(self, blk)
3333
}
3434
}
3535

src/libcore/option.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,13 @@ pure fn get_or_default<T: copy>(opt: option<T>, def: T) -> T {
5858
alt opt { some(x) { x } none { def } }
5959
}
6060

61-
fn with_option<T, U: copy>(opt: option<T>, def: U, f: fn(T) -> U) -> U {
61+
fn map_default<T, U: copy>(opt: option<T>, def: U, f: fn(T) -> U) -> U {
6262
#[doc = "Applies a function to the contained value or returns a default"];
6363

6464
alt opt { none { def } some(t) { f(t) } }
6565
}
6666

67-
fn with_option_do<T>(opt: option<T>, f: fn(T)) {
67+
fn iter<T>(opt: option<T>, f: fn(T)) {
6868
#[doc = "Performs an operation on the contained value or does nothing"];
6969

7070
alt opt { none { } some(t) { f(t); } }
@@ -96,10 +96,10 @@ impl extensions<T:copy> for option<T> {
9696
#[doc = "Returns the contained value or a default"]
9797
fn get_or_default(def: T) -> T { get_or_default(self, def) }
9898
#[doc = "Applies a function to the contained value or returns a default"]
99-
fn with_option<U: copy>(def: U, f: fn(T) -> U) -> U
100-
{ with_option(self, def, f) }
99+
fn map_default<U: copy>(def: U, f: fn(T) -> U) -> U
100+
{ map_default(self, def, f) }
101101
#[doc = "Performs an operation on the contained value or does nothing"]
102-
fn with_option_do(f: fn(T)) { with_option_do(self, f) }
102+
fn iter(f: fn(T)) { iter(self, f) }
103103
#[doc = "
104104
Gets the value out of an option
105105

src/libcore/os.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -767,7 +767,7 @@ mod tests {
767767
setenv("HOME", "");
768768
assert os::homedir() == none;
769769

770-
option::with_option_do(oldhome, {|s| setenv("HOME", s)});
770+
option::iter(oldhome, {|s| setenv("HOME", s)});
771771
}
772772

773773
#[test]
@@ -797,8 +797,8 @@ mod tests {
797797
setenv("USERPROFILE", "/home/PaloAlto");
798798
assert os::homedir() == some("/home/MountainView");
799799

800-
option::with_option_do(oldhome, {|s| setenv("HOME", s)});
801-
option::with_option_do(olduserprofile,
800+
option::iter(oldhome, {|s| setenv("HOME", s)});
801+
option::iter(olduserprofile,
802802
{|s| setenv("USERPROFILE", s)});
803803
}
804804

src/libcore/task.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,7 @@ fn spawn_raw(opts: task_opts, +f: fn~()) unsafe {
505505
}
506506
};
507507

508-
option::with_option_do(opts.notify_chan) {|c|
508+
option::iter(opts.notify_chan) {|c|
509509
// FIXME (1087): Would like to do notification in Rust
510510
rustrt::rust_task_config_notify(new_task, c);
511511
}

src/librustsyntax/diagnostic.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -243,8 +243,8 @@ fn highlight_lines(cm: codemap::codemap, sp: span,
243243
}
244244

245245
fn print_macro_backtrace(cm: codemap::codemap, sp: span) {
246-
option::with_option_do (sp.expn_info) {|ei|
247-
let ss = option::with_option(ei.callie.span, "",
246+
option::iter (sp.expn_info) {|ei|
247+
let ss = option::map_default(ei.callie.span, "",
248248
bind codemap::span_to_str(_, cm));
249249
print_diagnostic(ss, note,
250250
#fmt("in expansion of #%s", ei.callie.name));

src/librustsyntax/ext/qquote.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ fn expand_ast(ecx: ext_ctxt, _sp: span,
135135
-> @ast::expr
136136
{
137137
let mut what = "expr";
138-
option::with_option_do(arg) {|arg|
138+
option::iter(arg) {|arg|
139139
let args: [@ast::expr] =
140140
alt arg.node {
141141
ast::expr_vec(elts, _) { elts }

src/librustsyntax/print/pprust.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -793,7 +793,7 @@ fn print_mac(s: ps, m: ast::mac) {
793793
some(@{node: ast::expr_vec(_, _), _}) { }
794794
_ { word(s.s, " "); }
795795
}
796-
option::with_option_do(arg, bind print_expr(s, _));
796+
option::iter(arg, bind print_expr(s, _));
797797
// FIXME: extension 'body'
798798
}
799799
ast::mac_embed_type(ty) {

src/librustsyntax/visit.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ fn visit_pat<E>(p: @pat, e: E, v: vt<E>) {
225225
}
226226
pat_ident(path, inner) {
227227
visit_path(path, e, v);
228-
option::with_option_do(inner, {|subpat| v.visit_pat(subpat, e, v)});
228+
option::iter(inner, {|subpat| v.visit_pat(subpat, e, v)});
229229
}
230230
pat_lit(ex) { v.visit_expr(ex, e, v); }
231231
pat_range(e1, e2) { v.visit_expr(e1, e, v); v.visit_expr(e2, e, v); }

src/rustc/metadata/astencode.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -692,15 +692,15 @@ fn encode_side_tables_for_id(ecx: @e::encode_ctxt,
692692

693693
#debug["Encoding side tables for id %d", id];
694694

695-
option::with_option_do(tcx.def_map.find(id)) {|def|
695+
option::iter(tcx.def_map.find(id)) {|def|
696696
ebml_w.tag(c::tag_table_def) {||
697697
ebml_w.id(id);
698698
ebml_w.tag(c::tag_table_val) {||
699699
ast::serialize_def(ebml_w, def)
700700
}
701701
}
702702
}
703-
option::with_option_do((*tcx.node_types).find(id as uint)) {|ty|
703+
option::iter((*tcx.node_types).find(id as uint)) {|ty|
704704
ebml_w.tag(c::tag_table_node_type) {||
705705
ebml_w.id(id);
706706
ebml_w.tag(c::tag_table_val) {||
@@ -709,7 +709,7 @@ fn encode_side_tables_for_id(ecx: @e::encode_ctxt,
709709
}
710710
}
711711

712-
option::with_option_do(tcx.node_type_substs.find(id)) {|tys|
712+
option::iter(tcx.node_type_substs.find(id)) {|tys|
713713
ebml_w.tag(c::tag_table_node_type_subst) {||
714714
ebml_w.id(id);
715715
ebml_w.tag(c::tag_table_val) {||
@@ -718,7 +718,7 @@ fn encode_side_tables_for_id(ecx: @e::encode_ctxt,
718718
}
719719
}
720720

721-
option::with_option_do(tcx.freevars.find(id)) {|fv|
721+
option::iter(tcx.freevars.find(id)) {|fv|
722722
ebml_w.tag(c::tag_table_freevars) {||
723723
ebml_w.id(id);
724724
ebml_w.tag(c::tag_table_val) {||
@@ -730,7 +730,7 @@ fn encode_side_tables_for_id(ecx: @e::encode_ctxt,
730730
}
731731

732732
let lid = {crate: ast::local_crate, node: id};
733-
option::with_option_do(tcx.tcache.find(lid)) {|tpbt|
733+
option::iter(tcx.tcache.find(lid)) {|tpbt|
734734
ebml_w.tag(c::tag_table_tcache) {||
735735
ebml_w.id(id);
736736
ebml_w.tag(c::tag_table_val) {||
@@ -739,7 +739,7 @@ fn encode_side_tables_for_id(ecx: @e::encode_ctxt,
739739
}
740740
}
741741

742-
option::with_option_do(tcx.ty_param_bounds.find(id)) {|pbs|
742+
option::iter(tcx.ty_param_bounds.find(id)) {|pbs|
743743
ebml_w.tag(c::tag_table_param_bounds) {||
744744
ebml_w.id(id);
745745
ebml_w.tag(c::tag_table_val) {||
@@ -753,7 +753,7 @@ fn encode_side_tables_for_id(ecx: @e::encode_ctxt,
753753
// is what we actually use in trans, all modes will have been
754754
// resolved.
755755
//
756-
//option::with_option_do(tcx.inferred_modes.find(id)) {|m|
756+
//option::iter(tcx.inferred_modes.find(id)) {|m|
757757
// ebml_w.tag(c::tag_table_inferred_modes) {||
758758
// ebml_w.id(id);
759759
// ebml_w.tag(c::tag_table_val) {||
@@ -762,25 +762,25 @@ fn encode_side_tables_for_id(ecx: @e::encode_ctxt,
762762
// }
763763
//}
764764

765-
option::with_option_do(ccx.maps.mutbl_map.find(id)) {|_m|
765+
option::iter(ccx.maps.mutbl_map.find(id)) {|_m|
766766
ebml_w.tag(c::tag_table_mutbl) {||
767767
ebml_w.id(id);
768768
}
769769
}
770770

771-
option::with_option_do(ccx.maps.copy_map.find(id)) {|_m|
771+
option::iter(ccx.maps.copy_map.find(id)) {|_m|
772772
ebml_w.tag(c::tag_table_copy) {||
773773
ebml_w.id(id);
774774
}
775775
}
776776

777-
option::with_option_do(ccx.maps.spill_map.find(id)) {|_m|
777+
option::iter(ccx.maps.spill_map.find(id)) {|_m|
778778
ebml_w.tag(c::tag_table_spill) {||
779779
ebml_w.id(id);
780780
}
781781
}
782782

783-
option::with_option_do(ccx.maps.last_uses.find(id)) {|m|
783+
option::iter(ccx.maps.last_uses.find(id)) {|m|
784784
ebml_w.tag(c::tag_table_last_use) {||
785785
ebml_w.id(id);
786786
ebml_w.tag(c::tag_table_val) {||
@@ -792,7 +792,7 @@ fn encode_side_tables_for_id(ecx: @e::encode_ctxt,
792792
// impl_map is not used except when emitting metadata,
793793
// don't need to keep it.
794794

795-
option::with_option_do(ccx.maps.method_map.find(id)) {|mo|
795+
option::iter(ccx.maps.method_map.find(id)) {|mo|
796796
ebml_w.tag(c::tag_table_method_map) {||
797797
ebml_w.id(id);
798798
ebml_w.tag(c::tag_table_val) {||
@@ -801,7 +801,7 @@ fn encode_side_tables_for_id(ecx: @e::encode_ctxt,
801801
}
802802
}
803803

804-
option::with_option_do(ccx.maps.vtable_map.find(id)) {|dr|
804+
option::iter(ccx.maps.vtable_map.find(id)) {|dr|
805805
ebml_w.tag(c::tag_table_vtable_map) {||
806806
ebml_w.id(id);
807807
ebml_w.tag(c::tag_table_val) {||

src/rustc/metadata/cstore.rs

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

164164
fn get_path(cstore: cstore, d: ast::def_id) -> [str] {
165165
// let f = bind str::split_str(_, "::");
166-
option::with_option(p(cstore).mod_path_map.find(d), [],
166+
option::map_default(p(cstore).mod_path_map.find(d), [],
167167
{|ds| str::split_str(ds, "::")})
168168
}
169169
// Local Variables:

src/rustc/metadata/decoder.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ fn class_member_id(d: ebml::doc, cdata: cmd) -> ast::def_id {
120120

121121
fn field_mutability(d: ebml::doc) -> ast::class_mutability {
122122
// Use maybe_get_doc in case it's a method
123-
option::with_option(ebml::maybe_get_doc(d, tag_class_mut),
123+
option::map_default(ebml::maybe_get_doc(d, tag_class_mut),
124124
ast::class_immutable,
125125
{|d|
126126
alt ebml::doc_as_u8(d) as char {

src/rustc/middle/check_const.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ fn check_item(sess: session, ast_map: ast_map::map, def_map: resolve::def_map,
2424
}
2525
item_enum(vs, _) {
2626
for vs.each {|var|
27-
option::with_option_do(var.node.disr_expr) {|ex|
27+
option::iter(var.node.disr_expr) {|ex|
2828
v.visit_expr(ex, true, v);
2929
}
3030
}

src/rustc/middle/kind.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ fn check_expr(e: @expr, cx: ctx, v: visit::vt<ctx>) {
183183
}
184184
}
185185
expr_path(_) | expr_field(_, _, _) {
186-
option::with_option_do(cx.tcx.node_type_substs.find(e.id)) {|ts|
186+
option::iter(cx.tcx.node_type_substs.find(e.id)) {|ts|
187187
let bounds = alt check e.node {
188188
expr_path(_) {
189189
let did = ast_util::def_id_of_def(cx.tcx.def_map.get(e.id));
@@ -251,7 +251,7 @@ fn check_stmt(stmt: @stmt, cx: ctx, v: visit::vt<ctx>) {
251251
fn check_ty(aty: @ty, cx: ctx, v: visit::vt<ctx>) {
252252
alt aty.node {
253253
ty_path(_, id) {
254-
option::with_option_do(cx.tcx.node_type_substs.find(id)) {|ts|
254+
option::iter(cx.tcx.node_type_substs.find(id)) {|ts|
255255
let did = ast_util::def_id_of_def(cx.tcx.def_map.get(id));
256256
let bounds = ty::lookup_item_type(cx.tcx, did).bounds;
257257
vec::iter2(ts, *bounds) {|ty, bound|

src/rustc/middle/last_use.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ fn visit_expr(ex: @expr, cx: ctx, v: visit::vt<ctx>) {
133133
clear_in_current(cx, root_id, false);
134134
}
135135
_ {
136-
option::with_option_do(def_is_owned_local(cx, my_def)) {|nid|
136+
option::iter(def_is_owned_local(cx, my_def)) {|nid|
137137
clear_in_current(cx, nid, false);
138138
cx.current += [{def: nid,
139139
uses: cons(var_use(ex.id), @nil)}];
@@ -188,7 +188,7 @@ fn visit_expr(ex: @expr, cx: ctx, v: visit::vt<ctx>) {
188188
alt ty::arg_mode(cx.tcx, arg_t) {
189189
by_ref | by_val | by_mutbl_ref {
190190
let def = cx.def_map.get(arg.id);
191-
option::with_option_do(def_is_owned_local(cx, def)) {|id|
191+
option::iter(def_is_owned_local(cx, def)) {|id|
192192
clear_in_current(cx, id, false);
193193
cx.spill_map.insert(id, ());
194194
}
@@ -243,7 +243,7 @@ fn visit_fn(fk: visit::fn_kind, decl: fn_decl, body: blk,
243243
alt cx.tcx.freevars.find(id) {
244244
some(vars) {
245245
for vec::each(*vars) {|v|
246-
option::with_option_do(def_is_owned_local(cx, v.def)) {|nid|
246+
option::iter(def_is_owned_local(cx, v.def)) {|nid|
247247
clear_in_current(cx, nid, false);
248248
cx.current += [{def: nid,
249249
uses: cons(close_over(id), @nil)}];

src/rustc/middle/resolve.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1928,7 +1928,7 @@ fn check_exports(e: @env) {
19281928

19291929

19301930
fn maybe_add_reexport(e: @env, export_id: node_id, def: option<def>) {
1931-
option::with_option_do(def) {|def|
1931+
option::iter(def) {|def|
19321932
add_export(e, export_id, def_id_of_def(def), true);
19331933
}
19341934
}
@@ -2110,7 +2110,7 @@ fn find_impls_in_view_item(e: env, vi: @ast::view_item,
21102110
ast::view_path_simple(name, pt, id) {
21112111
let mut found = [];
21122112
if vec::len(*pt) == 1u {
2113-
option::with_option_do(sc) {|sc|
2113+
option::iter(sc) {|sc|
21142114
list::iter(sc) {|level|
21152115
if vec::len(found) == 0u {
21162116
for vec::each(*level) {|imp|

src/rustc/middle/trans/base.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1657,7 +1657,7 @@ fn trans_if(cx: block, cond: @ast::expr, thn: ast::blk,
16571657
let then_cx = scope_block(bcx, "then");
16581658
then_cx.block_span = some(thn.span);
16591659
let else_cx = scope_block(bcx, "else");
1660-
option::with_option_do(els) {|e| else_cx.block_span = some(e.span); }
1660+
option::iter(els) {|e| else_cx.block_span = some(e.span); }
16611661
CondBr(bcx, cond_val, then_cx.llbb, else_cx.llbb);
16621662
let then_bcx = trans_block(then_cx, thn, then_dest);
16631663
let then_bcx = trans_block_cleanups(then_bcx, then_cx);
@@ -2717,7 +2717,7 @@ fn trans_call_inner(in_cx: block, fn_expr_ty: ty::t, ret_ty: ty::t,
27172717
Unreachable(bcx);
27182718
} else if ret_in_loop {
27192719
bcx = with_cond(bcx, Load(bcx, option::get(ret_flag))) {|bcx|
2720-
option::with_option_do(bcx.fcx.loop_ret) {|lret|
2720+
option::iter(bcx.fcx.loop_ret) {|lret|
27212721
Store(bcx, C_bool(true), lret.flagptr);
27222722
Store(bcx, C_bool(false), bcx.fcx.llretptr);
27232723
}
@@ -3674,7 +3674,7 @@ fn cleanup_and_leave(bcx: block, upto: option<BasicBlockRef>,
36743674
loop {
36753675
alt cur.kind {
36763676
block_scope(info) if info.cleanups.len() > 0u {
3677-
option::with_option_do(vec::find(info.cleanup_paths,
3677+
option::iter(vec::find(info.cleanup_paths,
36783678
{|cp| cp.target == leave})) {|cp|
36793679
Br(bcx, cp.dest);
36803680
done = true;
@@ -3786,7 +3786,7 @@ fn alloc_local(cx: block, local: @ast::local) -> block {
37863786
}
37873787
let val = alloc_ty(cx, t);
37883788
if cx.sess().opts.debuginfo {
3789-
option::with_option_do(simple_name) {|name|
3789+
option::iter(simple_name) {|name|
37903790
str::as_c_str(name, {|buf|
37913791
llvm::LLVMSetValueName(val, buf)
37923792
});

src/rustc/middle/trans/closure.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ fn build_closure(bcx0: block,
325325
}
326326
}
327327
}
328-
option::with_option_do(include_ret_handle) {|flagptr|
328+
option::iter(include_ret_handle) {|flagptr|
329329
let our_ret = alt bcx.fcx.loop_ret {
330330
some({retptr, _}) { retptr }
331331
none { bcx.fcx.llretptr }

src/rustc/middle/trans/common.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ fn add_clean_free(cx: block, ptr: ValueRef, shared: bool) {
280280
// drop glue checks whether it is zero.
281281
fn revoke_clean(cx: block, val: ValueRef) {
282282
in_scope_cx(cx) {|info|
283-
option::with_option_do(vec::position(info.cleanups, {|cu|
283+
option::iter(vec::position(info.cleanups, {|cu|
284284
alt cu { clean_temp(v, _, _) if v == val { true } _ { false } }
285285
})) {|i|
286286
info.cleanups =
@@ -836,7 +836,7 @@ fn hash_mono_id(&&mi: mono_id) -> uint {
836836
h = h * alt param {
837837
mono_precise(ty, vts) {
838838
let mut h = ty::type_id(ty);
839-
option::with_option_do(vts) {|vts|
839+
option::iter(vts) {|vts|
840840
for vec::each(vts) {|vt| h += hash_mono_id(vt); }
841841
}
842842
h

src/rustc/middle/trans/reachable.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ fn traverse_exports(cx: ctx, vis: [@view_item]) -> bool {
5151
}
5252

5353
fn traverse_export(cx: ctx, exp_id: node_id) {
54-
option::with_option_do(cx.exp_map.find(exp_id)) {|defs|
54+
option::iter(cx.exp_map.find(exp_id)) {|defs|
5555
for vec::each(defs) {|def| traverse_def_id(cx, def.id); }
5656
}
5757
}

0 commit comments

Comments
 (0)