From d05e2ad66c7bb2418b7c746f87486d4f74180193 Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Tue, 25 Sep 2012 16:23:04 -0700 Subject: [PATCH] Demode core::result --- src/cargo/cargo.rs | 10 +- src/compiletest/errors.rs | 2 +- src/compiletest/header.rs | 2 +- src/compiletest/runtest.rs | 8 +- src/fuzzer/fuzzer.rs | 6 +- src/libcore/comm.rs | 2 +- src/libcore/io.rs | 6 +- src/libcore/private.rs | 2 +- src/libcore/result.rs | 116 ++++++++++-------- src/libstd/json.rs | 14 +-- src/libstd/net_ip.rs | 16 +-- src/libstd/net_tcp.rs | 28 ++--- src/libstd/net_url.rs | 32 ++--- src/rustc/middle/typeck/astconv.rs | 4 +- src/rustc/middle/typeck/infer/combine.rs | 8 +- src/rustdoc/config.rs | 28 ++--- src/test/bench/core-std.rs | 2 +- src/test/bench/shootout-fasta.rs | 2 +- src/test/bench/shootout-k-nucleotide-pipes.rs | 2 +- src/test/bench/shootout-k-nucleotide.rs | 2 +- src/test/bench/shootout-mandelbrot.rs | 2 +- src/test/run-fail/result-get-fail.rs | 2 +- src/test/run-pass/cleanup-copy-mode.rs | 2 +- 23 files changed, 153 insertions(+), 145 deletions(-) diff --git a/src/cargo/cargo.rs b/src/cargo/cargo.rs index 4dcfc608e0ea3..6f356a6e943a4 100644 --- a/src/cargo/cargo.rs +++ b/src/cargo/cargo.rs @@ -460,7 +460,7 @@ fn parse_source(name: ~str, j: json::Json) -> source { fn try_parse_sources(filename: &Path, sources: map::HashMap<~str, source>) { if !os::path_exists(filename) { return; } let c = io::read_whole_file_str(filename); - match json::from_str(result::get(c)) { + match json::from_str(c.get()) { Ok(json::Dict(j)) => { for j.each |k, v| { sources.insert(k, parse_source(k, v)); @@ -579,7 +579,7 @@ fn load_source_info(c: &cargo, src: source) { let srcfile = dir.push("source.json"); if !os::path_exists(&srcfile) { return; } let srcstr = io::read_whole_file_str(&srcfile); - match json::from_str(result::get(srcstr)) { + match json::from_str(srcstr.get()) { Ok(json::Dict(s)) => { let o = parse_source(src.name, json::Dict(s)); @@ -601,7 +601,7 @@ fn load_source_packages(c: &cargo, src: source) { let pkgfile = dir.push("packages.json"); if !os::path_exists(&pkgfile) { return; } let pkgstr = io::read_whole_file_str(&pkgfile); - match json::from_str(result::get(pkgstr)) { + match json::from_str(pkgstr.get()) { Ok(json::List(js)) => { for (*js).each |j| { match *j { @@ -659,7 +659,7 @@ fn build_cargo_options(argv: ~[~str]) -> options { fn configure(opts: options) -> cargo { let home = match get_cargo_root() { Ok(home) => home, - Err(_err) => result::get(get_cargo_sysroot()) + Err(_err) => get_cargo_sysroot().get() }; let get_cargo_dir = match opts.mode { @@ -668,7 +668,7 @@ fn configure(opts: options) -> cargo { local_mode => get_cargo_root_nearest }; - let p = result::get(get_cargo_dir()); + let p = get_cargo_dir().get(); let sources = map::HashMap(); try_parse_sources(&home.push("sources.json"), sources); diff --git a/src/compiletest/errors.rs b/src/compiletest/errors.rs index e7d6593061d70..a8b69201a2250 100644 --- a/src/compiletest/errors.rs +++ b/src/compiletest/errors.rs @@ -9,7 +9,7 @@ type expected_error = { line: uint, kind: ~str, msg: ~str }; // Load any test directives embedded in the file fn load_errors(testfile: &Path) -> ~[expected_error] { let mut error_patterns = ~[]; - let rdr = result::get(io::file_reader(testfile)); + let rdr = io::file_reader(testfile).get(); let mut line_num = 1u; while !rdr.eof() { let ln = rdr.read_line(); diff --git a/src/compiletest/header.rs b/src/compiletest/header.rs index 4ff1b8e9c7887..5cd54a115ff19 100644 --- a/src/compiletest/header.rs +++ b/src/compiletest/header.rs @@ -73,7 +73,7 @@ fn is_test_ignored(config: config, testfile: &Path) -> bool { } fn iter_header(testfile: &Path, it: fn(~str) -> bool) -> bool { - let rdr = result::get(io::file_reader(testfile)); + let rdr = io::file_reader(testfile).get(); while !rdr.eof() { let ln = rdr.read_line(); diff --git a/src/compiletest/runtest.rs b/src/compiletest/runtest.rs index 1c69e51113751..fcb007eca8b92 100644 --- a/src/compiletest/runtest.rs +++ b/src/compiletest/runtest.rs @@ -109,7 +109,7 @@ fn run_pretty_test(config: config, props: test_props, testfile: &Path) { let rounds = match props.pp_exact { option::Some(_) => 1, option::None => 2 }; - let mut srcs = ~[result::get(io::read_whole_file_str(testfile))]; + let mut srcs = ~[io::read_whole_file_str(testfile).get()]; let mut round = 0; while round < rounds { @@ -129,7 +129,7 @@ fn run_pretty_test(config: config, props: test_props, testfile: &Path) { match props.pp_exact { option::Some(file) => { let filepath = testfile.dir_path().push_rel(&file); - result::get(io::read_whole_file_str(&filepath)) + io::read_whole_file_str(&filepath).get() } option::None => { srcs[vec::len(srcs) - 2u] } }; @@ -561,8 +561,8 @@ fn dump_output(config: config, testfile: &Path, out: ~str, err: ~str) { fn dump_output_file(config: config, testfile: &Path, out: ~str, extension: ~str) { let outfile = make_out_name(config, testfile, extension); - let writer = result::get( - io::file_writer(&outfile, ~[io::Create, io::Truncate])); + let writer = + io::file_writer(&outfile, ~[io::Create, io::Truncate]).get(); writer.write_str(out); } diff --git a/src/fuzzer/fuzzer.rs b/src/fuzzer/fuzzer.rs index 5e2cf689b7c57..65adbb9e09e6a 100644 --- a/src/fuzzer/fuzzer.rs +++ b/src/fuzzer/fuzzer.rs @@ -19,7 +19,7 @@ impl test_mode : cmp::Eq { fn write_file(filename: &Path, content: ~str) { result::get( - io::file_writer(filename, ~[io::Create, io::Truncate])) + &io::file_writer(filename, ~[io::Create, io::Truncate])) .write_str(content); } @@ -543,7 +543,7 @@ fn check_convergence(files: &[Path]) { error!("pp convergence tests: %u files", vec::len(files)); for files.each |file| { if !file_might_not_converge(file) { - let s = @result::get(io::read_whole_file_str(file)); + let s = @result::get(&io::read_whole_file_str(file)); if !content_might_not_converge(*s) { error!("pp converge: %s", file.to_str()); // Change from 7u to 2u once @@ -563,7 +563,7 @@ fn check_variants(files: &[Path], cx: context) { loop; } - let s = @result::get(io::read_whole_file_str(file)); + let s = @result::get(&io::read_whole_file_str(file)); if contains(*s, ~"#") { loop; // Macros are confusing } diff --git a/src/libcore/comm.rs b/src/libcore/comm.rs index b99eec8bb5b33..a32d7af2ac68a 100644 --- a/src/libcore/comm.rs +++ b/src/libcore/comm.rs @@ -459,7 +459,7 @@ fn test_recv_chan_wrong_task() { let po = Port(); let ch = Chan(po); send(ch, ~"flower"); - assert result::is_err(task::try(|| + assert result::is_err(&task::try(|| recv_chan(ch) )) } diff --git a/src/libcore/io.rs b/src/libcore/io.rs index 7c08e508d51e4..9a2a177c19627 100644 --- a/src/libcore/io.rs +++ b/src/libcore/io.rs @@ -645,7 +645,7 @@ impl T : WriterUtil { #[allow(non_implicitly_copyable_typarams)] fn file_writer(path: &Path, flags: ~[FileFlag]) -> Result { - result::chain(mk_file_writer(path, flags), |w| result::Ok(w)) + mk_file_writer(path, flags).chain(|w| result::Ok(w)) } @@ -864,10 +864,10 @@ mod tests { { let out: io::Writer = result::get( - io::file_writer(tmpfile, ~[io::Create, io::Truncate])); + &io::file_writer(tmpfile, ~[io::Create, io::Truncate])); out.write_str(frood); } - let inp: io::Reader = result::get(io::file_reader(tmpfile)); + let inp: io::Reader = result::get(&io::file_reader(tmpfile)); let frood2: ~str = inp.read_c_str(); log(debug, frood2); assert frood == frood2; diff --git a/src/libcore/private.rs b/src/libcore/private.rs index 777aea7320c6a..9fe05723d35fb 100644 --- a/src/libcore/private.rs +++ b/src/libcore/private.rs @@ -283,7 +283,7 @@ fn test_weaken_task_fail() { } } }; - assert result::is_err(res); + assert result::is_err(&res); } /**************************************************************************** diff --git a/src/libcore/result.rs b/src/libcore/result.rs index 205d375e9db88..3735d555e2d04 100644 --- a/src/libcore/result.rs +++ b/src/libcore/result.rs @@ -1,5 +1,9 @@ //! A type representing either success or failure +// NB: transitionary, de-mode-ing. +#[forbid(deprecated_mode)]; +#[forbid(deprecated_pattern)]; + use cmp::Eq; use either::Either; @@ -18,8 +22,8 @@ enum Result { * * If the result is an error */ -pure fn get(res: Result) -> T { - match res { +pure fn get(res: &Result) -> T { + match *res { Ok(t) => t, Err(the_err) => unsafe { fail fmt!("get called on error result: %?", the_err) @@ -50,23 +54,23 @@ pure fn get_ref(res: &a/Result) -> &a/T { * * If the result is not an error */ -pure fn get_err(res: Result) -> U { - match res { +pure fn get_err(res: &Result) -> U { + match *res { Err(u) => u, Ok(_) => fail ~"get_err called on ok result" } } /// Returns true if the result is `ok` -pure fn is_ok(res: Result) -> bool { - match res { +pure fn is_ok(res: &Result) -> bool { + match *res { Ok(_) => true, Err(_) => false } } /// Returns true if the result is `err` -pure fn is_err(res: Result) -> bool { +pure fn is_err(res: &Result) -> bool { !is_ok(res) } @@ -76,8 +80,8 @@ pure fn is_err(res: Result) -> bool { * `ok` result variants are converted to `either::right` variants, `err` * result variants are converted to `either::left`. */ -pure fn to_either(res: Result) -> Either { - match res { +pure fn to_either(res: &Result) -> Either { + match *res { Ok(res) => either::Right(res), Err(fail_) => either::Left(fail_) } @@ -97,11 +101,13 @@ pure fn to_either(res: Result) -> Either { * ok(parse_bytes(buf)) * } */ -fn chain(res: Result, op: fn(T) -> Result) +fn chain(+res: Result, op: fn(+t: T) -> Result) -> Result { - match res { - Ok(t) => op(t), - Err(e) => Err(e) + // XXX: Should be writable with move + match + if res.is_ok() { + op(unwrap(res)) + } else { + Err(unwrap_err(res)) } } @@ -114,10 +120,10 @@ fn chain(res: Result, op: fn(T) -> Result) * successful result while handling an error. */ fn chain_err( - res: Result, - op: fn(V) -> Result) + +res: Result, + op: fn(+t: V) -> Result) -> Result { - match res { + move match res { Ok(t) => Ok(t), Err(v) => op(v) } @@ -137,9 +143,9 @@ fn chain_err( * print_buf(buf) * } */ -fn iter(res: Result, f: fn(T)) { - match res { - Ok(t) => f(t), +fn iter(res: &Result, f: fn((&T))) { + match *res { + Ok(t) => f(&t), Err(_) => () } } @@ -152,10 +158,10 @@ fn iter(res: Result, f: fn(T)) { * This function can be used to pass through a successful result while * handling an error. */ -fn iter_err(res: Result, f: fn(E)) { - match res { +fn iter_err(res: &Result, f: fn((&E))) { + match *res { Ok(_) => (), - Err(e) => f(e) + Err(e) => f(&e) } } @@ -173,10 +179,10 @@ fn iter_err(res: Result, f: fn(E)) { * parse_bytes(buf) * } */ -fn map(res: Result, op: fn(T) -> U) +fn map(res: &Result, op: fn((&T)) -> U) -> Result { - match res { - Ok(t) => Ok(op(t)), + match *res { + Ok(t) => Ok(op(&t)), Err(e) => Err(e) } } @@ -189,63 +195,65 @@ fn map(res: Result, op: fn(T) -> U) * is immediately returned. This function can be used to pass through a * successful result while handling an error. */ -fn map_err(res: Result, op: fn(E) -> F) +fn map_err(res: &Result, op: fn((&E)) -> F) -> Result { - match res { + match *res { Ok(t) => Ok(t), - Err(e) => Err(op(e)) + Err(e) => Err(op(&e)) } } impl Result { - fn is_ok() -> bool { is_ok(self) } + fn is_ok() -> bool { is_ok(&self) } - fn is_err() -> bool { is_err(self) } + fn is_err() -> bool { is_err(&self) } - fn iter(f: fn(T)) { + fn iter(f: fn((&T))) { match self { - Ok(t) => f(t), + Ok(t) => f(&t), Err(_) => () } } - fn iter_err(f: fn(E)) { + fn iter_err(f: fn((&E))) { match self { Ok(_) => (), - Err(e) => f(e) + Err(e) => f(&e) } } } impl Result { - fn get() -> T { get(self) } + fn get() -> T { get(&self) } - fn map_err(op: fn(E) -> F) -> Result { + fn map_err(op: fn((&E)) -> F) -> Result { match self { Ok(t) => Ok(t), - Err(e) => Err(op(e)) + Err(e) => Err(op(&e)) } } } impl Result { - fn get_err() -> E { get_err(self) } + fn get_err() -> E { get_err(&self) } - fn map(op: fn(T) -> U) -> Result { + fn map(op: fn((&T)) -> U) -> Result { match self { - Ok(t) => Ok(op(t)), + Ok(t) => Ok(op(&t)), Err(e) => Err(e) } } } impl Result { - fn chain(op: fn(T) -> Result) -> Result { - chain(self, op) + fn chain(op: fn(+t: T) -> Result) -> Result { + // XXX: Bad copy + chain(copy self, op) } - fn chain_err(op: fn(E) -> Result) -> Result { - chain_err(self, op) + fn chain_err(op: fn(+t: E) -> Result) -> Result { + // XXX: Bad copy + chain_err(copy self, op) } } @@ -280,11 +288,11 @@ fn map_vec( } fn map_opt( - o_t: Option, op: fn(T) -> Result) -> Result,U> { + o_t: &Option, op: fn((&T)) -> Result) -> Result,U> { - match o_t { + match *o_t { None => Ok(None), - Some(t) => match op(t) { + Some(t) => match op(&t) { Ok(v) => Ok(Some(v)), Err(e) => Err(e) } @@ -301,14 +309,14 @@ fn map_opt( * to accommodate an error like the vectors being of different lengths. */ fn map_vec2(ss: &[S], ts: &[T], - op: fn(S,T) -> Result) -> Result<~[V],U> { + op: fn((&S),(&T)) -> Result) -> Result<~[V],U> { assert vec::same_length(ss, ts); let n = vec::len(ts); let mut vs = vec::with_capacity(n); let mut i = 0u; while i < n { - match op(ss[i],ts[i]) { + match op(&ss[i],&ts[i]) { Ok(v) => vec::push(vs, v), Err(u) => return Err(u) } @@ -323,13 +331,13 @@ fn map_vec2(ss: &[S], ts: &[T], * on its own as no result vector is built. */ fn iter_vec2(ss: &[S], ts: &[T], - op: fn(S,T) -> Result<(),U>) -> Result<(),U> { + op: fn((&S),(&T)) -> Result<(),U>) -> Result<(),U> { assert vec::same_length(ss, ts); let n = vec::len(ts); let mut i = 0u; while i < n { - match op(ss[i],ts[i]) { + match op(&ss[i],&ts[i]) { Ok(()) => (), Err(u) => return Err(u) } @@ -380,7 +388,7 @@ mod tests { #[legacy_exports]; fn op1() -> result::Result { result::Ok(666) } - fn op2(&&i: int) -> result::Result { + fn op2(+i: int) -> result::Result { result::Ok(i as uint + 1u) } @@ -388,12 +396,12 @@ mod tests { #[test] fn chain_success() { - assert get(chain(op1(), op2)) == 667u; + assert get(&chain(op1(), op2)) == 667u; } #[test] fn chain_failure() { - assert get_err(chain(op3(), op2)) == ~"sadface"; + assert get_err(&chain(op3(), op2)) == ~"sadface"; } #[test] diff --git a/src/libstd/json.rs b/src/libstd/json.rs index 0f7bec6344a63..2002e143ffa40 100644 --- a/src/libstd/json.rs +++ b/src/libstd/json.rs @@ -892,7 +892,7 @@ mod tests { ])) ]); let astr = to_str(a); - let b = result::get(from_str(astr)); + let b = result::get(&from_str(astr)); let bstr = to_str(b); assert astr == bstr; assert a == b; @@ -1040,24 +1040,24 @@ mod tests { assert from_str(~"{\"a\":1,") == Err({line: 1u, col: 8u, msg: @~"EOF while parsing object"}); - assert eq(result::get(from_str(~"{}")), mk_dict(~[])); - assert eq(result::get(from_str(~"{\"a\": 3}")), + assert eq(result::get(&from_str(~"{}")), mk_dict(~[])); + assert eq(result::get(&from_str(~"{\"a\": 3}")), mk_dict(~[(~"a", Num(3.0f))])); - assert eq(result::get(from_str(~"{ \"a\": null, \"b\" : true }")), + assert eq(result::get(&from_str(~"{ \"a\": null, \"b\" : true }")), mk_dict(~[ (~"a", Null), (~"b", Boolean(true))])); - assert eq(result::get(from_str(~"\n{ \"a\": null, \"b\" : true }\n")), + assert eq(result::get(&from_str(~"\n{ \"a\": null, \"b\" : true }\n")), mk_dict(~[ (~"a", Null), (~"b", Boolean(true))])); - assert eq(result::get(from_str(~"{\"a\" : 1.0 ,\"b\": [ true ]}")), + assert eq(result::get(&from_str(~"{\"a\" : 1.0 ,\"b\": [ true ]}")), mk_dict(~[ (~"a", Num(1.0)), (~"b", List(@~[Boolean(true)])) ])); - assert eq(result::get(from_str( + assert eq(result::get(&from_str( ~"{" + ~"\"a\": 1.0, " + ~"\"b\": [" + diff --git a/src/libstd/net_ip.rs b/src/libstd/net_ip.rs index 3e104e259b8e2..445bc62e4c9a6 100644 --- a/src/libstd/net_ip.rs +++ b/src/libstd/net_ip.rs @@ -176,24 +176,24 @@ mod v4 { unsafe { let INADDR_NONE = ll::get_INADDR_NONE(); let ip_rep_result = parse_to_ipv4_rep(ip); - if result::is_err(ip_rep_result) { - let err_str = result::get_err(ip_rep_result); + if result::is_err(&ip_rep_result) { + let err_str = result::get_err(&ip_rep_result); return result::Err({err_msg: err_str}) } // ipv4_rep.as_u32 is unsafe :/ let input_is_inaddr_none = - result::get(ip_rep_result).as_u32() == INADDR_NONE; + result::get(&ip_rep_result).as_u32() == INADDR_NONE; let new_addr = uv_ip4_addr(str::from_slice(ip), 22); let reformatted_name = uv_ip4_name(&new_addr); log(debug, fmt!("try_parse_addr: input ip: %s reparsed ip: %s", ip, reformatted_name)); let ref_ip_rep_result = parse_to_ipv4_rep(reformatted_name); - if result::is_err(ref_ip_rep_result) { - let err_str = result::get_err(ref_ip_rep_result); + if result::is_err(&ref_ip_rep_result) { + let err_str = result::get_err(&ref_ip_rep_result); return result::Err({err_msg: err_str}) } - if result::get(ref_ip_rep_result).as_u32() == INADDR_NONE && + if result::get(&ref_ip_rep_result).as_u32() == INADDR_NONE && !input_is_inaddr_none { return result::Err( {err_msg: ~"uv_ip4_name produced invalid result."}) @@ -358,7 +358,7 @@ mod test { let localhost_name = ~"localhost"; let iotask = uv::global_loop::get(); let ga_result = get_addr(localhost_name, iotask); - if result::is_err(ga_result) { + if result::is_err(&ga_result) { fail ~"got err result from net::ip::get_addr();" } // note really sure how to realiably test/assert @@ -384,6 +384,6 @@ mod test { let localhost_name = ~"sjkl234m,./sdf"; let iotask = uv::global_loop::get(); let ga_result = get_addr(localhost_name, iotask); - assert result::is_err(ga_result); + assert result::is_err(&ga_result); } } diff --git a/src/libstd/net_tcp.rs b/src/libstd/net_tcp.rs index a0a209eae52c7..a1c7637dee69f 100644 --- a/src/libstd/net_tcp.rs +++ b/src/libstd/net_tcp.rs @@ -871,17 +871,17 @@ fn read_common_impl(socket_data: *TcpSocketData, timeout_msecs: uint) log(debug, ~"starting tcp::read"); let iotask = (*socket_data).iotask; let rs_result = read_start_common_impl(socket_data); - if result::is_err(rs_result) { - let err_data = result::get_err(rs_result); + if result::is_err(&rs_result) { + let err_data = result::get_err(&rs_result); result::Err(err_data) } else { log(debug, ~"tcp::read before recv_timeout"); let read_result = if timeout_msecs > 0u { timer::recv_timeout( - iotask, timeout_msecs, result::get(rs_result)) + iotask, timeout_msecs, result::get(&rs_result)) } else { - Some(core::comm::recv(result::get(rs_result))) + Some(core::comm::recv(result::get(&rs_result))) }; log(debug, ~"tcp::read after recv_timeout"); match read_result { @@ -1514,9 +1514,9 @@ mod test { let accept_result = accept(new_conn); log(debug, ~"SERVER: after accept()"); - if result::is_err(accept_result) { + if result::is_err(&accept_result) { log(debug, ~"SERVER: error accept connection"); - let err_data = result::get_err(accept_result); + let err_data = result::get_err(&accept_result); core::comm::send(kill_ch, Some(err_data)); log(debug, ~"SERVER/WORKER: send on err cont ch"); @@ -1558,8 +1558,8 @@ mod test { log(debug, ~"SERVER: recv'd on cont_ch..leaving listen cb"); }); // err check on listen_result - if result::is_err(listen_result) { - match result::get_err(listen_result) { + if result::is_err(&listen_result) { + match result::get_err(&listen_result) { GenericListenErr(name, msg) => { fail fmt!("SERVER: exited abnormally name %s msg %s", name, msg); @@ -1592,8 +1592,8 @@ mod test { new_conn, kill_ch); }); // err check on listen_result - if result::is_err(listen_result) { - result::get_err(listen_result) + if result::is_err(&listen_result) { + result::get_err(&listen_result) } else { fail ~"SERVER: did not fail as expected" @@ -1609,9 +1609,9 @@ mod test { log(debug, ~"CLIENT: starting.."); let connect_result = connect(move server_ip_addr, server_port, iotask); - if result::is_err(connect_result) { + if result::is_err(&connect_result) { log(debug, ~"CLIENT: failed to connect"); - let err_data = result::get_err(connect_result); + let err_data = result::get_err(&connect_result); Err(err_data) } else { @@ -1636,9 +1636,9 @@ mod test { fn tcp_write_single(sock: &TcpSocket, val: ~[u8]) { let write_result_future = sock.write_future(val); let write_result = write_result_future.get(); - if result::is_err(write_result) { + if result::is_err(&write_result) { log(debug, ~"tcp_write_single: write failed!"); - let err_data = result::get_err(write_result); + let err_data = result::get_err(&write_result); log(debug, fmt!("tcp_write_single err name: %s msg: %s", err_data.err_name, err_data.err_msg)); // meh. torn on what to do here. diff --git a/src/libstd/net_url.rs b/src/libstd/net_url.rs index 74c603e29e91b..2a27aed773d0f 100644 --- a/src/libstd/net_url.rs +++ b/src/libstd/net_url.rs @@ -627,30 +627,30 @@ fn get_query_fragment(rawurl: &str) -> fn from_str(rawurl: &str) -> result::Result { // scheme let mut schm = get_scheme(rawurl); - if result::is_err(schm) { - return result::Err(copy *result::get_err(schm)); + if result::is_err(&schm) { + return result::Err(copy *result::get_err(&schm)); } let (scheme, rest) = result::unwrap(schm); // authority let mut auth = get_authority(rest); - if result::is_err(auth) { - return result::Err(copy *result::get_err(auth)); + if result::is_err(&auth) { + return result::Err(copy *result::get_err(&auth)); } let (userinfo, host, port, rest) = result::unwrap(auth); // path let has_authority = if host == ~"" { false } else { true }; let mut pth = get_path(rest, has_authority); - if result::is_err(pth) { - return result::Err(copy *result::get_err(pth)); + if result::is_err(&pth) { + return result::Err(copy *result::get_err(&pth)); } let (path, rest) = result::unwrap(pth); // query and fragment let mut qry = get_query_fragment(rest); - if result::is_err(qry) { - return result::Err(copy *result::get_err(qry)); + if result::is_err(&qry) { + return result::Err(copy *result::get_err(&qry)); } let (query, fragment) = result::unwrap(qry); @@ -796,13 +796,13 @@ mod tests { assert p == option::Some(~"8000"); // invalid authorities; - assert result::is_err(get_authority( + assert result::is_err(&get_authority( ~"//user:pass@rust-lang:something")); - assert result::is_err(get_authority( + assert result::is_err(&get_authority( ~"//user@rust-lang:something:/path")); - assert result::is_err(get_authority( + assert result::is_err(&get_authority( ~"//2001:0db8:85a3:0042:0000:8a2e:0370:7334:800a")); - assert result::is_err(get_authority( + assert result::is_err(&get_authority( ~"//2001:0db8:85a3:0042:0000:8a2e:0370:7334:8000:00")); // these parse as empty, because they don't start with '//' @@ -830,7 +830,7 @@ mod tests { assert r == ~"?q=v"; //failure cases - assert result::is_err(get_path(~"something?q", true)); + assert result::is_err(&get_path(~"something?q", true)); } @@ -877,13 +877,13 @@ mod tests { #[test] fn test_no_scheme() { - assert result::is_err(get_scheme(~"noschemehere.html")); + assert result::is_err(&get_scheme(~"noschemehere.html")); } #[test] fn test_invalid_scheme_errors() { - assert result::is_err(from_str(~"99://something")); - assert result::is_err(from_str(~"://something")); + assert result::is_err(&from_str(~"99://something")); + assert result::is_err(&from_str(~"://something")); } #[test] diff --git a/src/rustc/middle/typeck/astconv.rs b/src/rustc/middle/typeck/astconv.rs index 0c47499455362..5434677b6fcb6 100644 --- a/src/rustc/middle/typeck/astconv.rs +++ b/src/rustc/middle/typeck/astconv.rs @@ -415,7 +415,7 @@ fn ty_of_arg( let mode = { match a.mode { ast::infer(_) if expected_ty.is_some() => { - result::get(ty::unify_mode( + result::get(&ty::unify_mode( self.tcx(), ty::expected_found {expected: expected_ty.get().mode, found: a.mode})) @@ -434,7 +434,7 @@ fn ty_of_arg( _ => { let m1 = ast::expl(ty::default_arg_mode_for_ty(self.tcx(), ty)); - result::get(ty::unify_mode( + result::get(&ty::unify_mode( self.tcx(), ty::expected_found {expected: m1, found: a.mode})) diff --git a/src/rustc/middle/typeck/infer/combine.rs b/src/rustc/middle/typeck/infer/combine.rs index 84791b59b329f..db65bff9bfec2 100644 --- a/src/rustc/middle/typeck/infer/combine.rs +++ b/src/rustc/middle/typeck/infer/combine.rs @@ -221,7 +221,7 @@ fn super_tps( if vec::same_length(as_, bs) { iter_vec2(as_, bs, |a, b| { - eq_tys(self, a, b) + eq_tys(self, *a, *b) }).then(|| Ok(as_.to_vec()) ) } else { Err(ty::terr_ty_param_size( @@ -327,7 +327,7 @@ fn super_fn_sigs( b_args: ~[ty::arg]) -> cres<~[ty::arg]> { if vec::same_length(a_args, b_args) { - map_vec2(a_args, b_args, |a, b| self.args(a, b)) + map_vec2(a_args, b_args, |a, b| self.args(*a, *b)) } else { Err(ty::terr_arg_count) } @@ -474,7 +474,7 @@ fn super_tys( (ty::ty_rec(as_), ty::ty_rec(bs)) => { if vec::same_length(as_, bs) { map_vec2(as_, bs, |a,b| { - self.flds(a, b) + self.flds(*a, *b) }).chain(|flds| Ok(ty::mk_rec(tcx, flds)) ) } else { Err(ty::terr_record_size(expected_found(self, as_.len(), @@ -484,7 +484,7 @@ fn super_tys( (ty::ty_tup(as_), ty::ty_tup(bs)) => { if vec::same_length(as_, bs) { - map_vec2(as_, bs, |a, b| self.tys(a, b) ) + map_vec2(as_, bs, |a, b| self.tys(*a, *b) ) .chain(|ts| Ok(ty::mk_tup(tcx, ts)) ) } else { Err(ty::terr_tuple_size( diff --git a/src/rustdoc/config.rs b/src/rustdoc/config.rs index b95e16570435b..d8e79182506c7 100644 --- a/src/rustdoc/config.rs +++ b/src/rustdoc/config.rs @@ -285,20 +285,20 @@ mod test { #[test] fn should_error_with_no_crates() { let config = test::parse_config(~[~"rustdoc"]); - assert result::get_err(config) == ~"no crates specified"; + assert config.get_err() == ~"no crates specified"; } #[test] fn should_error_with_multiple_crates() { let config = test::parse_config(~[~"rustdoc", ~"crate1.rc", ~"crate2.rc"]); - assert result::get_err(config) == ~"multiple crates specified"; + assert config.get_err() == ~"multiple crates specified"; } #[test] fn should_set_output_dir_to_cwd_if_not_provided() { let config = test::parse_config(~[~"rustdoc", ~"crate.rc"]); - assert result::get(config).output_dir == Path("."); + assert config.get().output_dir == Path("."); } #[test] @@ -306,13 +306,13 @@ fn should_set_output_dir_if_provided() { let config = test::parse_config(~[ ~"rustdoc", ~"crate.rc", ~"--output-dir", ~"snuggles" ]); - assert result::get(config).output_dir == Path("snuggles"); + assert config.get().output_dir == Path("snuggles"); } #[test] fn should_set_output_format_to_pandoc_html_if_not_provided() { let config = test::parse_config(~[~"rustdoc", ~"crate.rc"]); - assert result::get(config).output_format == PandocHtml; + assert config.get().output_format == PandocHtml; } #[test] @@ -320,7 +320,7 @@ fn should_set_output_format_to_markdown_if_requested() { let config = test::parse_config(~[ ~"rustdoc", ~"crate.rc", ~"--output-format", ~"markdown" ]); - assert result::get(config).output_format == Markdown; + assert config.get().output_format == Markdown; } #[test] @@ -328,7 +328,7 @@ fn should_set_output_format_to_pandoc_html_if_requested() { let config = test::parse_config(~[ ~"rustdoc", ~"crate.rc", ~"--output-format", ~"html" ]); - assert result::get(config).output_format == PandocHtml; + assert config.get().output_format == PandocHtml; } #[test] @@ -336,13 +336,13 @@ fn should_error_on_bogus_format() { let config = test::parse_config(~[ ~"rustdoc", ~"crate.rc", ~"--output-format", ~"bogus" ]); - assert result::get_err(config) == ~"unknown output format 'bogus'"; + assert config.get_err() == ~"unknown output format 'bogus'"; } #[test] fn should_set_output_style_to_doc_per_mod_by_default() { let config = test::parse_config(~[~"rustdoc", ~"crate.rc"]); - assert result::get(config).output_style == DocPerMod; + assert config.get().output_style == DocPerMod; } #[test] @@ -350,7 +350,7 @@ fn should_set_output_style_to_one_doc_if_requested() { let config = test::parse_config(~[ ~"rustdoc", ~"crate.rc", ~"--output-style", ~"doc-per-crate" ]); - assert result::get(config).output_style == DocPerCrate; + assert config.get().output_style == DocPerCrate; } #[test] @@ -358,7 +358,7 @@ fn should_set_output_style_to_doc_per_mod_if_requested() { let config = test::parse_config(~[ ~"rustdoc", ~"crate.rc", ~"--output-style", ~"doc-per-mod" ]); - assert result::get(config).output_style == DocPerMod; + assert config.get().output_style == DocPerMod; } #[test] @@ -366,7 +366,7 @@ fn should_error_on_bogus_output_style() { let config = test::parse_config(~[ ~"rustdoc", ~"crate.rc", ~"--output-style", ~"bogus" ]); - assert result::get_err(config) == ~"unknown output style 'bogus'"; + assert config.get_err() == ~"unknown output style 'bogus'"; } #[test] @@ -374,11 +374,11 @@ fn should_set_pandoc_command_if_requested() { let config = test::parse_config(~[ ~"rustdoc", ~"crate.rc", ~"--pandoc-cmd", ~"panda-bear-doc" ]); - assert result::get(config).pandoc_cmd == Some(~"panda-bear-doc"); + assert config.get().pandoc_cmd == Some(~"panda-bear-doc"); } #[test] fn should_set_pandoc_command_when_using_pandoc() { let config = test::parse_config(~[~"rustdoc", ~"crate.rc"]); - assert result::get(config).pandoc_cmd == Some(~"pandoc"); + assert config.get().pandoc_cmd == Some(~"pandoc"); } diff --git a/src/test/bench/core-std.rs b/src/test/bench/core-std.rs index a88793705a6b6..535b76bc94bfc 100644 --- a/src/test/bench/core-std.rs +++ b/src/test/bench/core-std.rs @@ -56,7 +56,7 @@ fn read_line() { .push_rel(&Path("src/test/bench/shootout-k-nucleotide.data")); for int::range(0, 3) |_i| { - let reader = result::get(io::file_reader(&path)); + let reader = result::get(&io::file_reader(&path)); while !reader.eof() { reader.read_line(); } diff --git a/src/test/bench/shootout-fasta.rs b/src/test/bench/shootout-fasta.rs index a07b29f3dc6f8..0c742e16bfa57 100644 --- a/src/test/bench/shootout-fasta.rs +++ b/src/test/bench/shootout-fasta.rs @@ -81,7 +81,7 @@ fn main(++args: ~[~str]) { }; let writer = if os::getenv(~"RUST_BENCH").is_some() { - result::get(io::file_writer(&Path("./shootout-fasta.data"), + result::get(&io::file_writer(&Path("./shootout-fasta.data"), ~[io::Truncate, io::Create])) } else { io::stdout() diff --git a/src/test/bench/shootout-k-nucleotide-pipes.rs b/src/test/bench/shootout-k-nucleotide-pipes.rs index dbdcf15db8a75..b5dcacd76d3b4 100644 --- a/src/test/bench/shootout-k-nucleotide-pipes.rs +++ b/src/test/bench/shootout-k-nucleotide-pipes.rs @@ -134,7 +134,7 @@ fn main(++args: ~[~str]) { // get to this massive data set, but #include_bin chokes on it (#2598) let path = Path(env!("CFG_SRC_DIR")) .push_rel(&Path("src/test/bench/shootout-k-nucleotide.data")); - result::get(io::file_reader(&path)) + result::get(&io::file_reader(&path)) } else { io::stdin() }; diff --git a/src/test/bench/shootout-k-nucleotide.rs b/src/test/bench/shootout-k-nucleotide.rs index d9d5827c56d41..5f7036ed82a52 100644 --- a/src/test/bench/shootout-k-nucleotide.rs +++ b/src/test/bench/shootout-k-nucleotide.rs @@ -131,7 +131,7 @@ fn main(++args: ~[~str]) { // get to this massive data set, but #include_bin chokes on it (#2598) let path = Path(env!("CFG_SRC_DIR")) .push_rel(&Path("src/test/bench/shootout-k-nucleotide.data")); - result::get(io::file_reader(&path)) + result::get(&io::file_reader(&path)) } else { io::stdin() }; diff --git a/src/test/bench/shootout-mandelbrot.rs b/src/test/bench/shootout-mandelbrot.rs index f6386a207b11a..0cf0f0da5e5ae 100644 --- a/src/test/bench/shootout-mandelbrot.rs +++ b/src/test/bench/shootout-mandelbrot.rs @@ -114,7 +114,7 @@ fn writer(path: ~str, writech: comm::Chan>, size: uint) } _ => { result::get( - io::file_writer(&Path(path), + &io::file_writer(&Path(path), ~[io::Create, io::Truncate])) } }; diff --git a/src/test/run-fail/result-get-fail.rs b/src/test/run-fail/result-get-fail.rs index fbc8378643b96..2b8712f3d593a 100644 --- a/src/test/run-fail/result-get-fail.rs +++ b/src/test/run-fail/result-get-fail.rs @@ -1,4 +1,4 @@ // error-pattern:get called on error result: ~"kitty" fn main() { - log(error, result::get(result::Err::(~"kitty"))); + log(error, result::get(&result::Err::(~"kitty"))); } diff --git a/src/test/run-pass/cleanup-copy-mode.rs b/src/test/run-pass/cleanup-copy-mode.rs index 2cf1276887e85..e4bfa54c41041 100644 --- a/src/test/run-pass/cleanup-copy-mode.rs +++ b/src/test/run-pass/cleanup-copy-mode.rs @@ -2,7 +2,7 @@ fn adder(+x: @int, +y: @int) -> int { return *x + *y; } fn failer() -> @int { fail; } fn main() { - assert(result::is_err(task::try(|| { + assert(result::is_err(&task::try(|| { adder(@2, failer()); () }))); }