Skip to content

Commit

Permalink
Switch alts to use arrows
Browse files Browse the repository at this point in the history
  • Loading branch information
brson committed Aug 6, 2012
1 parent c9d2769 commit 025d866
Show file tree
Hide file tree
Showing 329 changed files with 8,097 additions and 8,425 deletions.
340 changes: 166 additions & 174 deletions src/cargo/cargo.rs

Large diffs are not rendered by default.

37 changes: 20 additions & 17 deletions src/compiletest/compiletest.rs
Expand Up @@ -43,8 +43,8 @@ fn parse_config(args: ~[~str]) -> config {
let args_ = vec::tail(args);
let matches =
alt getopts::getopts(args_, opts) {
ok(m) { m }
err(f) { fail getopts::fail_str(f) }
ok(m) => m,
err(f) => fail getopts::fail_str(f)
};

return {compile_lib_path: getopts::opt_str(matches, ~"compile-lib-path"),
Expand Down Expand Up @@ -85,7 +85,7 @@ fn log_config(config: config) {
}

fn opt_str(maybestr: option<~str>) -> ~str {
alt maybestr { option::some(s) { s } option::none { ~"(none)" } }
alt maybestr { option::some(s) => s, option::none => ~"(none)" }
}

fn str_opt(maybestr: ~str) -> option<~str> {
Expand All @@ -94,20 +94,20 @@ fn str_opt(maybestr: ~str) -> option<~str> {

fn str_mode(s: ~str) -> mode {
alt s {
~"compile-fail" { mode_compile_fail }
~"run-fail" { mode_run_fail }
~"run-pass" { mode_run_pass }
~"pretty" { mode_pretty }
_ { fail ~"invalid mode" }
~"compile-fail" => mode_compile_fail,
~"run-fail" => mode_run_fail,
~"run-pass" => mode_run_pass,
~"pretty" => mode_pretty,
_ => fail ~"invalid mode"
}
}

fn mode_str(mode: mode) -> ~str {
alt mode {
mode_compile_fail { ~"compile-fail" }
mode_run_fail { ~"run-fail" }
mode_run_pass { ~"run-pass" }
mode_pretty { ~"pretty" }
mode_compile_fail => ~"compile-fail",
mode_run_fail => ~"run-fail",
mode_run_pass => ~"run-pass",
mode_pretty => ~"pretty"
}
}

Expand All @@ -121,14 +121,14 @@ fn run_tests(config: config) {
fn test_opts(config: config) -> test::test_opts {
{filter:
alt config.filter {
option::some(s) { option::some(s) }
option::none { option::none }
option::some(s) => option::some(s),
option::none => option::none
},
run_ignored: config.run_ignored,
logfile:
alt config.logfile {
option::some(s) { option::some(s) }
option::none { option::none }
option::some(s) => option::some(s),
option::none => option::none
}
}
}
Expand All @@ -149,7 +149,10 @@ fn make_tests(config: config) -> ~[test::test_desc] {
fn is_test(config: config, testfile: ~str) -> bool {
// Pretty-printer does not work with .rc files yet
let valid_extensions =
alt config.mode { mode_pretty { ~[~".rs"] } _ { ~[~".rc", ~".rs"] } };
alt config.mode {
mode_pretty => ~[~".rs"],
_ => ~[~".rc", ~".rs"]
};
let invalid_prefixes = ~[~".", ~"#", ~"~"];
let name = path::basename(testfile);

Expand Down
4 changes: 2 additions & 2 deletions src/compiletest/errors.rs
Expand Up @@ -24,8 +24,8 @@ fn parse_expected(line_num: uint, line: ~str) -> ~[expected_error] unsafe {
let error_tag = ~"//~";
let mut idx;
alt str::find_str(line, error_tag) {
option::none { return ~[]; }
option::some(nn) { idx = (nn as uint) + str::len(error_tag); }
option::none => return ~[],
option::some(nn) => { idx = (nn as uint) + str::len(error_tag); }
}

// "//~^^^ kind msg" denotes a message expected
Expand Down
18 changes: 9 additions & 9 deletions src/compiletest/header.rs
Expand Up @@ -31,8 +31,8 @@ fn load_props(testfile: ~str) -> test_props {
let mut pp_exact = option::none;
for iter_header(testfile) |ln| {
alt parse_error_pattern(ln) {
option::some(ep) { vec::push(error_patterns, ep) }
option::none { }
option::some(ep) => vec::push(error_patterns, ep),
option::none => ()
};

if option::is_none(compile_flags) {
Expand Down Expand Up @@ -108,17 +108,17 @@ fn parse_exec_env(line: ~str) -> option<(~str, ~str)> {
// nv is either FOO or FOO=BAR
let strs = str::splitn_char(nv, '=', 1u);
alt strs.len() {
1u { (strs[0], ~"") }
2u { (strs[0], strs[1]) }
n { fail fmt!{"Expected 1 or 2 strings, not %u", n}; }
1u => (strs[0], ~""),
2u => (strs[0], strs[1]),
n => fail fmt!{"Expected 1 or 2 strings, not %u", n}
}
}
}

fn parse_pp_exact(line: ~str, testfile: ~str) -> option<~str> {
alt parse_name_value_directive(line, ~"pp-exact") {
option::some(s) { option::some(s) }
option::none {
option::some(s) => option::some(s),
option::none => {
if parse_name_directive(line, ~"pp-exact") {
option::some(path::basename(testfile))
} else {
Expand All @@ -136,12 +136,12 @@ fn parse_name_value_directive(line: ~str,
directive: ~str) -> option<~str> unsafe {
let keycolon = directive + ~":";
alt str::find_str(line, keycolon) {
option::some(colon) {
option::some(colon) => {
let value = str::slice(line, colon + str::len(keycolon),
str::len(line));
debug!{"%s: %s", directive, value};
option::some(value)
}
option::none { option::none }
option::none => option::none
}
}
4 changes: 2 additions & 2 deletions src/compiletest/procsrv.rs
Expand Up @@ -75,10 +75,10 @@ fn run(lib_path: ~str,
while count > 0 {
let stream = comm::recv(p);
alt check stream {
(1, s) {
(1, s) => {
outs = s;
}
(2, s) {
(2, s) => {
errs = s;
}
};
Expand Down
22 changes: 11 additions & 11 deletions src/compiletest/runtest.rs
Expand Up @@ -19,10 +19,10 @@ fn run(config: config, testfile: ~str) {
debug!{"running %s", testfile};
let props = load_props(testfile);
alt config.mode {
mode_compile_fail { run_cfail_test(config, props, testfile); }
mode_run_fail { run_rfail_test(config, props, testfile); }
mode_run_pass { run_rpass_test(config, props, testfile); }
mode_pretty { run_pretty_test(config, props, testfile); }
mode_compile_fail => run_cfail_test(config, props, testfile),
mode_run_fail => run_rfail_test(config, props, testfile),
mode_run_pass => run_rpass_test(config, props, testfile),
mode_pretty => run_pretty_test(config, props, testfile)
}
}

Expand Down Expand Up @@ -90,7 +90,7 @@ fn run_pretty_test(config: config, props: test_props, testfile: ~str) {
} else { logv(config, ~"testing for converging pretty-printing"); }

let rounds =
alt props.pp_exact { option::some(_) { 1 } option::none { 2 } };
alt props.pp_exact { option::some(_) => 1, option::none => 2 };

let mut srcs = ~[result::get(io::read_whole_file_str(testfile))];

Expand All @@ -110,11 +110,11 @@ fn run_pretty_test(config: config, props: test_props, testfile: ~str) {

let mut expected =
alt props.pp_exact {
option::some(file) {
option::some(file) => {
let filepath = path::connect(path::dirname(testfile), file);
result::get(io::read_whole_file_str(filepath))
}
option::none { srcs[vec::len(srcs) - 2u] }
option::none => { srcs[vec::len(srcs) - 2u] }
};
let mut actual = srcs[vec::len(srcs) - 1u];

Expand Down Expand Up @@ -384,8 +384,8 @@ fn make_run_args(config: config, _props: test_props, testfile: ~str) ->
// then split apart its command
let runtool =
alt config.runtool {
option::some(s) { option::some(s) }
option::none { option::none }
option::some(s) => option::some(s),
option::none => option::none
};
split_maybe_args(runtool)
};
Expand All @@ -403,8 +403,8 @@ fn split_maybe_args(argstr: option<~str>) -> ~[~str] {
}

alt argstr {
option::some(s) { rm_whitespace(str::split_char(s, ' ')) }
option::none { ~[] }
option::some(s) => rm_whitespace(str::split_char(s, ' ')),
option::none => ~[]
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/compiletest/util.rs
Expand Up @@ -8,10 +8,10 @@ fn make_new_path(path: ~str) -> ~str {
// Windows just uses PATH as the library search path, so we have to
// maintain the current value while adding our own
alt getenv(lib_path_env_var()) {
option::some(curr) {
option::some(curr) => {
fmt!{"%s%s%s", path, path_div(), curr}
}
option::none { path }
option::none => path
}
}

Expand Down
76 changes: 38 additions & 38 deletions src/fuzzer/fuzzer.rs
Expand Up @@ -63,39 +63,39 @@ pure fn safe_to_steal_expr(e: @ast::expr, tm: test_mode) -> bool {

pure fn safe_to_use_expr(e: ast::expr, tm: test_mode) -> bool {
alt tm {
tm_converge {
tm_converge => {
alt e.node {
// If the fuzzer moves a block-ending-in-semicolon into callee
// position, the pretty-printer can't preserve this even by
// parenthesizing!! See email to marijn.
ast::expr_if(_, _, _) { false }
ast::expr_block(_) { false }
ast::expr_alt(_, _, _) { false }
ast::expr_while(_, _) { false }
ast::expr_if(_, _, _) => { false }
ast::expr_block(_) => { false }
ast::expr_alt(_, _, _) => { false }
ast::expr_while(_, _) => { false }

// https://github.com/mozilla/rust/issues/929
ast::expr_cast(_, _) { false }
ast::expr_assert(_) { false }
ast::expr_binary(_, _, _) { false }
ast::expr_assign(_, _) { false }
ast::expr_assign_op(_, _, _) { false }
ast::expr_cast(_, _) => { false }
ast::expr_assert(_) => { false }
ast::expr_binary(_, _, _) => { false }
ast::expr_assign(_, _) => { false }
ast::expr_assign_op(_, _, _) => { false }

ast::expr_fail(option::none) { false }
ast::expr_ret(option::none) { false }
ast::expr_fail(option::none) => { false }
ast::expr_ret(option::none) => { false }

// https://github.com/mozilla/rust/issues/953
ast::expr_fail(option::some(_)) { false }
ast::expr_fail(option::some(_)) => { false }

// https://github.com/mozilla/rust/issues/928
//ast::expr_cast(_, _) { false }

// https://github.com/mozilla/rust/issues/1458
ast::expr_call(_, _, _) { false }
ast::expr_call(_, _, _) => { false }

_ { true }
_ => { true }
}
}
tm_run { true }
tm_run => { true }
}
}

Expand Down Expand Up @@ -141,23 +141,23 @@ fn steal(crate: ast::crate, tm: test_mode) -> stolen_stuff {
fn safe_to_replace_expr(e: ast::expr_, _tm: test_mode) -> bool {
alt e {
// https://github.com/mozilla/rust/issues/652
ast::expr_if(*) { false }
ast::expr_block(_) { false }
ast::expr_if(*) => { false }
ast::expr_block(_) => { false }

// expr_call is also missing a constraint
ast::expr_fn_block(*) { false }
ast::expr_fn_block(*) => { false }

_ { true }
_ => { true }
}
}

fn safe_to_replace_ty(t: ast::ty_, _tm: test_mode) -> bool {
alt t {
ast::ty_infer { false } // always implicit, always top level
ast::ty_bot { false } // in source, can only appear
ast::ty_infer => { false } // always implicit, always top level
ast::ty_bot => { false } // in source, can only appear
// as the out type of a function
ast::ty_mac(_) { false }
_ { true }
ast::ty_mac(_) => { false }
_ => { true }
}
}

Expand Down Expand Up @@ -273,10 +273,10 @@ fn check_variants_T<T: copy>(
pprust::no_ann(),
false));
alt cx.mode {
tm_converge {
tm_converge => {
check_roundtrip_convergence(str3, 1u);
}
tm_run {
tm_run => {
let file_label = fmt!{"rusttmp/%s_%s_%u_%u",
last_part(filename),
thing_label, i, j};
Expand Down Expand Up @@ -315,17 +315,17 @@ fn check_whole_compiler(code: ~str, suggested_filename_prefix: ~str,
let compile_result = check_compiling(filename);

let run_result = alt (compile_result, allow_running) {
(passed, true) { check_running(suggested_filename_prefix) }
(h, _) { h }
(passed, true) => { check_running(suggested_filename_prefix) }
(h, _) => { h }
};

alt run_result {
passed | cleanly_rejected(_) | known_bug(_) {
passed | cleanly_rejected(_) | known_bug(_) => {
removeIfExists(suggested_filename_prefix);
removeIfExists(suggested_filename_prefix + ~".rs");
removeDirIfExists(suggested_filename_prefix + ~".dSYM");
}
failed(s) {
failed(s) => {
log(error, ~"check_whole_compiler failure: " + s);
log(error, ~"Saved as: " + filename);
}
Expand Down Expand Up @@ -365,17 +365,17 @@ fn check_running(exe_filename: ~str) -> happiness {
failed(~"Mentioned malloc")
} else {
alt p.status {
0 { passed }
100 { cleanly_rejected(~"running: explicit fail") }
101 | 247 { cleanly_rejected(~"running: timed out") }
245 | 246 | 138 | 252 {
0 => { passed }
100 => { cleanly_rejected(~"running: explicit fail") }
101 | 247 => { cleanly_rejected(~"running: timed out") }
245 | 246 | 138 | 252 => {
known_bug(~"https://github.com/mozilla/rust/issues/1466")
}
136 | 248 {
136 | 248 => {
known_bug(
~"SIGFPE - https://github.com/mozilla/rust/issues/944")
}
rc {
rc => {
failed(~"Rust program ran but exited with status " +
int::str(rc))
}
Expand Down Expand Up @@ -442,8 +442,8 @@ fn has_raw_pointers(c: ast::crate) -> bool {
let has_rp = @mut false;
fn visit_ty(flag: @mut bool, t: @ast::ty) {
alt t.node {
ast::ty_ptr(_) { *flag = true; }
_ { }
ast::ty_ptr(_) => { *flag = true; }
_ => { }
}
}
let v =
Expand Down
6 changes: 3 additions & 3 deletions src/libcore/bool.rs
Expand Up @@ -40,9 +40,9 @@ pure fn is_false(v: bool) -> bool { !v }
/// Parse logic value from `s`
pure fn from_str(s: ~str) -> option<bool> {
alt check s {
~"true" { some(true) }
~"false" { some(false) }
_ { none }
~"true" => some(true),
~"false" => some(false),
_ => none
}
}

Expand Down

0 comments on commit 025d866

Please sign in to comment.