From 21be1379d561b6679a8a2ea47dce88f948c5acca Mon Sep 17 00:00:00 2001 From: Tim Chevalier Date: Mon, 2 Apr 2012 15:34:49 -0700 Subject: [PATCH] Rename some core::option functions from_maybe => get_with_default maybe => with_option may => with_option_do I know these names are kind of ridiculous, but it's the best I could think of. Feel free to bikeshed. Closes #2081 --- doc/tutorial.md | 2 +- src/compiletest/header.rs | 2 +- src/libcore/iter.rs | 2 +- src/libcore/option.rs | 13 +++++----- src/libcore/os.rs | 7 ++--- src/libcore/result.rs | 7 +++-- src/libcore/task.rs | 2 +- src/librustsyntax/diagnostic.rs | 4 +-- src/librustsyntax/ext/qquote.rs | 2 +- src/librustsyntax/parse/eval.rs | 2 +- src/librustsyntax/print/pprust.rs | 2 +- src/librustsyntax/visit.rs | 2 +- src/rustc/metadata/astencode.rs | 26 +++++++++---------- src/rustc/metadata/cstore.rs | 2 +- src/rustc/metadata/decoder.rs | 2 +- src/rustc/middle/check_const.rs | 2 +- src/rustc/middle/kind.rs | 4 +-- src/rustc/middle/last_use.rs | 6 ++--- src/rustc/middle/resolve.rs | 4 +-- src/rustc/middle/trans/base.rs | 6 ++--- src/rustc/middle/trans/closure.rs | 2 +- src/rustc/middle/trans/common.rs | 2 +- src/rustc/middle/trans/reachable.rs | 2 +- src/rustc/middle/trans/type_use.rs | 4 +-- .../middle/tstate/pre_post_conditions.rs | 2 +- src/rustc/middle/tstate/states.rs | 4 +-- src/rustc/middle/ty.rs | 2 +- src/rustc/middle/typeck.rs | 2 +- src/rustdoc/attr_pass.rs | 2 +- src/rustdoc/config.rs | 8 +++--- src/rustdoc/reexport_pass.rs | 2 +- 31 files changed, 67 insertions(+), 64 deletions(-) diff --git a/doc/tutorial.md b/doc/tutorial.md index 4849a37231b..66f3070de6c 100644 --- a/doc/tutorial.md +++ b/doc/tutorial.md @@ -1551,7 +1551,7 @@ programs that just can't be typed. ~~~~ let n = option::none; -# option::may(n, fn&(&&x:int) {}) +# option::with_option_do(n, fn&(&&x:int) {}) ~~~~ If you never do anything else with `n`, the compiler will not be able diff --git a/src/compiletest/header.rs b/src/compiletest/header.rs index 04abf75894e..004fa08960f 100644 --- a/src/compiletest/header.rs +++ b/src/compiletest/header.rs @@ -40,7 +40,7 @@ fn load_props(testfile: str) -> test_props { pp_exact = parse_pp_exact(ln, testfile); } - option::may(parse_aux_build(ln)) {|ab| + option::with_option_do(parse_aux_build(ln)) {|ab| aux_builds += [ab]; } }; diff --git a/src/libcore/iter.rs b/src/libcore/iter.rs index e5cb78c38d4..9e8abefb4a0 100644 --- a/src/libcore/iter.rs +++ b/src/libcore/iter.rs @@ -29,7 +29,7 @@ impl of iterable for [A] { impl of iterable for option { fn iter(blk: fn(A)) { - option::may(self, blk) + option::with_option_do(self, blk) } } diff --git a/src/libcore/option.rs b/src/libcore/option.rs index d89593f14c4..daf9a229354 100644 --- a/src/libcore/option.rs +++ b/src/libcore/option.rs @@ -52,19 +52,19 @@ pure fn is_some(opt: option) -> bool { !is_none(opt) } -pure fn from_maybe(opt: option, def: T) -> T { +pure fn get_or_default(opt: option, def: T) -> T { #[doc = "Returns the contained value or a default"]; alt opt { some(x) { x } none { def } } } -fn maybe(opt: option, def: U, f: fn(T) -> U) -> U { +fn with_option(opt: option, def: U, f: fn(T) -> U) -> U { #[doc = "Applies a function to the contained value or returns a default"]; alt opt { none { def } some(t) { f(t) } } } -fn may(opt: option, f: fn(T)) { +fn with_option_do(opt: option, f: fn(T)) { #[doc = "Performs an operation on the contained value or does nothing"]; alt opt { none { } some(t) { f(t); } } @@ -94,11 +94,12 @@ impl extensions for option { "] fn chain(f: fn(T) -> option) -> option { chain(self, f) } #[doc = "Returns the contained value or a default"] - fn from_maybe(def: T) -> T { from_maybe(self, def) } + fn get_or_default(def: T) -> T { get_or_default(self, def) } #[doc = "Applies a function to the contained value or returns a default"] - fn maybe(def: U, f: fn(T) -> U) -> U { maybe(self, def, f) } + fn with_option(def: U, f: fn(T) -> U) -> U + { with_option(self, def, f) } #[doc = "Performs an operation on the contained value or does nothing"] - fn may(f: fn(T)) { may(self, f) } + fn with_option_do(f: fn(T)) { with_option_do(self, f) } #[doc = " Gets the value out of an option diff --git a/src/libcore/os.rs b/src/libcore/os.rs index 16a5b0f36f2..3e7b2dba943 100644 --- a/src/libcore/os.rs +++ b/src/libcore/os.rs @@ -702,7 +702,7 @@ mod tests { setenv("HOME", ""); assert os::homedir() == none; - option::may(oldhome, {|s| setenv("HOME", s)}); + option::with_option_do(oldhome, {|s| setenv("HOME", s)}); } #[test] @@ -732,8 +732,9 @@ mod tests { setenv("USERPROFILE", "/home/PaloAlto"); assert os::homedir() == some("/home/MountainView"); - option::may(oldhome, {|s| setenv("HOME", s)}); - option::may(olduserprofile, {|s| setenv("USERPROFILE", s)}); + option::with_option_do(oldhome, {|s| setenv("HOME", s)}); + option::with_option_do(olduserprofile, + {|s| setenv("USERPROFILE", s)}); } // Issue #712 diff --git a/src/libcore/result.rs b/src/libcore/result.rs index a3f7cc3a4d8..3957bd31a10 100644 --- a/src/libcore/result.rs +++ b/src/libcore/result.rs @@ -20,10 +20,9 @@ If the result is an error pure fn get(res: result) -> T { alt res { ok(t) { t } - err(_) { - // FIXME: Serialize the error value - // and include it in the fail message (maybe just note it) - fail "get called on error result"; + err(the_err) { + // FIXME: have a run-fail test for this + unchecked{ fail #fmt("get called on error result: %?", the_err); } } } } diff --git a/src/libcore/task.rs b/src/libcore/task.rs index dcd784fb2a3..dc2dd5d179e 100644 --- a/src/libcore/task.rs +++ b/src/libcore/task.rs @@ -498,7 +498,7 @@ fn spawn_raw(opts: task_opts, +f: fn~()) unsafe { } }; - option::may(opts.notify_chan) {|c| + option::with_option_do(opts.notify_chan) {|c| // FIXME (1087): Would like to do notification in Rust rustrt::rust_task_config_notify(new_task, c); } diff --git a/src/librustsyntax/diagnostic.rs b/src/librustsyntax/diagnostic.rs index c4eac5477f4..e29c11cbb11 100644 --- a/src/librustsyntax/diagnostic.rs +++ b/src/librustsyntax/diagnostic.rs @@ -243,8 +243,8 @@ fn highlight_lines(cm: codemap::codemap, sp: span, } fn print_macro_backtrace(cm: codemap::codemap, sp: span) { - option::may (sp.expn_info) {|ei| - let ss = option::maybe(ei.callie.span, "", + option::with_option_do (sp.expn_info) {|ei| + let ss = option::with_option(ei.callie.span, "", bind codemap::span_to_str(_, cm)); print_diagnostic(ss, note, #fmt("in expansion of #%s", ei.callie.name)); diff --git a/src/librustsyntax/ext/qquote.rs b/src/librustsyntax/ext/qquote.rs index a8294f9bae0..b38dbccd7b1 100644 --- a/src/librustsyntax/ext/qquote.rs +++ b/src/librustsyntax/ext/qquote.rs @@ -135,7 +135,7 @@ fn expand_ast(ecx: ext_ctxt, _sp: span, -> @ast::expr { let mut what = "expr"; - option::may(arg) {|arg| + option::with_option_do(arg) {|arg| let args: [@ast::expr] = alt arg.node { ast::expr_vec(elts, _) { elts } diff --git a/src/librustsyntax/parse/eval.rs b/src/librustsyntax/parse/eval.rs index 42187ad9c7c..a9e0ce9845e 100644 --- a/src/librustsyntax/parse/eval.rs +++ b/src/librustsyntax/parse/eval.rs @@ -23,7 +23,7 @@ fn eval_crate_directives_to_mod(cx: ctx, cdirs: [@ast::crate_directive], -> (ast::_mod, [ast::attribute]) { #debug("eval crate prefix: %s", prefix); #debug("eval crate suffix: %s", - option::from_maybe(suffix, "none")); + option::get_or_default(suffix, "none")); let (cview_items, citems, cattrs) = parse_companion_mod(cx, prefix, suffix); let mut view_items: [@ast::view_item] = []; diff --git a/src/librustsyntax/print/pprust.rs b/src/librustsyntax/print/pprust.rs index 1a4780f78ae..6f53344926b 100644 --- a/src/librustsyntax/print/pprust.rs +++ b/src/librustsyntax/print/pprust.rs @@ -792,7 +792,7 @@ fn print_mac(s: ps, m: ast::mac) { some(@{node: ast::expr_vec(_, _), _}) { } _ { word(s.s, " "); } } - option::may(arg, bind print_expr(s, _)); + option::with_option_do(arg, bind print_expr(s, _)); // FIXME: extension 'body' } ast::mac_embed_type(ty) { diff --git a/src/librustsyntax/visit.rs b/src/librustsyntax/visit.rs index a27293ea19e..c4e5da66743 100644 --- a/src/librustsyntax/visit.rs +++ b/src/librustsyntax/visit.rs @@ -225,7 +225,7 @@ fn visit_pat(p: @pat, e: E, v: vt) { } pat_ident(path, inner) { visit_path(path, e, v); - option::may(inner, {|subpat| v.visit_pat(subpat, e, v)}); + option::with_option_do(inner, {|subpat| v.visit_pat(subpat, e, v)}); } pat_lit(ex) { v.visit_expr(ex, e, v); } pat_range(e1, e2) { v.visit_expr(e1, e, v); v.visit_expr(e2, e, v); } diff --git a/src/rustc/metadata/astencode.rs b/src/rustc/metadata/astencode.rs index 5d7802e08c0..8bc96a45ed6 100644 --- a/src/rustc/metadata/astencode.rs +++ b/src/rustc/metadata/astencode.rs @@ -692,7 +692,7 @@ fn encode_side_tables_for_id(ecx: @e::encode_ctxt, #debug["Encoding side tables for id %d", id]; - option::may(tcx.def_map.find(id)) {|def| + option::with_option_do(tcx.def_map.find(id)) {|def| ebml_w.tag(c::tag_table_def) {|| ebml_w.id(id); ebml_w.tag(c::tag_table_val) {|| @@ -700,7 +700,7 @@ fn encode_side_tables_for_id(ecx: @e::encode_ctxt, } } } - option::may((*tcx.node_types).find(id as uint)) {|ty| + option::with_option_do((*tcx.node_types).find(id as uint)) {|ty| ebml_w.tag(c::tag_table_node_type) {|| ebml_w.id(id); ebml_w.tag(c::tag_table_val) {|| @@ -709,7 +709,7 @@ fn encode_side_tables_for_id(ecx: @e::encode_ctxt, } } - option::may(tcx.node_type_substs.find(id)) {|tys| + option::with_option_do(tcx.node_type_substs.find(id)) {|tys| ebml_w.tag(c::tag_table_node_type_subst) {|| ebml_w.id(id); ebml_w.tag(c::tag_table_val) {|| @@ -718,7 +718,7 @@ fn encode_side_tables_for_id(ecx: @e::encode_ctxt, } } - option::may(tcx.freevars.find(id)) {|fv| + option::with_option_do(tcx.freevars.find(id)) {|fv| ebml_w.tag(c::tag_table_freevars) {|| ebml_w.id(id); ebml_w.tag(c::tag_table_val) {|| @@ -730,7 +730,7 @@ fn encode_side_tables_for_id(ecx: @e::encode_ctxt, } let lid = {crate: ast::local_crate, node: id}; - option::may(tcx.tcache.find(lid)) {|tpbt| + option::with_option_do(tcx.tcache.find(lid)) {|tpbt| ebml_w.tag(c::tag_table_tcache) {|| ebml_w.id(id); ebml_w.tag(c::tag_table_val) {|| @@ -739,7 +739,7 @@ fn encode_side_tables_for_id(ecx: @e::encode_ctxt, } } - option::may(tcx.ty_param_bounds.find(id)) {|pbs| + option::with_option_do(tcx.ty_param_bounds.find(id)) {|pbs| ebml_w.tag(c::tag_table_param_bounds) {|| ebml_w.id(id); ebml_w.tag(c::tag_table_val) {|| @@ -753,7 +753,7 @@ fn encode_side_tables_for_id(ecx: @e::encode_ctxt, // is what we actually use in trans, all modes will have been // resolved. // - //option::may(tcx.inferred_modes.find(id)) {|m| + //option::with_option_do(tcx.inferred_modes.find(id)) {|m| // ebml_w.tag(c::tag_table_inferred_modes) {|| // ebml_w.id(id); // ebml_w.tag(c::tag_table_val) {|| @@ -762,25 +762,25 @@ fn encode_side_tables_for_id(ecx: @e::encode_ctxt, // } //} - option::may(ccx.maps.mutbl_map.find(id)) {|_m| + option::with_option_do(ccx.maps.mutbl_map.find(id)) {|_m| ebml_w.tag(c::tag_table_mutbl) {|| ebml_w.id(id); } } - option::may(ccx.maps.copy_map.find(id)) {|_m| + option::with_option_do(ccx.maps.copy_map.find(id)) {|_m| ebml_w.tag(c::tag_table_copy) {|| ebml_w.id(id); } } - option::may(ccx.maps.spill_map.find(id)) {|_m| + option::with_option_do(ccx.maps.spill_map.find(id)) {|_m| ebml_w.tag(c::tag_table_spill) {|| ebml_w.id(id); } } - option::may(ccx.maps.last_uses.find(id)) {|m| + option::with_option_do(ccx.maps.last_uses.find(id)) {|m| ebml_w.tag(c::tag_table_last_use) {|| ebml_w.id(id); ebml_w.tag(c::tag_table_val) {|| @@ -792,7 +792,7 @@ fn encode_side_tables_for_id(ecx: @e::encode_ctxt, // impl_map is not used except when emitting metadata, // don't need to keep it. - option::may(ccx.maps.method_map.find(id)) {|mo| + option::with_option_do(ccx.maps.method_map.find(id)) {|mo| ebml_w.tag(c::tag_table_method_map) {|| ebml_w.id(id); ebml_w.tag(c::tag_table_val) {|| @@ -801,7 +801,7 @@ fn encode_side_tables_for_id(ecx: @e::encode_ctxt, } } - option::may(ccx.maps.vtable_map.find(id)) {|dr| + option::with_option_do(ccx.maps.vtable_map.find(id)) {|dr| ebml_w.tag(c::tag_table_vtable_map) {|| ebml_w.id(id); ebml_w.tag(c::tag_table_val) {|| diff --git a/src/rustc/metadata/cstore.rs b/src/rustc/metadata/cstore.rs index 36f2c28e74f..473bf8b4e54 100644 --- a/src/rustc/metadata/cstore.rs +++ b/src/rustc/metadata/cstore.rs @@ -163,7 +163,7 @@ fn get_dep_hashes(cstore: cstore) -> [str] { fn get_path(cstore: cstore, d: ast::def_id) -> [str] { // let f = bind str::split_str(_, "::"); - option::maybe(p(cstore).mod_path_map.find(d), [], + option::with_option(p(cstore).mod_path_map.find(d), [], {|ds| str::split_str(ds, "::")}) } // Local Variables: diff --git a/src/rustc/metadata/decoder.rs b/src/rustc/metadata/decoder.rs index bb6c4d5dc3d..2a2438b52a7 100644 --- a/src/rustc/metadata/decoder.rs +++ b/src/rustc/metadata/decoder.rs @@ -120,7 +120,7 @@ fn class_member_id(d: ebml::doc, cdata: cmd) -> ast::def_id { fn field_mutability(d: ebml::doc) -> ast::class_mutability { // Use maybe_get_doc in case it's a method - option::maybe(ebml::maybe_get_doc(d, tag_class_mut), + option::with_option(ebml::maybe_get_doc(d, tag_class_mut), ast::class_immutable, {|d| alt ebml::doc_as_u8(d) as char { diff --git a/src/rustc/middle/check_const.rs b/src/rustc/middle/check_const.rs index 9098bf1fc11..0284bbd4310 100644 --- a/src/rustc/middle/check_const.rs +++ b/src/rustc/middle/check_const.rs @@ -19,7 +19,7 @@ fn check_item(it: @item, &&_is_const: bool, v: visit::vt) { item_const(_, ex) { v.visit_expr(ex, true, v); } item_enum(vs, _) { for var in vs { - option::may(var.node.disr_expr) {|ex| + option::with_option_do(var.node.disr_expr) {|ex| v.visit_expr(ex, true, v); } } diff --git a/src/rustc/middle/kind.rs b/src/rustc/middle/kind.rs index 66638089651..8449e995eda 100644 --- a/src/rustc/middle/kind.rs +++ b/src/rustc/middle/kind.rs @@ -183,7 +183,7 @@ fn check_expr(e: @expr, cx: ctx, v: visit::vt) { } } expr_path(_) | expr_field(_, _, _) { - option::may(cx.tcx.node_type_substs.find(e.id)) {|ts| + option::with_option_do(cx.tcx.node_type_substs.find(e.id)) {|ts| let bounds = alt check e.node { expr_path(_) { let did = ast_util::def_id_of_def(cx.tcx.def_map.get(e.id)); @@ -235,7 +235,7 @@ fn check_stmt(stmt: @stmt, cx: ctx, v: visit::vt) { fn check_ty(aty: @ty, cx: ctx, v: visit::vt) { alt aty.node { ty_path(_, id) { - option::may(cx.tcx.node_type_substs.find(id)) {|ts| + option::with_option_do(cx.tcx.node_type_substs.find(id)) {|ts| let did = ast_util::def_id_of_def(cx.tcx.def_map.get(id)); let bounds = ty::lookup_item_type(cx.tcx, did).bounds; vec::iter2(ts, *bounds) {|ty, bound| diff --git a/src/rustc/middle/last_use.rs b/src/rustc/middle/last_use.rs index aaa452a89c2..08b6add9ccd 100644 --- a/src/rustc/middle/last_use.rs +++ b/src/rustc/middle/last_use.rs @@ -137,7 +137,7 @@ fn visit_expr(ex: @expr, cx: ctx, v: visit::vt) { clear_in_current(cx, root_id, false); } _ { - option::may(def_is_owned_local(cx, my_def)) {|nid| + option::with_option_do(def_is_owned_local(cx, my_def)) {|nid| clear_in_current(cx, nid, false); cx.current += [{def: nid, uses: cons(var_use(ex.id), @nil)}]; @@ -192,7 +192,7 @@ fn visit_expr(ex: @expr, cx: ctx, v: visit::vt) { alt ty::arg_mode(cx.tcx, arg_t) { by_ref | by_val | by_mutbl_ref { let def = cx.def_map.get(arg.id); - option::may(def_is_owned_local(cx, def)) {|id| + option::with_option_do(def_is_owned_local(cx, def)) {|id| clear_in_current(cx, id, false); cx.spill_map.insert(id, ()); } @@ -247,7 +247,7 @@ fn visit_fn(fk: visit::fn_kind, decl: fn_decl, body: blk, alt cx.tcx.freevars.find(id) { some(vars) { for v in *vars { - option::may(def_is_owned_local(cx, v.def)) {|nid| + option::with_option_do(def_is_owned_local(cx, v.def)) {|nid| clear_in_current(cx, nid, false); cx.current += [{def: nid, uses: cons(close_over(id), @nil)}]; diff --git a/src/rustc/middle/resolve.rs b/src/rustc/middle/resolve.rs index 961ef7084ed..972fdc186a9 100644 --- a/src/rustc/middle/resolve.rs +++ b/src/rustc/middle/resolve.rs @@ -1936,7 +1936,7 @@ fn check_exports(e: @env) { fn maybe_add_reexport(e: @env, export_id: node_id, def: option) { - option::may(def) {|def| + option::with_option_do(def) {|def| add_export(e, export_id, def_id_of_def(def), true); } } @@ -2118,7 +2118,7 @@ fn find_impls_in_view_item(e: env, vi: @ast::view_item, ast::view_path_simple(name, pt, id) { let mut found = []; if vec::len(*pt) == 1u { - option::may(sc) {|sc| + option::with_option_do(sc) {|sc| list::iter(sc) {|level| if vec::len(found) == 0u { for imp in *level { diff --git a/src/rustc/middle/trans/base.rs b/src/rustc/middle/trans/base.rs index 552b6b7b7bc..0a3e20793e1 100644 --- a/src/rustc/middle/trans/base.rs +++ b/src/rustc/middle/trans/base.rs @@ -1657,7 +1657,7 @@ fn trans_if(cx: block, cond: @ast::expr, thn: ast::blk, let then_cx = scope_block(bcx, "then"); then_cx.block_span = some(thn.span); let else_cx = scope_block(bcx, "else"); - option::may(els) {|e| else_cx.block_span = some(e.span); } + option::with_option_do(els) {|e| else_cx.block_span = some(e.span); } CondBr(bcx, cond_val, then_cx.llbb, else_cx.llbb); let then_bcx = trans_block(then_cx, thn, then_dest); let then_bcx = trans_block_cleanups(then_bcx, then_cx); @@ -2744,7 +2744,7 @@ fn trans_call_inner(in_cx: block, fn_expr_ty: ty::t, ret_ty: ty::t, Unreachable(bcx); } else if ret_in_loop { bcx = with_cond(bcx, Load(bcx, option::get(ret_flag))) {|bcx| - option::may(bcx.fcx.loop_ret) {|lret| + option::with_option_do(bcx.fcx.loop_ret) {|lret| Store(bcx, C_bool(true), lret.flagptr); Store(bcx, C_bool(false), bcx.fcx.llretptr); } @@ -3816,7 +3816,7 @@ fn alloc_local(cx: block, local: @ast::local) -> block { } let val = alloc_ty(cx, t); if cx.sess().opts.debuginfo { - option::may(simple_name) {|name| + option::with_option_do(simple_name) {|name| str::as_c_str(name, {|buf| llvm::LLVMSetValueName(val, buf) }); diff --git a/src/rustc/middle/trans/closure.rs b/src/rustc/middle/trans/closure.rs index 0ef624c57ef..8bcb022799c 100644 --- a/src/rustc/middle/trans/closure.rs +++ b/src/rustc/middle/trans/closure.rs @@ -325,7 +325,7 @@ fn build_closure(bcx0: block, } } } - option::may(include_ret_handle) {|flagptr| + option::with_option_do(include_ret_handle) {|flagptr| let our_ret = alt bcx.fcx.loop_ret { some({retptr, _}) { retptr } none { bcx.fcx.llretptr } diff --git a/src/rustc/middle/trans/common.rs b/src/rustc/middle/trans/common.rs index 4e0918cf6c7..2878180f960 100644 --- a/src/rustc/middle/trans/common.rs +++ b/src/rustc/middle/trans/common.rs @@ -842,7 +842,7 @@ fn hash_mono_id(&&mi: mono_id) -> uint { h = h * alt param { mono_precise(ty, vts) { let mut h = ty::type_id(ty); - option::may(vts) {|vts| + option::with_option_do(vts) {|vts| for vec::each(vts) {|vt| h += hash_mono_id(vt); } } h diff --git a/src/rustc/middle/trans/reachable.rs b/src/rustc/middle/trans/reachable.rs index 3eab2dc4144..00745b77f57 100644 --- a/src/rustc/middle/trans/reachable.rs +++ b/src/rustc/middle/trans/reachable.rs @@ -51,7 +51,7 @@ fn traverse_exports(cx: ctx, vis: [@view_item]) -> bool { } fn traverse_export(cx: ctx, exp_id: node_id) { - option::may(cx.exp_map.find(exp_id)) {|defs| + option::with_option_do(cx.exp_map.find(exp_id)) {|defs| for vec::each(defs) {|def| traverse_def_id(cx, def.id); } } } diff --git a/src/rustc/middle/trans/type_use.rs b/src/rustc/middle/trans/type_use.rs index 2d3e07fbe06..4cf0899150a 100644 --- a/src/rustc/middle/trans/type_use.rs +++ b/src/rustc/middle/trans/type_use.rs @@ -146,7 +146,7 @@ fn mark_for_expr(cx: ctx, e: @expr) { } } expr_path(_) { - option::may(cx.ccx.tcx.node_type_substs.find(e.id)) {|ts| + option::with_option_do(cx.ccx.tcx.node_type_substs.find(e.id)) {|ts| let id = ast_util::def_id_of_def(cx.ccx.tcx.def_map.get(e.id)); vec::iter2(type_uses_for(cx.ccx, id, ts.len()), ts) {|uses, subst| type_needs(cx, uses, subst) @@ -215,7 +215,7 @@ fn handle_body(cx: ctx, body: blk) { }, visit_block: {|b, cx, v| visit::visit_block(b, cx, v); - option::may(b.node.expr) {|e| + option::with_option_do(b.node.expr) {|e| node_type_needs(cx, use_repr, e.id); } }, diff --git a/src/rustc/middle/tstate/pre_post_conditions.rs b/src/rustc/middle/tstate/pre_post_conditions.rs index 03a03cd0aed..43ebc69ba3f 100644 --- a/src/rustc/middle/tstate/pre_post_conditions.rs +++ b/src/rustc/middle/tstate/pre_post_conditions.rs @@ -336,7 +336,7 @@ fn find_pre_post_expr(fcx: fn_ctxt, e: @expr) { let use_cap_item = fn@(&&cap_item: @capture_item) { let d = local_node_id_to_local_def_id(fcx, cap_item.id); - option::may(d, { |id| use_var(fcx, id) }); + option::with_option_do(d, { |id| use_var(fcx, id) }); }; vec::iter(cap_clause.copies, use_cap_item); vec::iter(cap_clause.moves, use_cap_item); diff --git a/src/rustc/middle/tstate/states.rs b/src/rustc/middle/tstate/states.rs index c0ebc3a9d36..8f1b11fd576 100644 --- a/src/rustc/middle/tstate/states.rs +++ b/src/rustc/middle/tstate/states.rs @@ -410,7 +410,7 @@ fn find_pre_post_state_expr(fcx: fn_ctxt, pres: prestate, e: @expr) -> bool { let base_pres = alt vec::last_opt(exs) { none { pres } some(f) { expr_poststate(fcx.ccx, f) }}; - option::may(maybe_base, {|base| + option::with_option_do(maybe_base, {|base| changed |= find_pre_post_state_expr(fcx, base_pres, base) | set_poststate_ann(fcx.ccx, e.id, expr_poststate(fcx.ccx, base))}); @@ -611,7 +611,7 @@ fn find_pre_post_state_expr(fcx: fn_ctxt, pres: prestate, e: @expr) -> bool { handle_fail(fcx, pres, post); ret set_prestate_ann(fcx.ccx, e.id, pres) | set_poststate_ann(fcx.ccx, e.id, post) | - option::maybe(maybe_fail_val, false, {|fail_val| + option::with_option(maybe_fail_val, false, {|fail_val| find_pre_post_state_expr(fcx, pres, fail_val)}); } expr_check(_, p) { diff --git a/src/rustc/middle/ty.rs b/src/rustc/middle/ty.rs index 99cd0d20564..6a7f7e1a05d 100644 --- a/src/rustc/middle/ty.rs +++ b/src/rustc/middle/ty.rs @@ -385,7 +385,7 @@ fn mk_ctxt(s: session::session, dm: resolve::def_map, amap: ast_map::map, region_map: @middle::region::region_map) -> ctxt { let interner = map::hashmap({|&&k: intern_key| hash_type_structure(k.struct) + - option::maybe(k.o_def_id, 0u, ast_util::hash_def_id) + option::with_option(k.o_def_id, 0u, ast_util::hash_def_id) }, {|&&a, &&b| a == b}); @{interner: interner, mut next_id: 0u, diff --git a/src/rustc/middle/typeck.rs b/src/rustc/middle/typeck.rs index 1cff48e3189..db8bc72c0ae 100644 --- a/src/rustc/middle/typeck.rs +++ b/src/rustc/middle/typeck.rs @@ -3170,7 +3170,7 @@ fn check_expr_with_unifier(fcx: @fn_ctxt, expr: @ast::expr, unify: unifier, fcx.write_ty(id, typ); } ast::expr_rec(fields, base) { - option::may(base) {|b| check_expr(fcx, b); } + option::with_option_do(base) {|b| check_expr(fcx, b); } let fields_t = vec::map(fields, {|f| bot |= check_expr(fcx, f.node.expr); let expr_t = fcx.expr_ty(f.node.expr); diff --git a/src/rustdoc/attr_pass.rs b/src/rustdoc/attr_pass.rs index 5d33fcb8574..f36f3688a3a 100644 --- a/src/rustdoc/attr_pass.rs +++ b/src/rustdoc/attr_pass.rs @@ -50,7 +50,7 @@ fn fold_crate( { topmod: { item: { - name: option::from_maybe(attrs.name, doc.topmod.name()) + name: option::get_or_default(attrs.name, doc.topmod.name()) with doc.topmod.item } with doc.topmod diff --git a/src/rustdoc/config.rs b/src/rustdoc/config.rs index 077f8a6ffd2..eda5acb1811 100644 --- a/src/rustdoc/config.rs +++ b/src/rustdoc/config.rs @@ -125,14 +125,15 @@ fn config_from_opts( let result = result::chain(result) {|config| let output_dir = getopts::opt_maybe_str(match, opt_output_dir()); result::ok({ - output_dir: option::from_maybe(output_dir, config.output_dir) + output_dir: option::get_or_default(output_dir, config.output_dir) with config }) }; let result = result::chain(result) {|config| let output_format = getopts::opt_maybe_str( match, opt_output_format()); - option::maybe(output_format, result::ok(config)) {|output_format| + option::with_option(output_format, result::ok(config)) + {|output_format| result::chain(parse_output_format(output_format)) {|output_format| result::ok({ output_format: output_format @@ -143,7 +144,8 @@ fn config_from_opts( }; let result = result::chain(result) {|config| let output_style = getopts::opt_maybe_str(match, opt_output_style()); - option::maybe(output_style, result::ok(config)) {|output_style| + option::with_option(output_style, result::ok(config)) + {|output_style| result::chain(parse_output_style(output_style)) {|output_style| result::ok({ output_style: output_style diff --git a/src/rustdoc/reexport_pass.rs b/src/rustdoc/reexport_pass.rs index 958c1fece7b..f50e93e1464 100644 --- a/src/rustdoc/reexport_pass.rs +++ b/src/rustdoc/reexport_pass.rs @@ -195,7 +195,7 @@ fn build_reexport_path_map(srv: astsrv::srv, -def_map: def_map) -> path_map { } if reexportdocs.len() > 0u { - option::may(path_map.find(modpath)) {|docs| + option::with_option_do(path_map.find(modpath)) {|docs| reexportdocs = docs + vec::filter(reexportdocs, {|x| !vec::contains(docs, x) });