diff options
| author | Brian Anderson <banderson@mozilla.com> | 2012-08-03 19:59:04 -0700 |
|---|---|---|
| committer | Brian Anderson <banderson@mozilla.com> | 2012-08-05 22:08:09 -0700 |
| commit | 025d86624de982cdab7e6b13600fec1499c02b56 (patch) | |
| tree | 96ba196f8a420c52e6034acd14f323d3d2239e29 /src | |
| parent | c9d27693796fe4ced8568e11aa465750f743097b (diff) | |
| download | rust-025d86624de982cdab7e6b13600fec1499c02b56.tar.gz rust-025d86624de982cdab7e6b13600fec1499c02b56.zip | |
Switch alts to use arrows
Diffstat (limited to 'src')
329 files changed, 8097 insertions, 8425 deletions
diff --git a/src/cargo/cargo.rs b/src/cargo/cargo.rs index 4e836aad569..33482679920 100644 --- a/src/cargo/cargo.rs +++ b/src/cargo/cargo.rs @@ -129,22 +129,22 @@ fn is_uuid(id: ~str) -> bool { } alt i { - 0u { + 0u => { if str::len(part) == 8u { correct += 1u; } } - 1u | 2u | 3u { + 1u | 2u | 3u => { if str::len(part) == 4u { correct += 1u; } } - 4u { + 4u => { if str::len(part) == 12u { correct += 1u; } } - _ { } + _ => { } } } if correct >= 5u { @@ -193,8 +193,8 @@ fn is_archive_url(u: ~str) -> bool { // url parsing, we wouldn't need it alt str::find_str(u, ~"://") { - option::some(i) { has_archive_extension(u) } - _ { false } + option::some(i) => has_archive_extension(u), + _ => false } } @@ -224,15 +224,15 @@ fn load_link(mis: ~[@ast::meta_item]) -> (option<~str>, let mut uuid = none; for mis.each |a| { alt a.node { - ast::meta_name_value(v, {node: ast::lit_str(s), span: _}) { + ast::meta_name_value(v, {node: ast::lit_str(s), span: _}) => { alt *v { - ~"name" { name = some(*s); } - ~"vers" { vers = some(*s); } - ~"uuid" { uuid = some(*s); } - _ { } + ~"name" => name = some(*s), + ~"vers" => vers = some(*s), + ~"uuid" => uuid = some(*s), + _ => { } } } - _ { fail ~"load_link: meta items must be name-values"; } + _ => fail ~"load_link: meta items must be name-values" } } (name, vers, uuid) @@ -251,15 +251,15 @@ fn load_crate(filename: ~str) -> option<crate> { for c.node.attrs.each |a| { alt a.node.value.node { - ast::meta_name_value(v, {node: ast::lit_str(s), span: _}) { + ast::meta_name_value(v, {node: ast::lit_str(s), span: _}) => { alt *v { - ~"desc" { desc = some(*v); } - ~"sigs" { sigs = some(*v); } - ~"crate_type" { crate_type = some(*v); } - _ { } + ~"desc" => desc = some(*v), + ~"sigs" => sigs = some(*v), + ~"crate_type" => crate_type = some(*v), + _ => { } } } - ast::meta_list(v, mis) { + ast::meta_list(v, mis) => { if *v == ~"link" { let (n, v, u) = load_link(mis); name = n; @@ -267,7 +267,7 @@ fn load_crate(filename: ~str) -> option<crate> { uuid = u; } } - _ { + _ => { fail ~"crate attributes may not contain " + ~"meta_words"; } @@ -280,7 +280,7 @@ fn load_crate(filename: ~str) -> option<crate> { fn goto_view_item(e: env, i: @ast::view_item) { alt i.node { - ast::view_item_use(ident, metas, id) { + ast::view_item_use(ident, metas, id) => { let name_items = attr::find_meta_items_by_name(metas, ~"name"); let m = if name_items.is_empty() { @@ -294,16 +294,16 @@ fn load_crate(filename: ~str) -> option<crate> { for m.each |item| { alt attr::get_meta_item_value_str(item) { - some(value) { + some(value) => { let name = attr::get_meta_item_name(item); alt *name { - ~"vers" { attr_vers = *value; } - ~"from" { attr_from = *value; } - _ {} + ~"vers" => attr_vers = *value, + ~"from" => attr_from = *value, + _ => () } } - none {} + none => () } } @@ -316,11 +316,11 @@ fn load_crate(filename: ~str) -> option<crate> { }; alt *attr_name { - ~"std" | ~"core" { } - _ { vec::push(e.deps, query); } + ~"std" | ~"core" => (), + _ => vec::push(e.deps, query) } } - _ { } + _ => () } } fn goto_item(_e: env, _i: @ast::item) { @@ -340,7 +340,7 @@ fn load_crate(filename: ~str) -> option<crate> { let deps = copy e.deps; alt (name, vers, uuid) { - (some(name0), some(vers0), some(uuid0)) { + (some(name0), some(vers0), some(uuid0)) => { some({ name: name0, vers: vers0, @@ -350,7 +350,7 @@ fn load_crate(filename: ~str) -> option<crate> { crate_type: crate_type, deps: deps }) } - _ { return none; } + _ => return none } } @@ -391,30 +391,22 @@ fn parse_source(name: ~str, j: json::json) -> source { } alt j { - json::dict(j) { + json::dict(j) => { let mut url = alt j.find(~"url") { - some(json::string(u)) { - *u - } - _ { fail ~"needed 'url' field in source"; } + some(json::string(u)) => *u, + _ => fail ~"needed 'url' field in source" }; let method = alt j.find(~"method") { - some(json::string(u)) { - *u - } - _ { assume_source_method(url) } + some(json::string(u)) => *u, + _ => assume_source_method(url) }; let key = alt j.find(~"key") { - some(json::string(u)) { - some(*u) - } - _ { none } + some(json::string(u)) => some(*u), + _ => none }; let keyfp = alt j.find(~"keyfp") { - some(json::string(u)) { - some(*u) - } - _ { none } + some(json::string(u)) => some(*u), + _ => none }; if method == ~"file" { url = os::make_absolute(url); @@ -427,7 +419,7 @@ fn parse_source(name: ~str, j: json::json) -> source { mut keyfp: keyfp, mut packages: ~[mut] }; } - _ { fail ~"needed dict value in source"; } + _ => fail ~"needed dict value in source" }; } @@ -435,20 +427,20 @@ fn try_parse_sources(filename: ~str, sources: map::hashmap<~str, source>) { if !os::path_exists(filename) { return; } let c = io::read_whole_file_str(filename); alt json::from_str(result::get(c)) { - ok(json::dict(j)) { + ok(json::dict(j)) => { for j.each |k, v| { sources.insert(k, parse_source(k, v)); debug!{"source: %s", k}; } } - ok(_) { fail ~"malformed sources.json"; } - err(e) { fail fmt!{"%s:%s", filename, e.to_str()}; } + ok(_) => fail ~"malformed sources.json", + err(e) => fail fmt!{"%s:%s", filename, e.to_str()} } } fn load_one_source_package(src: source, p: map::hashmap<~str, json::json>) { let name = alt p.find(~"name") { - some(json::string(n)) { + some(json::string(n)) => { if !valid_pkg_name(*n) { warn(~"malformed source json: " + src.name + ~", '" + *n + ~"'"+ @@ -458,14 +450,14 @@ fn load_one_source_package(src: source, p: map::hashmap<~str, json::json>) { } *n } - _ { + _ => { warn(~"malformed source json: " + src.name + ~" (missing name)"); return; } }; let uuid = alt p.find(~"uuid") { - some(json::string(n)) { + some(json::string(n)) => { if !is_uuid(*n) { warn(~"malformed source json: " + src.name + ~", '" + *n + ~"'"+ @@ -474,23 +466,23 @@ fn load_one_source_package(src: source, p: map::hashmap<~str, json::json>) { } *n } - _ { + _ => { warn(~"malformed source json: " + src.name + ~" (missing uuid)"); return; } }; let url = alt p.find(~"url") { - some(json::string(n)) { *n } - _ { + some(json::string(n)) => *n, + _ => { warn(~"malformed source json: " + src.name + ~" (missing url)"); return; } }; let method = alt p.find(~"method") { - some(json::string(n)) { *n } - _ { + some(json::string(n)) => *n, + _ => { warn(~"malformed source json: " + src.name + ~" (missing method)"); return; @@ -498,26 +490,26 @@ fn load_one_source_package(src: source, p: map::hashmap<~str, json::json>) { }; let reference = alt p.find(~"ref") { - some(json::string(n)) { some(*n) } - _ { none } + some(json::string(n)) => some(*n), + _ => none }; let mut tags = ~[]; alt p.find(~"tags") { - some(json::list(js)) { + some(json::list(js)) => { for (*js).each |j| { alt j { - json::string(j) { vec::grow(tags, 1u, *j); } - _ { } + json::string(j) => vec::grow(tags, 1u, *j), + _ => () } } } - _ { } + _ => () } let description = alt p.find(~"description") { - some(json::string(n)) { *n } - _ { + some(json::string(n)) => *n, + _ => { warn(~"malformed source json: " + src.name + ~" (missing description)"); return; @@ -536,11 +528,11 @@ fn load_one_source_package(src: source, p: map::hashmap<~str, json::json>) { }; alt vec::position(src.packages, |pkg| pkg.uuid == uuid) { - some(idx) { + some(idx) => { src.packages[idx] = newpkg; log(debug, ~" updated package: " + src.name + ~"/" + name); } - none { + none => { vec::grow(src.packages, 1u, newpkg); } } @@ -554,17 +546,17 @@ fn load_source_info(c: cargo, src: source) { if !os::path_exists(srcfile) { return; } let srcstr = io::read_whole_file_str(srcfile); alt json::from_str(result::get(srcstr)) { - ok(json::dict(s)) { + ok(json::dict(s)) => { let o = parse_source(src.name, json::dict(s)); src.key = o.key; src.keyfp = o.keyfp; } - ok(_) { + ok(_) => { warn(~"malformed source.json: " + src.name + ~"(source info is not a dict)"); } - err(e) { + err(e) => { warn(fmt!{"%s:%s", src.name, e.to_str()}); } }; @@ -576,24 +568,24 @@ fn load_source_packages(c: cargo, src: source) { if !os::path_exists(pkgfile) { return; } let pkgstr = io::read_whole_file_str(pkgfile); alt json::from_str(result::get(pkgstr)) { - ok(json::list(js)) { + ok(json::list(js)) => { for (*js).each |j| { alt j { - json::dict(p) { + json::dict(p) => { load_one_source_package(src, p); } - _ { + _ => { warn(~"malformed source json: " + src.name + ~" (non-dict pkg)"); } } } } - ok(_) { + ok(_) => { warn(~"malformed packages.json: " + src.name + ~"(packages is not a list)"); } - err(e) { + err(e) => { warn(fmt!{"%s:%s", src.name, e.to_str()}); } }; @@ -601,8 +593,8 @@ fn load_source_packages(c: cargo, src: source) { fn build_cargo_options(argv: ~[~str]) -> options { let matches = alt getopts::getopts(argv, opts()) { - result::ok(m) { m } - result::err(f) { + result::ok(m) => m, + result::err(f) => { fail fmt!{"%s", getopts::fail_str(f)}; } }; @@ -632,14 +624,14 @@ fn build_cargo_options(argv: ~[~str]) -> options { fn configure(opts: options) -> cargo { let home = alt get_cargo_root() { - ok(home) { home } - err(_err) { result::get(get_cargo_sysroot()) } + ok(home) => home, + err(_err) => result::get(get_cargo_sysroot()) }; let get_cargo_dir = alt opts.mode { - system_mode { get_cargo_sysroot } - user_mode { get_cargo_root } - local_mode { get_cargo_root_nearest } + system_mode => get_cargo_sysroot, + user_mode => get_cargo_root, + local_mode => get_cargo_root_nearest }; let p = result::get(get_cargo_dir()); @@ -726,8 +718,8 @@ fn run_in_buildpath(what: ~str, path: ~str, subdir: ~str, cf: ~str, fn test_one_crate(_c: cargo, path: ~str, cf: ~str) { let buildpath = alt run_in_buildpath(~"testing", path, ~"/test", cf, ~[ ~"--test"]) { - none { return; } - some(bp) { bp } + none => return, + some(bp) => bp }; run_programs(buildpath); } @@ -735,8 +727,8 @@ fn test_one_crate(_c: cargo, path: ~str, cf: ~str) { fn install_one_crate(c: cargo, path: ~str, cf: ~str) { let buildpath = alt run_in_buildpath(~"installing", path, ~"/build", cf, ~[]) { - none { return; } - some(bp) { bp } + none => return, + some(bp) => bp }; let newv = os::list_dir_path(buildpath); let exec_suffix = os::exe_suffix(); @@ -761,13 +753,13 @@ fn install_one_crate(c: cargo, path: ~str, cf: ~str) { fn rustc_sysroot() -> ~str { alt os::self_exe_path() { - some(path) { + some(path) => { let path = ~[path, ~"..", ~"bin", ~"rustc"]; let rustc = path::normalize(path::connect_many(path)); debug!{" rustc: %s", rustc}; rustc } - none { ~"rustc" } + none => ~"rustc" } } @@ -788,8 +780,8 @@ fn install_source(c: cargo, path: ~str) { for cratefiles.each |cf| { alt load_crate(cf) { - none { again; } - some(crate) { + none => again, + some(crate) => { for crate.deps.each |query| { // FIXME (#1356): handle cyclic dependencies // (n.b. #1356 says "Cyclic dependency is an error @@ -797,8 +789,8 @@ fn install_source(c: cargo, path: ~str) { let wd_base = c.workdir + path::path_sep(); let wd = alt tempfile::mkdtemp(wd_base, ~"") { - some(wd) { wd } - none { fail fmt!{"needed temp dir: %s", wd_base}; } + some(wd) => wd, + none => fail fmt!{"needed temp dir: %s", wd_base} }; install_query(c, wd, query); @@ -847,18 +839,18 @@ fn install_file(c: cargo, wd: ~str, path: ~str) { fn install_package(c: cargo, src: ~str, wd: ~str, pkg: package) { let url = copy pkg.url; let method = alt pkg.method { - ~"git" { ~"git" } - ~"file" { ~"file" } - _ { ~"curl" } + ~"git" => ~"git", + ~"file" => ~"file", + _ => ~"curl" }; info(fmt!{"installing %s/%s via %s...", src, pkg.name, method}); alt method { - ~"git" { install_git(c, wd, url, copy pkg.reference); } - ~"file" { install_file(c, wd, url); } - ~"curl" { install_curl(c, wd, copy url); } - _ {} + ~"git" => install_git(c, wd, url, copy pkg.reference), + ~"file" => install_file(c, wd, url), + ~"curl" => install_curl(c, wd, copy url), + _ => () } } @@ -922,7 +914,7 @@ fn install_named(c: cargo, wd: ~str, name: ~str) { fn install_uuid_specific(c: cargo, wd: ~str, src: ~str, uuid: ~str) { alt c.sources.find(src) { - some(s) { + some(s) => { let packages = copy s.packages; if vec::any(packages, |p| { if p.uuid == uuid { @@ -931,14 +923,14 @@ fn install_uuid_specific(c: cargo, wd: ~str, src: ~str, uuid: ~str) { } else { false } }) { return; } } - _ { } + _ => () } error(~"can't find package: " + src + ~"/" + uuid); } fn install_named_specific(c: cargo, wd: ~str, src: ~str, name: ~str) { alt c.sources.find(src) { - some(s) { + some(s) => { let packages = copy s.packages; if vec::any(packages, |p| { if p.name == name { @@ -947,7 +939,7 @@ fn install_named_specific(c: cargo, wd: ~str, src: ~str, name: ~str) { } else { false } }) { return; } } - _ { } + _ => () } error(~"can't find package: " + src + ~"/" + name); } @@ -969,7 +961,7 @@ fn cmd_uninstall(c: cargo) { if is_uuid(target) { for os::list_dir(lib).each |file| { alt str::find_str(file, ~"-" + target + ~"-") { - some(idx) { + some(idx) => { let full = path::normalize(path::connect(lib, file)); if os::remove_file(full) { info(~"uninstalled: '" + full + ~"'"); @@ -978,7 +970,7 @@ fn cmd_uninstall(c: cargo) { } return; } - none { again; } + none => again } } @@ -986,7 +978,7 @@ fn cmd_uninstall(c: cargo) { } else { for os::list_dir(lib).each |file| { alt str::find_str(file, ~"lib" + target + ~"-") { - some(idx) { + some(idx) => { let full = path::normalize(path::connect(lib, file)); if os::remove_file(full) { @@ -996,12 +988,12 @@ fn cmd_uninstall(c: cargo) { } return; } - none { again; } + none => again } } for os::list_dir(bin).each |file| { alt str::find_str(file, target) { - some(idx) { + some(idx) => { let full = path::normalize(path::connect(bin, file)); if os::remove_file(full) { info(~"uninstalled: '" + full + ~"'"); @@ -1010,7 +1002,7 @@ fn cmd_uninstall(c: cargo) { } return; } - none { again; } + none => again } } @@ -1020,12 +1012,12 @@ fn cmd_uninstall(c: cargo) { fn install_query(c: cargo, wd: ~str, target: ~str) { alt c.dep_cache.find(target) { - some(inst) { + some(inst) => { if inst { return; } } - none {} + none => () } c.dep_cache.insert(target, true); @@ -1047,7 +1039,7 @@ fn install_query(c: cargo, wd: ~str, target: ~str) { let mut ps = copy target; alt str::find_char(ps, '/') { - option::some(idx) { + option::some(idx) => { let source = str::slice(ps, 0u, idx); ps = str::slice(ps, idx + 1u, str::len(ps)); if is_uuid(ps) { @@ -1056,7 +1048,7 @@ fn install_query(c: cargo, wd: ~str, target: ~str) { install_named_specific(c, wd, source, ps); } } - option::none { + option::none => { if is_uuid(ps) { install_uuid(c, wd, ps); } else { @@ -1081,8 +1073,8 @@ fn install_query(c: cargo, wd: ~str, target: ~str) { fn cmd_install(c: cargo) unsafe { let wd_base = c.workdir + path::path_sep(); let wd = alt tempfile::mkdtemp(wd_base, ~"") { - some(wd) { wd } - none { fail fmt!{"needed temp dir: %s", wd_base}; } + some(wd) => wd, + none => fail fmt!{"needed temp dir: %s", wd_base} }; if vec::len(c.opts.free) == 2u { @@ -1138,7 +1130,7 @@ fn sync_one_file(c: cargo, dir: ~str, src: source) -> bool { os::copy_file(path::connect(url, ~"packages.json.sig"), sigfile); alt copy src.key { - some(u) { + some(u) => { let p = run::program_output(~"curl", ~[~"-f", ~"-s", ~"-o", keyfile, u]); if p.status != 0 { @@ -1147,10 +1139,10 @@ fn sync_one_file(c: cargo, dir: ~str, src: source) -> bool { } pgp::add(c.root, keyfile); } - _ { } + _ => () } alt (src.key, src.keyfp) { - (some(_), some(f)) { + (some(_), some(f)) => { let r = pgp::verify(c.root, pkgfile, sigfile, f); if !r { @@ -1169,7 +1161,7 @@ fn sync_one_file(c: cargo, dir: ~str, src: source) -> bool { } } } - _ {} + _ => () } copy_warn(pkgfile, destpkgfile); @@ -1247,7 +1239,7 @@ fn sync_one_git(c: cargo, dir: ~str, src: source) -> bool { let has_src_file = os::path_exists(srcfile); alt copy src.key { - some(u) { + some(u) => { let p = run::program_output(~"curl", ~[~"-f", ~"-s", ~"-o", keyfile, u]); if p.status != 0 { @@ -1257,10 +1249,10 @@ fn sync_one_git(c: cargo, dir: ~str, src: source) -> bool { } pgp::add(c.root, keyfile); } - _ { } + _ => () } alt (src.key, src.keyfp) { - (some(_), some(f)) { + (some(_), some(f)) => { let r = pgp::verify(c.root, pkgfile, sigfile, f); if !r { @@ -1281,7 +1273,7 @@ fn sync_one_git(c: cargo, dir: ~str, src: source) -> bool { } } } - _ {} + _ => () } os::remove_file(keyfile); @@ -1327,7 +1319,7 @@ fn sync_one_curl(c: cargo, dir: ~str, src: source) -> bool { } alt copy src.key { - some(u) { + some(u) => { let p = run::program_output(~"curl", ~[~"-f", ~"-s", ~"-o", keyfile, u]); if p.status != 0 { @@ -1336,10 +1328,10 @@ fn sync_one_curl(c: cargo, dir: ~str, src: source) -> bool { } pgp::add(c.root, keyfile); } - _ { } + _ => () } alt (src.key, src.keyfp) { - (some(_), some(f)) { + (some(_), some(f)) => { if smart { url = src.url + ~"/packages.json.sig"; } @@ -1383,7 +1375,7 @@ fn sync_one_curl(c: cargo, dir: ~str, src: source) -> bool { } } } - _ {} + _ => () } copy_warn(pkgfile, destpkgfile); @@ -1412,9 +1404,9 @@ fn sync_one(c: cargo, src: source) { need_dir(dir); let result = alt src.method { - ~"git" { sync_one_git(c, dir, src) } - ~"file" { sync_one_file(c, dir, src) } - _ { sync_one_curl(c, dir, src) } + ~"git" => sync_one_git(c, dir, src), + ~"file" => sync_one_file(c, dir, src), + _ => sync_one_curl(c, dir, src) }; if result { @@ -1499,10 +1491,10 @@ fn cmd_list(c: cargo) { error(fmt!{"'%s' is an invalid source name", name}); } else { alt c.sources.find(name) { - some(source) { + some(source) => { print_source(source); } - none { + none => { error(fmt!{"no such source: %s", name}); } } @@ -1571,7 +1563,7 @@ fn dump_sources(c: cargo) { } alt io::buffered_file_writer(out) { - result::ok(writer) { + result::ok(writer) => { let hash = map::str_hash(); let root = json::dict(hash); @@ -1583,16 +1575,16 @@ fn dump_sources(c: cargo) { chash.insert(~"method", json::string(@v.method)); alt copy v.key { - some(key) { + some(key) => { chash.insert(~"key", json::string(@key)); } - _ {} + _ => () } alt copy v.keyfp { - some(keyfp) { + some(keyfp) => { chash.insert(~"keyfp", json::string(@keyfp)); } - _ {} + _ => () } hash.insert(k, child); @@ -1600,7 +1592,7 @@ fn dump_sources(c: cargo) { writer.write_str(json::to_str(root)); } - result::err(e) { + result::err(e) => { error(fmt!{"could not dump sources: %s", e}); } } @@ -1624,14 +1616,14 @@ fn cmd_sources(c: cargo) { let action = c.opts.free[2u]; alt action { - ~"clear" { + ~"clear" => { for c.sources.each_key |k| { c.sources.remove(k); } info(~"cleared sources"); } - ~"add" { + ~"add" => { if vec::len(c.opts.free) < 5u { cmd_usage(); return; @@ -1646,10 +1638,10 @@ fn cmd_sources(c: cargo) { } alt c.sources.find(name) { - some(source) { + some(source) => { error(fmt!{"source already exists: %s", name}); } - none { + none => { c.sources.insert(name, @{ name: name, mut url: url, @@ -1662,7 +1654,7 @@ fn cmd_sources(c: cargo) { } } } - ~"remove" { + ~"remove" => { if vec::len(c.opts.free) < 4u { cmd_usage(); return; @@ -1676,16 +1668,16 @@ fn cmd_sources(c: cargo) { } alt c.sources.find(name) { - some(source) { + some(source) => { c.sources.remove(name); info(fmt!{"removed source: %s", name}); } - none { + none => { error(fmt!{"no such source: %s", name}); } } } - ~"set-url" { + ~"set-url" => { if vec::len(c.opts.free) < 5u { cmd_usage(); return; @@ -1700,7 +1692,7 @@ fn cmd_sources(c: cargo) { } alt c.sources.find(name) { - some(source) { + some(source) => { let old = copy source.url; let method = assume_source_method(url); @@ -1711,12 +1703,12 @@ fn cmd_sources(c: cargo) { info(fmt!{"changed source url: '%s' to '%s'", old, url}); } - none { + none => { error(fmt!{"no such source: %s", name}); } } } - ~"set-method" { + ~"set-method" => { if vec::len(c.opts.free) < 5u { cmd_usage(); return; @@ -1731,13 +1723,13 @@ fn cmd_sources(c: cargo) { } alt c.sources.find(name) { - some(source) { + some(source) => { let old = copy source.method; source.method = alt method { - ~"git" { ~"git" } - ~"file" { ~"file" } - _ { ~"curl" } + ~"git" => ~"git", + ~"file" => ~"file", + _ => ~"curl" }; c.sources.insert(name, source); @@ -1745,12 +1737,12 @@ fn cmd_sources(c: cargo) { info(fmt!{"changed source method: '%s' to '%s'", old, method}); } - none { + none => { error(fmt!{"no such source: %s", name}); } } } - ~"rename" { + ~"rename" => { if vec::len(c.opts.free) < 5u { cmd_usage(); return; @@ -1769,17 +1761,17 @@ fn cmd_sources(c: cargo) { } alt c.sources.find(name) { - some(source) { + some(source) => { c.sources.remove(name); c.sources.insert(newn, source); info(fmt!{"renamed source: %s to %s", name, newn}); } - none { + none => { error(fmt!{"no such source: %s", name}); } } } - _ { cmd_usage(); } + _ => cmd_usage() } } @@ -1883,13 +1875,13 @@ fn main(argv: ~[~str]) { } if o.help { alt o.free[1] { - ~"init" { cmd_usage_init(); } - ~"install" { cmd_usage_install(); } - ~"uninstall" { cmd_usage_uninstall(); } - ~"list" { cmd_usage_list(); } - ~"search" { cmd_usage_search(); } - ~"sources" { cmd_usage_sources(); } - _ { cmd_usage(); } + ~"init" => cmd_usage_init(), + ~"install" => cmd_usage_install(), + ~"uninstall" => cmd_usage_uninstall(), + ~"list" => cmd_usage_list(), + ~"search" => cmd_usage_search(), + ~"sources" => cmd_usage_sources(), + _ => cmd_usage() } return; } @@ -1910,13 +1902,13 @@ fn main(argv: ~[~str]) { } alt o.free[1] { - ~"init" { cmd_init(c); } - ~"install" { cmd_install(c); } - ~"uninstall" { cmd_uninstall(c); } - ~"list" { cmd_list(c); } - ~"search" { cmd_search(c); } - ~"sources" { cmd_sources(c); } - _ { cmd_usage(); } + ~"init" => cmd_init(c), + ~"install" => cmd_install(c), + ~"uninstall" => cmd_uninstall(c), + ~"list" => cmd_list(c), + ~"search" => cmd_search(c), + ~"sources" => cmd_sources(c), + _ => cmd_usage() } dump_cache(c); diff --git a/src/compiletest/compiletest.rs b/src/compiletest/compiletest.rs index 4fc88009bc6..39c4f0f81d0 100644 --- a/src/compiletest/compiletest.rs +++ b/src/compiletest/compiletest.rs @@ -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"), @@ -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> { @@ -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" } } @@ -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 } } } @@ -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); diff --git a/src/compiletest/errors.rs b/src/compiletest/errors.rs index 431843d9268..8a550e94c78 100644 --- a/src/compiletest/errors.rs +++ b/src/compiletest/errors.rs @@ -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 diff --git a/src/compiletest/header.rs b/src/compiletest/header.rs index ec214f5b586..731e874ddcc 100644 --- a/src/compiletest/header.rs +++ b/src/compiletest/header.rs @@ -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) { @@ -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 { @@ -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 } } diff --git a/src/compiletest/procsrv.rs b/src/compiletest/procsrv.rs index 1a642915cd5..bb9080becff 100644 --- a/src/compiletest/procsrv.rs +++ b/src/compiletest/procsrv.rs @@ -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; } }; diff --git a/src/compiletest/runtest.rs b/src/compiletest/runtest.rs index ac5c3161c47..79b7e6f08d4 100644 --- a/src/compiletest/runtest.rs +++ b/src/compiletest/runtest.rs @@ -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) } } @@ -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))]; @@ -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]; @@ -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) }; @@ -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 => ~[] } } diff --git a/src/compiletest/util.rs b/src/compiletest/util.rs index fec0fc84bc3..027d247ebb8 100644 --- a/src/compiletest/util.rs +++ b/src/compiletest/util.rs @@ -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 } } diff --git a/src/fuzzer/fuzzer.rs b/src/fuzzer/fuzzer.rs index 39f33b732d8..1cc0c08eb5c 100644 --- a/src/fuzzer/fuzzer.rs +++ b/src/fuzzer/fuzzer.rs @@ -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 } } } @@ -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 } } } @@ -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}; @@ -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); } @@ -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)) } @@ -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 = diff --git a/src/libcore/bool.rs b/src/libcore/bool.rs index 83e7ebec860..91b268bc703 100644 --- a/src/libcore/bool.rs +++ b/src/libcore/bool.rs @@ -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 } } diff --git a/src/libcore/char.rs b/src/libcore/char.rs index 5849d19d8c1..97a484b491f 100644 --- a/src/libcore/char.rs +++ b/src/libcore/char.rs @@ -114,10 +114,10 @@ pure fn is_digit(c: char) -> bool { */ pure fn to_digit(c: char, radix: uint) -> option<uint> { let val = alt c { - '0' to '9' { c as uint - ('0' as uint) } - 'a' to 'z' { c as uint + 10u - ('a' as uint) } - 'A' to 'Z' { c as uint + 10u - ('A' as uint) } - _ { return none; } + '0' to '9' => c as uint - ('0' as uint), + 'a' to 'z' => c as uint + 10u - ('a' as uint), + 'A' to 'Z' => c as uint + 10u - ('A' as uint), + _ => return none }; if val < radix { some(val) } else { none } @@ -159,14 +159,14 @@ fn escape_unicode(c: char) -> ~str { */ fn escape_default(c: char) -> ~str { alt c { - '\t' { ~"\\t" } - '\r' { ~"\\r" } - '\n' { ~"\\n" } - '\\' { ~"\\\\" } - '\'' { ~"\\'" } - '"' { ~"\\\"" } - '\x20' to '\x7e' { str::from_char(c) } - _ { escape_unicode(c) } + '\t' => ~"\\t", + '\r' => ~"\\r", + '\n' => ~"\\n", + '\\' => ~"\\\\", + '\'' => ~"\\'", + '"' => ~"\\\"", + '\x20' to '\x7e' => str::from_char(c), + _ => escape_unicode(c) } } diff --git a/src/libcore/comm.rs b/src/libcore/comm.rs index fd1067241a8..86bcfad89dd 100644 --- a/src/libcore/comm.rs +++ b/src/libcore/comm.rs @@ -410,8 +410,8 @@ fn test_select2_stress() { let mut bs = 0; for iter::repeat(msgs * times * 2u) { alt check select2(po_a, po_b) { - either::left(~"a") { as += 1 } - either::right(~"b") { bs += 1 } + either::left(~"a") => as += 1, + either::right(~"b") => bs += 1 } } diff --git a/src/libcore/dlist.rs b/src/libcore/dlist.rs index ae75c04da72..7b9d4432e54 100644 --- a/src/libcore/dlist.rs +++ b/src/libcore/dlist.rs @@ -27,30 +27,22 @@ enum dlist<T> = @{ impl private_methods<T> for dlist_node<T> { pure fn assert_links() { alt self.next { - some(neighbour) { - alt neighbour.prev { - some(me) { - if !box::ptr_eq(*self, *me) { - fail ~"Asymmetric next-link in dlist node." - } - } - none { fail ~"One-way next-link in dlist node." } - } + some(neighbour) => alt neighbour.prev { + some(me) => if !box::ptr_eq(*self, *me) { + fail ~"Asymmetric next-link in dlist node." + } + none => fail ~"One-way next-link in dlist node." } - none { } + none => () } alt self.prev { - some(neighbour) { - alt neighbour.next { - some(me) { - if !box::ptr_eq(*me, *self) { - fail ~"Asymmetric prev-link in dlist node." - } - } - none { fail ~"One-way prev-link in dlist node." } - } + some(neighbour) => alt neighbour.next { + some(me) => if !box::ptr_eq(*me, *self) { + fail ~"Asymmetric prev-link in dlist node." + } + none => fail ~"One-way prev-link in dlist node." } - none { } + none => () } } } @@ -64,8 +56,8 @@ impl extensions<T> for dlist_node<T> { /// Get the next node in the list, failing if there isn't one. pure fn next_node() -> dlist_node<T> { alt self.next_link() { - some(nobe) { nobe } - none { fail ~"This dlist node has no next neighbour." } + some(nobe) => nobe, + none => fail ~"This dlist node has no next neighbour." } } /// Get the previous node in the list, if there is one. @@ -76,8 +68,8 @@ impl extensions<T> for dlist_node<T> { /// Get the previous node in the list, failing if there isn't one. pure fn prev_node() -> dlist_node<T> { alt self.prev_link() { - some(nobe) { nobe } - none { fail ~"This dlist node has no previous neighbour." } + some(nobe) => nobe, + none => fail ~"This dlist node has no previous neighbour." } } } @@ -147,12 +139,12 @@ impl private_methods<T> for dlist<T> { #[inline(always)] fn link(+before: dlist_link<T>, +after: dlist_link<T>) { alt before { - some(neighbour) { neighbour.next = after; } - none { self.hd = after; } + some(neighbour) => neighbour.next = after, + none => self.hd = after } alt after { - some(neighbour) { neighbour.prev = before; } - none { self.tl = before; } + some(neighbour) => neighbour.prev = before, + none => self.tl = before } } // Remove a node from the list. @@ -295,19 +287,15 @@ impl extensions<T> for dlist<T> { /// Get the node at the list's head, failing if empty. O(1). pure fn head_n() -> dlist_node<T> { alt self.hd { - some(nobe) { nobe } - none { - fail ~"Attempted to get the head of an empty dlist." - } + some(nobe) => nobe, + none => fail ~"Attempted to get the head of an empty dlist." } } /// Get the node at the list's tail, failing if empty. O(1). pure fn tail_n() -> dlist_node<T> { alt self.tl { - some(nobe) { nobe } - none { - fail ~"Attempted to get the tail of an empty dlist." - } + some(nobe) => nobe, + none => fail ~"Attempted to get the tail of an empty dlist." } } diff --git a/src/libcore/either.rs b/src/libcore/either.rs index 64a7abd0f35..d07b126bb5d 100644 --- a/src/libcore/either.rs +++ b/src/libcore/either.rs @@ -18,7 +18,10 @@ fn either<T, U, V>(f_left: fn(T) -> V, * result is returned. */ - alt value { left(l) { f_left(l) } right(r) { f_right(r) } } + alt value { + left(l) => f_left(l), + right(r) => f_right(r) + } } fn lefts<T: copy, U>(eithers: ~[either<T, U>]) -> ~[T] { @@ -26,7 +29,10 @@ fn lefts<T: copy, U>(eithers: ~[either<T, U>]) -> ~[T] { let mut result: ~[T] = ~[]; for vec::each(eithers) |elt| { - alt elt { left(l) { vec::push(result, l); } _ {/* fallthrough */ } } + alt elt { + left(l) => vec::push(result, l), + _ => { /* fallthrough */ } + } } return result; } @@ -36,7 +42,10 @@ fn rights<T, U: copy>(eithers: ~[either<T, U>]) -> ~[U] { let mut result: ~[U] = ~[]; for vec::each(eithers) |elt| { - alt elt { right(r) { vec::push(result, r); } _ {/* fallthrough */ } } + alt elt { + right(r) => vec::push(result, r), + _ => { /* fallthrough */ } + } } return result; } @@ -54,8 +63,8 @@ fn partition<T: copy, U: copy>(eithers: ~[either<T, U>]) let mut rights: ~[U] = ~[]; for vec::each(eithers) |elt| { alt elt { - left(l) { vec::push(lefts, l); } - right(r) { vec::push(rights, r); } + left(l) => vec::push(lefts, l), + right(r) => vec::push(rights, r) } } return {lefts: lefts, rights: rights}; @@ -65,8 +74,8 @@ pure fn flip<T: copy, U: copy>(eith: either<T, U>) -> either<U, T> { //! Flips between left and right of a given either alt eith { - right(r) { left(r) } - left(l) { right(l) } + right(r) => left(r), + left(l) => right(l) } } @@ -80,21 +89,21 @@ pure fn to_result<T: copy, U: copy>( */ alt eith { - right(r) { result::ok(r) } - left(l) { result::err(l) } + right(r) => result::ok(r), + left(l) => result::err(l) } } pure fn is_left<T, U>(eith: either<T, U>) -> bool { //! Checks whether the given value is a left - alt eith { left(_) { true } _ { false } } + alt eith { left(_) => true, _ => false } } pure fn is_right<T, U>(eith: either<T, U>) -> bool { //! Checks whether the given value is a right - alt eith { right(_) { true } _ { false } } + alt eith { right(_) => true, _ => false } } #[test] diff --git a/src/libcore/extfmt.rs b/src/libcore/extfmt.rs index 49313295edc..251bc2d18e1 100644 --- a/src/libcore/extfmt.rs +++ b/src/libcore/extfmt.rs @@ -123,8 +123,8 @@ mod ct { if !('0' as u8 <= c && c <= '9' as u8) { return option::none; } let n = (c - ('0' as u8)) as uint; return alt peek_num(s, i + 1u, lim) { - none { some({num: n, next: i + 1u}) } - some(next) { + none => some({num: n, next: i + 1u}), + some(next) => { let m = next.num; let j = next.next; some({num: n * 10u + m, next: j}) @@ -151,8 +151,8 @@ mod ct { if i >= lim { return {param: none, next: i}; } let num = peek_num(s, i, lim); return alt num { - none { {param: none, next: i} } - some(t) { + none => {param: none, next: i}, + some(t) => { let n = t.num; let j = t.next; if j < lim && s[j] == '$' as u8 { @@ -196,15 +196,16 @@ mod ct { let param = parse_parameter(s, i + 1u, lim); let j = param.next; alt param.param { - none { {count: count_is_next_param, next: j} } - some(n) { {count: count_is_param(n), next: j} } + none => {count: count_is_next_param, next: j}, + some(n) => {count: count_is_param(n), next: j} } } else { let num = peek_num(s, i, lim); alt num { - none { {count: count_implied, next: i} } - some(num) { - {count: count_is(num.num as int), next: num.next} + none => {count: count_implied, next: i}, + some(num) => { + count: count_is(num.num as int), + next: num.next } } }; @@ -220,8 +221,8 @@ mod ct { // If there were no digits specified, i.e. the precision // was ".", then the precision is 0 alt count.count { - count_implied { {count: count_is(0), next: count.next} } - _ { count } + count_implied => {count: count_is(0), next: count.next}, + _ => count } } else { {count: count_implied, next: i} }; } @@ -294,11 +295,11 @@ mod rt { let prec = get_int_precision(cv); let mut rs = alt cv.ty { - ty_default { uint_to_str_prec(u, 10u, prec) } - ty_hex_lower { uint_to_str_prec(u, 16u, prec) } - ty_hex_upper { str::to_upper(uint_to_str_prec(u, 16u, prec)) } - ty_bits { uint_to_str_prec(u, 2u, prec) } - ty_octal { uint_to_str_prec(u, 8u, prec) } + ty_default => uint_to_str_prec(u, 10u, prec), + ty_hex_lower => uint_to_str_prec(u, 16u, prec), + ty_hex_upper => str::to_upper(uint_to_str_prec(u, 16u, prec)), + ty_bits => uint_to_str_prec(u, 2u, prec), + ty_octal => uint_to_str_prec(u, 8u, prec) }; return unchecked { pad(cv, rs, pad_unsigned) }; } @@ -316,19 +317,19 @@ mod rt { // For strings, precision is the maximum characters // displayed let mut unpadded = alt cv.precision { - count_implied { s.to_unique() } - count_is(max) { - if max as uint < str::char_len(s) { - str::substr(s, 0u, max as uint) - } else { s.to_unique() } + count_implied => s.to_unique(), + count_is(max) => if max as uint < str::char_len(s) { + str::substr(s, 0u, max as uint) + } else { + s.to_unique() } }; return unchecked { pad(cv, unpadded, pad_nozero) }; } pure fn conv_float(cv: conv, f: float) -> ~str { let (to_str, digits) = alt cv.precision { - count_is(c) { (float::to_str_exact, c as uint) } - count_implied { (float::to_str, 6u) } + count_is(c) => (float::to_str_exact, c as uint), + count_implied => (float::to_str, 6u) }; let mut s = unchecked { to_str(f, digits) }; if 0.0 <= f { @@ -371,15 +372,15 @@ mod rt { } pure fn get_int_precision(cv: conv) -> uint { return alt cv.precision { - count_is(c) { c as uint } - count_implied { 1u } + count_is(c) => c as uint, + count_implied => 1u }; } enum pad_mode { pad_signed, pad_unsigned, pad_nozero, pad_float } fn pad(cv: conv, &s: ~str, mode: pad_mode) -> ~str { let uwidth : uint = alt cv.width { - count_implied { return s; } - count_is(width) { + count_implied => return s, + count_is(width) => { // FIXME: width should probably be uint (see Issue #1996) width as uint } @@ -393,13 +394,13 @@ mod rt { return s + padstr; } let {might_zero_pad, signed} = alt mode { - pad_nozero { {might_zero_pad:false, signed:false} } - pad_signed { {might_zero_pad:true, signed:true } } - pad_float { {might_zero_pad:true, signed:true } } - pad_unsigned { {might_zero_pad:true, signed:false} } + pad_nozero => {might_zero_pad:false, signed:false}, + pad_signed => {might_zero_pad:true, signed:true }, + pad_float => {might_zero_pad:true, signed:true}, + pad_unsigned => {might_zero_pad:true, signed:false} }; pure fn have_precision(cv: conv) -> bool { - return alt cv.precision { count_implied { false } _ { true } }; + return alt cv.precision { count_implied => false, _ => true }; } let zero_padding = { if might_zero_pad && have_flag(cv.flags, flag_left_zero_pad) && diff --git a/src/libcore/float.rs b/src/libcore/float.rs index e9dd26d23ce..02133205be9 100644 --- a/src/libcore/float.rs +++ b/src/libcore/float.rs @@ -257,21 +257,21 @@ fn from_str(num: ~str) -> option<float> { //The string must start with one of the following characters. alt str::char_at(num, 0u) { - '-' | '+' | '0' to '9' | '.' {} - _ { return none; } + '-' | '+' | '0' to '9' | '.' => (), + _ => return none } //Determine if first char is '-'/'+'. Set [pos] and [neg] accordingly. let mut neg = false; //Sign of the result alt str::char_at(num, 0u) { - '-' { + '-' => { neg = true; pos = 1u; } - '+' { + '+' => { pos = 1u; } - _ {} + _ => () } //Examine the following chars until '.', 'e', 'E' @@ -280,16 +280,12 @@ fn from_str(num: ~str) -> option<float> { c = char_range.ch; pos = char_range.next; alt c { - '0' to '9' { + '0' to '9' => { total = total * 10f; total += ((c as int) - ('0' as int)) as float; } - '.' | 'e' | 'E' { - break; - } - _ { - return none; - } + '.' | 'e' | 'E' => break, + _ => return none } } @@ -300,16 +296,12 @@ fn from_str(num: ~str) -> option<float> { c = char_range.ch; pos = char_range.next; alt c { - '0' | '1' | '2' | '3' | '4' | '5' | '6'| '7' | '8' | '9' { + '0' | '1' | '2' | '3' | '4' | '5' | '6'| '7' | '8' | '9' => { decimal /= 10f; total += (((c as int) - ('0' as int)) as float)*decimal; } - 'e' | 'E' { - break; - } - _ { - return none; - } + 'e' | 'E' => break, + _ => return none } } } @@ -321,26 +313,24 @@ fn from_str(num: ~str) -> option<float> { let char_range = str::char_range_at(num, pos); c = char_range.ch; alt c { - '+' { + '+' => { pos = char_range.next; } - '-' { + '-' => { pos = char_range.next; neg_exponent = true; } - _ {} + _ => () } while(pos < len) { let char_range = str::char_range_at(num, pos); c = char_range.ch; alt c { - '0' | '1' | '2' | '3' | '4' | '5' | '6'| '7' | '8' | '9' { + '0' | '1' | '2' | '3' | '4' | '5' | '6'| '7' | '8' | '9' => { exponent *= 10u; exponent += ((c as uint) - ('0' as uint)); } - _ { - break; - } + _ => break } pos = char_range.next; } @@ -458,8 +448,8 @@ fn test_from_str() { assert from_str(~"-inf") == some(neg_infinity); // note: NaN != NaN, hence this slightly complex test alt from_str(~"NaN") { - some(f) { assert is_NaN(f); } - none { fail; } + some(f) => assert is_NaN(f), + none => fail } assert from_str(~"") == none; diff --git a/src/libcore/future.rs b/src/libcore/future.rs index 43b0a4047b6..1f6b259c467 100644 --- a/src/libcore/future.rs +++ b/src/libcore/future.rs @@ -78,7 +78,7 @@ fn from_port<A:send>(-port: future_pipe::client::waiting<A>) -> future<A> { port_ <-> *port; let port = option::unwrap(port_); alt recv(port) { - future_pipe::completed(data) { move_it!{data} } + future_pipe::completed(data) => move_it!{data} } } } @@ -120,8 +120,8 @@ fn with<A,B>(future: future<A>, blk: fn(A) -> B) -> B { //! Work with the value without copying it let v = alt copy future.v { - either::left(v) { v } - either::right(f) { + either::left(v) => v, + either::right(f) => { let v = @f(); future.v = either::left(v); v diff --git a/src/libcore/int-template.rs b/src/libcore/int-template.rs index 1cd1480ec43..02ef14c5366 100644 --- a/src/libcore/int-template.rs +++ b/src/libcore/int-template.rs @@ -145,8 +145,8 @@ fn parse_buf(buf: ~[u8], radix: uint) -> option<T> { let mut n = 0 as T; loop { alt char::to_digit(buf[i] as char, radix) { - some(d) { n += (d as T) * power; } - none { return none; } + some(d) => n += (d as T) * power, + none => return none } power *= radix as T; if i <= start { return some(n); } diff --git a/src/libcore/io.rs b/src/libcore/io.rs index c20aaf14530..cf2c51625d8 100644 --- a/src/libcore/io.rs +++ b/src/libcore/io.rs @@ -197,9 +197,9 @@ impl reader_util for reader { fn convert_whence(whence: seek_style) -> i32 { return alt whence { - seek_set { 0i32 } - seek_cur { 1i32 } - seek_end { 2i32 } + seek_set => 0i32, + seek_cur => 1i32, + seek_end => 2i32 }; } @@ -441,10 +441,10 @@ fn mk_file_writer(path: ~str, flags: ~[fileflag]) let mut fflags: c_int = wb(); for vec::each(flags) |f| { alt f { - append { fflags |= O_APPEND as c_int; } - create { fflags |= O_CREAT as c_int; } - truncate { fflags |= O_TRUNC as c_int; } - no_flag { } + append => fflags |= O_APPEND as c_int, + create => fflags |= O_CREAT as c_int, + truncate => fflags |= O_TRUNC as c_int, + no_flag => () } } let fd = do os::as_c_charp(path) |pathbuf| { @@ -461,22 +461,22 @@ fn mk_file_writer(path: ~str, flags: ~[fileflag]) fn u64_to_le_bytes<T>(n: u64, size: uint, f: fn(v: &[u8]) -> T) -> T { assert size <= 8u; alt size { - 1u { f(&[n as u8]) } - 2u { f(&[n as u8, - (n >> 8) as u8]) } - 4u { f(&[n as u8, + 1u => f(&[n as u8]), + 2u => f(&[n as u8, + (n >> 8) as u8]), + 4u => f(&[n as u8, (n >> 8) as u8, (n >> 16) as u8, - (n >> 24) as u8]) } - 8u { f(&[n as u8, + (n >> 24) as u8]), + 8u => f(&[n as u8, (n >> 8) as u8, (n >> 16) as u8, (n >> 24) as u8, (n >> 32) as u8, (n >> 40) as u8, (n >> 48) as u8, - (n >> 56) as u8]) } - _ { + (n >> 56) as u8]), + _ => { let mut bytes: ~[u8] = ~[], i = size, n = n; while i > 0u { @@ -492,22 +492,22 @@ fn u64_to_le_bytes<T>(n: u64, size: uint, f: fn(v: &[u8]) -> T) -> T { fn u64_to_be_bytes<T>(n: u64, size: uint, f: fn(v: &[u8]) -> T) -> T { assert size <= 8u; alt size { - 1u { f(&[n as u8]) } - 2u { f(&[(n >> 8) as u8, - n as u8]) } - 4u { f(&[(n >> 24) as u8, + 1u => f(&[n as u8]), + 2u => f(&[(n >> 8) as u8, + n as u8]), + 4u => f(&[(n >> 24) as u8, (n >> 16) as u8, (n >> 8) as u8, - n as u8]) } - 8u { f(&[(n >> 56) as u8, + n as u8]), + 8u => f(&[(n >> 56) as u8, (n >> 48) as u8, (n >> 40) as u8, (n >> 32) as u8, (n >> 24) as u8, (n >> 16) as u8, (n >> 8) as u8, - n as u8]) } - _ { + n as u8]), + _ => { let mut bytes: ~[u8] = ~[]; let mut i = size; while i > 0u { @@ -718,9 +718,9 @@ fn seek_in_buf(offset: int, pos: uint, len: uint, whence: seek_style) -> let mut bpos = pos as int; let blen = len as int; alt whence { - seek_set { bpos = offset; } - seek_cur { bpos += offset; } - seek_end { bpos = blen + offset; } + seek_set => bpos = offset, + seek_cur => bpos += offset, + seek_end => bpos = blen + offset } if bpos < 0 { bpos = 0; } else if bpos > blen { bpos = blen; } return bpos as uint; @@ -768,8 +768,8 @@ mod fsync { new(-arg: arg<t>) { self.arg <- arg; } drop { alt self.arg.opt_level { - option::none { } - option::some(level) { + option::none => (), + option::some(level) => { // fail hard if not succesful assert(self.arg.fsync_fn(self.arg.val, level) != -1); } @@ -892,30 +892,30 @@ mod tests { #[test] fn file_reader_not_exist() { alt io::file_reader(~"not a file") { - result::err(e) { + result::err(e) => { assert e == ~"error opening not a file"; } - result::ok(_) { fail; } + result::ok(_) => fail } } #[test] fn file_writer_bad_name() { alt io::file_writer(~"?/?", ~[]) { - result::err(e) { + result::err(e) => { assert str::starts_with(e, ~"error opening ?/?"); } - result::ok(_) { fail; } + result::ok(_) => fail } } #[test] fn buffered_file_writer_bad_name() { alt io::buffered_file_writer(~"?/?") { - result::err(e) { + result::err(e) => { assert e == ~"error opening ?/?"; } - result::ok(_) { fail; } + result::ok(_) => fail } } diff --git a/src/libcore/iter-trait/option.rs b/src/libcore/iter-trait/option.rs index 87763b273da..a150afa36e1 100644 --- a/src/libcore/iter-trait/option.rs +++ b/src/libcore/iter-trait/option.rs @@ -2,14 +2,14 @@ type IMPL_T<A> = option<A>; pure fn EACH<A>(self: IMPL_T<A>, f: fn(A) -> bool) { alt self { - none { } - some(a) { f(a); } + none => (), + some(a) => { f(a); } } } fn SIZE_HINT<A>(self: IMPL_T<A>) -> option<uint> { alt self { - none { some(0u) } - some(_) { some(1u) } + none => some(0u), + some(_) => some(1u) } } diff --git a/src/libcore/iter.rs b/src/libcore/iter.rs index 0e635eeb002..541c19aa3a5 100644 --- a/src/libcore/iter.rs +++ b/src/libcore/iter.rs @@ -136,32 +136,32 @@ fn repeat(times: uint, blk: fn() -> bool) { fn min<A:copy,IA:base_iter<A>>(self: IA) -> A { alt do foldl::<A,option<A>,IA>(self, none) |a, b| { alt a { - some(a_) if a_ < b { + some(a_) if a_ < b => { // FIXME (#2005): Not sure if this is successfully optimized to // a move a } - _ { some(b) } + _ => some(b) } } { - some(val) { val } - none { fail ~"min called on empty iterator" } + some(val) => val, + none => fail ~"min called on empty iterator" } } fn max<A:copy,IA:base_iter<A>>(self: IA) -> A { alt do foldl::<A,option<A>,IA>(self, none) |a, b| { alt a { - some(a_) if a_ > b { + some(a_) if a_ > b => { // FIXME (#2005): Not sure if this is successfully optimized to // a move. a } - _ { some(b) } + _ => some(b) } } { - some(val) { val } - none { fail ~"max called on empty iterator" } + some(val) => val, + none => fail ~"max called on empty iterator" } } diff --git a/src/libcore/option.rs b/src/libcore/option.rs index 935d22fbaae..b2ae670ec05 100644 --- a/src/libcore/option.rs +++ b/src/libcore/option.rs @@ -23,7 +23,10 @@ pure fn get<T: copy>(opt: option<T>) -> T { * Fails if the value equals `none` */ - alt opt { some(x) { return x; } none { fail ~"option::get none"; } } + alt opt { + some(x) => return x, + none => fail ~"option::get none" + } } pure fn expect<T: copy>(opt: option<T>, reason: ~str) -> T { @@ -34,13 +37,13 @@ pure fn expect<T: copy>(opt: option<T>, reason: ~str) -> T { Fails if the value equals `none` "]; - alt opt { some(x) { x } none { fail reason; } } + alt opt { some(x) => x, none => fail reason } } pure fn map<T, U>(opt: option<T>, f: fn(T) -> U) -> option<U> { //! Maps a `some` value from one type to another - alt opt { some(x) { some(f(x)) } none { none } } + alt opt { some(x) => some(f(x)), none => none } } pure fn map_consume<T, U>(-opt: option<T>, f: fn(-T) -> U) -> option<U> { @@ -57,7 +60,7 @@ pure fn chain<T, U>(opt: option<T>, f: fn(T) -> option<U>) -> option<U> { * function that returns an option. */ - alt opt { some(x) { f(x) } none { none } } + alt opt { some(x) => f(x), none => none } } #[inline(always)] @@ -73,7 +76,7 @@ pure fn while_some<T>(+x: option<T>, blk: fn(+T) -> option<T>) { pure fn is_none<T>(opt: option<T>) -> bool { //! Returns true if the option equals `none` - alt opt { none { true } some(_) { false } } + alt opt { none => true, some(_) => false } } pure fn is_some<T>(opt: option<T>) -> bool { @@ -85,19 +88,19 @@ pure fn is_some<T>(opt: option<T>) -> bool { pure fn get_default<T: copy>(opt: option<T>, def: T) -> T { //! Returns the contained value or a default - alt opt { some(x) { x } none { def } } + alt opt { some(x) => x, none => def } } pure fn map_default<T, U>(opt: option<T>, +def: U, f: fn(T) -> U) -> U { //! Applies a function to the contained value or returns a default - alt opt { none { def } some(t) { f(t) } } + alt opt { none => def, some(t) => f(t) } } pure fn iter<T>(opt: option<T>, f: fn(T)) { //! Performs an operation on the contained value or does nothing - alt opt { none { } some(t) { f(t); } } + alt opt { none => (), some(t) => f(t) } } #[inline(always)] @@ -111,8 +114,8 @@ pure fn unwrap<T>(-opt: option<T>) -> T { unsafe { let addr = alt opt { - some(x) { ptr::addr_of(x) } - none { fail ~"option::unwrap none" } + some(x) => ptr::addr_of(x), + none => fail ~"option::unwrap none" }; let liberated_value = unsafe::reinterpret_cast(*addr); unsafe::forget(opt); diff --git a/src/libcore/os.rs b/src/libcore/os.rs index a2e3ca02bc3..fba4e7acac5 100644 --- a/src/libcore/os.rs +++ b/src/libcore/os.rs @@ -179,18 +179,16 @@ mod global_env { do priv::weaken_task |weak_po| { loop { alt comm::select2(msg_po, weak_po) { - either::left(msg_getenv(n, resp_ch)) { + either::left(msg_getenv(n, resp_ch)) => { comm::send(resp_ch, impl::getenv(n)) } - either::left(msg_setenv(n, v, resp_ch)) { + either::left(msg_setenv(n, v, resp_ch)) => { comm::send(resp_ch, impl::setenv(n, v)) } - either::left(msg_env(resp_ch)) { + either::left(msg_env(resp_ch)) => { comm::send(resp_ch, impl::env()) } - either::right(_) { - break; - } + either::right(_) => break } } } @@ -286,8 +284,8 @@ fn fsync_fd(fd: c_int, level: io::fsync::level) -> c_int { import libc::funcs::posix01::unistd::*; alt level { io::fsync::fsync - | io::fsync::fullfsync { return fsync(fd); } - io::fsync::fdatasync { return fdatasync(fd); } + | io::fsync::fullfsync => return fsync(fd), + io::fsync::fdatasync => return fdatasync(fd) } } @@ -297,8 +295,8 @@ fn fsync_fd(fd: c_int, level: io::fsync::level) -> c_int { import libc::funcs::posix88::fcntl::*; import libc::funcs::posix01::unistd::*; alt level { - io::fsync::fsync { return fsync(fd); } - _ { + io::fsync::fsync => return fsync(fd), + _ => { // According to man fnctl, the ok retval is only specified to be !=-1 if (fcntl(F_FULLFSYNC as c_int, fd) == -1 as c_int) { return -1 as c_int; } @@ -443,16 +441,12 @@ fn self_exe_path() -> option<path> { */ fn homedir() -> option<path> { return alt getenv(~"HOME") { - some(p) { - if !str::is_empty(p) { - some(p) - } else { - secondary() - } - } - none { - secondary() + some(p) => if !str::is_empty(p) { + some(p) + } else { + secondary() } + none => secondary() }; #[cfg(unix)] diff --git a/src/libcore/path.rs b/src/libcore/path.rs index beccdcf0538..dc541b14a4b 100644 --- a/src/libcore/path.rs +++ b/src/libcore/path.rs @@ -64,11 +64,11 @@ fn split_dirname_basename (pp: path) -> {dirname: ~str, basename: ~str} { alt str::rfind(pp, |ch| ch == consts::path_sep || ch == consts::alt_path_sep ) { - some(i) { - {dirname: str::slice(pp, 0u, i), - basename: str::slice(pp, i + 1u, str::len(pp))} - } - none { {dirname: ~".", basename: pp} } + some(i) => { + dirname: str::slice(pp, 0u, i), + basename: str::slice(pp, i + 1u, str::len(pp)) + }, + none => {dirname: ~".", basename: pp} } } diff --git a/src/libcore/pipes.rs b/src/libcore/pipes.rs index af7f7983a8a..f13ee96768a 100644 --- a/src/libcore/pipes.rs +++ b/src/libcore/pipes.rs @@ -120,9 +120,9 @@ struct packet_header { assert self.state != blocked || self.blocked_task != none; self.blocked_task = none; alt swap_state_acq(self.state, empty) { - empty | blocked { } - terminated { self.state = terminated; } - full { self.state = full; } + empty | blocked => (), + terminated => self.state = terminated, + full => self.state = full } } @@ -310,27 +310,25 @@ fn send<T: send, Tbuffer: send>(-p: send_packet_buffered<T, Tbuffer>, p.payload <- some(payload); let old_state = swap_state_rel(p.header.state, full); alt old_state { - empty { + empty => { // Yay, fastpath. // The receiver will eventually clean this up. //unsafe { forget(p); } } - full { fail ~"duplicate send" } - blocked { + full => fail ~"duplicate send", + blocked => { debug!{"waking up task for %?", p_}; alt p.header.blocked_task { - some(task) { - rustrt::task_signal_event( - task, ptr::addr_of(p.header) as *libc::c_void); - } - none { debug!{"just kidding!"} } + some(task) => rustrt::task_signal_event( + task, ptr::addr_of(p.header) as *libc::c_void), + none => debug!{"just kidding!"} } // The receiver will eventually clean this up. //unsafe { forget(p); } } - terminated { + terminated => { // The receiver will never receive this. Rely on drop_glue // to clean everything up. } @@ -367,7 +365,7 @@ fn try_recv<T: send, Tbuffer: send>(-p: recv_packet_buffered<T, Tbuffer>) let old_state = swap_state_acq(p.header.state, blocked); alt old_state { - empty { + empty => { debug!{"no data available on %?, going to sleep.", p_}; if count == 0 { wait_event(this); @@ -383,19 +381,17 @@ fn try_recv<T: send, Tbuffer: send>(-p: recv_packet_buffered<T, Tbuffer>) } debug!{"woke up, p.state = %?", copy p.header.state}; } - blocked { - if first { - fail ~"blocking on already blocked packet" - } + blocked => if first { + fail ~"blocking on already blocked packet" } - full { + full => { let mut payload = none; payload <-> p.payload; p.header.blocked_task = none; p.header.state = empty; return some(option::unwrap(payload)) } - terminated { + terminated => { // This assert detects when we've accidentally unsafely // casted too big of a number to a state. assert old_state == terminated; @@ -409,9 +405,9 @@ fn try_recv<T: send, Tbuffer: send>(-p: recv_packet_buffered<T, Tbuffer>) /// Returns true if messages are available. pure fn peek<T: send, Tb: send>(p: recv_packet_buffered<T, Tb>) -> bool { alt unsafe {(*p.header()).state} { - empty { false } - blocked { fail ~"peeking on blocked packet" } - full | terminated { true } + empty => false, + blocked => fail ~"peeking on blocked packet", + full | terminated => true } } @@ -425,11 +421,11 @@ impl peek<T: send, Tb: send> for recv_packet_buffered<T, Tb> { fn sender_terminate<T: send>(p: *packet<T>) { let p = unsafe { &*p }; alt swap_state_rel(p.header.state, terminated) { - empty { + empty => { // The receiver will eventually clean up. //unsafe { forget(p) } } - blocked { + blocked => { // wake up the target alt p.header.blocked_task { some(target) => @@ -441,11 +437,11 @@ fn sender_terminate<T: send>(p: *packet<T>) { // The receiver will eventually clean up. //unsafe { forget(p) } } - full { + full => { // This is impossible fail ~"you dun goofed" } - terminated { + terminated => { // I have to clean up, use drop_glue } } @@ -456,15 +452,15 @@ fn receiver_terminate<T: send>(p: *packet<T>) { let p = unsafe { &*p }; assert p.header.blocked_task == none; alt swap_state_rel(p.header.state, terminated) { - empty { + empty => { // the sender will clean up //unsafe { forget(p) } } - blocked { + blocked => { // this shouldn't happen. fail ~"terminating a blocked packet" } - terminated | full { + terminated | full => { // I have to clean up, use drop_glue } } @@ -490,14 +486,14 @@ fn wait_many(pkts: &[*packet_header]) -> uint { let p = unsafe { &*p }; let old = p.mark_blocked(this); alt old { - full | terminated { + full | terminated => { data_avail = true; ready_packet = i; (*p).state = old; break; } - blocked { fail ~"blocking on blocked packet" } - empty { } + blocked => fail ~"blocking on blocked packet", + empty => () } } @@ -507,13 +503,11 @@ fn wait_many(pkts: &[*packet_header]) -> uint { let pos = vec::position(pkts, |p| p == event); alt pos { - some(i) { + some(i) => { ready_packet = i; data_avail = true; } - none { - debug!{"ignoring spurious event, %?", event}; - } + none => debug!{"ignoring spurious event, %?", event} } } @@ -569,9 +563,9 @@ fn select2<A: send, Ab: send, B: send, Bb: send>( unsafe { alt i { - 0 { left((try_recv(a), b)) } - 1 { right((a, try_recv(b))) } - _ { fail ~"select2 return an invalid packet" } + 0 => left((try_recv(a), b)), + 1 => right((a, try_recv(b))), + _ => fail ~"select2 return an invalid packet" } } } @@ -586,9 +580,9 @@ fn selecti<T: selectable>(endpoints: &[T]) -> uint { fn select2i<A: selectable, B: selectable>(a: A, b: B) -> either<(), ()> { alt wait_many([a.header(), b.header()]/_) { - 0 { left(()) } - 1 { right(()) } - _ { fail ~"wait returned unexpected index" } + 0 => left(()), + 1 => right(()), + _ => fail ~"wait returned unexpected index" } } @@ -655,15 +649,13 @@ struct send_packet_buffered<T: send, Tbuffer: send> { pure fn header() -> *packet_header { alt self.p { - some(packet) { - unsafe { - let packet = &*packet; - let header = ptr::addr_of(packet.header); - //forget(packet); - header - } + some(packet) => unsafe { + let packet = &*packet; + let header = ptr::addr_of(packet.header); + //forget(packet); + header } - none { fail ~"packet already consumed" } + none => fail ~"packet already consumed" } } @@ -718,15 +710,13 @@ struct recv_packet_buffered<T: send, Tbuffer: send> : selectable { pure fn header() -> *packet_header { alt self.p { - some(packet) { - unsafe { - let packet = &*packet; - let header = ptr::addr_of(packet.header); - //forget(packet); - header - } + some(packet) => unsafe { + let packet = &*packet; + let header = ptr::addr_of(packet.header); + //forget(packet); + header } - none { fail ~"packet already consumed" } + none => fail ~"packet already consumed" } } @@ -847,11 +837,11 @@ impl port<T: send> of recv<T> for port<T> { let mut endp = none; endp <-> self.endp; alt move pipes::try_recv(unwrap(endp)) { - some(streamp::data(x, endp)) { + some(streamp::data(x, endp)) => { self.endp = some(move_it!{endp}); some(move_it!{x}) } - none { none } + none => none } } @@ -859,10 +849,8 @@ impl port<T: send> of recv<T> for port<T> { let mut endp = none; endp <-> self.endp; let peek = alt endp { - some(endp) { - pipes::peek(endp) - } - none { fail ~"peeking empty stream" } + some(endp) => pipes::peek(endp), + none => fail ~"peeking empty stream" }; self.endp <-> endp; peek @@ -894,10 +882,10 @@ struct port_set<T: send> : recv<T> { while result == none && ports.len() > 0 { let i = wait_many(ports.map(|p| p.header())); alt move ports[i].try_recv() { - some(copy m) { + some(copy m) => { result = some(move m); } - none { + none => { // Remove this port. let mut ports_ = ~[]; ports <-> ports_; @@ -914,8 +902,8 @@ struct port_set<T: send> : recv<T> { fn recv() -> T { match move self.try_recv() { - some(copy x) { move x } - none { fail ~"port_set: endpoints closed" } + some(copy x) => move x, + none => fail ~"port_set: endpoints closed" } } @@ -932,10 +920,8 @@ struct port_set<T: send> : recv<T> { impl<T: send> of selectable for port<T> { pure fn header() -> *packet_header unchecked { alt self.endp { - some(endp) { - endp.header() - } - none { fail ~"peeking empty stream" } + some(endp) => endp.header(), + none => fail ~"peeking empty stream" } } } @@ -968,22 +954,18 @@ impl<T: send, U: send, Left: selectable recv<T>, Right: selectable recv<U>> fn select() -> either<T, U> { alt self { - (lp, rp) { - alt select2i(lp, rp) { - left(()) { left (lp.recv()) } - right(()) { right(rp.recv()) } - } + (lp, rp) => alt select2i(lp, rp) { + left(()) => left (lp.recv()), + right(()) => right(rp.recv()) } } } fn try_select() -> either<option<T>, option<U>> { alt self { - (lp, rp) { - alt select2i(lp, rp) { - left(()) { left (lp.try_recv()) } - right(()) { right(rp.try_recv()) } - } + (lp, rp) => alt select2i(lp, rp) { + left(()) => left (lp.try_recv()), + right(()) => right(rp.try_recv()) } } } @@ -999,8 +981,8 @@ mod test { c1.send(~"abc"); alt (p1, p2).select() { - right(_) { fail } - _ { } + right(_) => fail, + _ => () } c2.send(123); diff --git a/src/libcore/priv.rs b/src/libcore/priv.rs index 00bbe3d032a..5d7123f1bba 100644 --- a/src/libcore/priv.rs +++ b/src/libcore/priv.rs @@ -50,8 +50,8 @@ unsafe fn chan_from_global_ptr<T: send>( // Wait to hear if we are the official instance of // this global task alt comm::recv::<msg>(setup_po) { - proceed { f(po); } - abort { } + proceed => f(po), + abort => () } }; diff --git a/src/libcore/result.rs b/src/libcore/result.rs index 58a4c558050..a74ac589b93 100644 --- a/src/libcore/result.rs +++ b/src/libcore/result.rs @@ -19,9 +19,9 @@ enum result<T, U> { */ pure fn get<T: copy, U>(res: result<T, U>) -> T { alt res { - ok(t) { t } - err(the_err) { - unchecked{ fail fmt!{"get called on error result: %?", the_err}; } + ok(t) => t, + err(the_err) => unchecked { + fail fmt!{"get called on error result: %?", the_err} } } } @@ -35,18 +35,16 @@ pure fn get<T: copy, U>(res: result<T, U>) -> T { */ pure fn get_err<T, U: copy>(res: result<T, U>) -> U { alt res { - err(u) { u } - ok(_) { - fail ~"get_error called on ok result"; - } + err(u) => u, + ok(_) => fail ~"get_error called on ok result" } } /// Returns true if the result is `ok` pure fn is_ok<T, U>(res: result<T, U>) -> bool { alt res { - ok(_) { true } - err(_) { false } + ok(_) => true, + err(_) => false } } @@ -63,8 +61,8 @@ pure fn is_err<T, U>(res: result<T, U>) -> bool { */ pure fn to_either<T: copy, U: copy>(res: result<U, T>) -> either<T, U> { alt res { - ok(res) { either::right(res) } - err(fail_) { either::left(fail_) } + ok(res) => either::right(res), + err(fail_) => either::left(fail_) } } @@ -85,8 +83,8 @@ pure fn to_either<T: copy, U: copy>(res: result<U, T>) -> either<T, U> { fn chain<T, U: copy, V: copy>(res: result<T, V>, op: fn(T) -> result<U, V>) -> result<U, V> { alt res { - ok(t) { op(t) } - err(e) { err(e) } + ok(t) => op(t), + err(e) => err(e) } } @@ -103,8 +101,8 @@ fn chain_err<T: copy, U: copy, V: copy>( op: fn(V) -> result<T, U>) -> result<T, U> { alt res { - ok(t) { ok(t) } - err(v) { op(v) } + ok(t) => ok(t), + err(v) => op(v) } } @@ -124,8 +122,8 @@ fn chain_err<T: copy, U: copy, V: copy>( */ fn iter<T, E>(res: result<T, E>, f: fn(T)) { alt res { - ok(t) { f(t) } - err(_) { } + ok(t) => f(t), + err(_) => () } } @@ -139,8 +137,8 @@ fn iter<T, E>(res: result<T, E>, f: fn(T)) { */ fn iter_err<T, E>(res: result<T, E>, f: fn(E)) { alt res { - ok(_) { } - err(e) { f(e) } + ok(_) => (), + err(e) => f(e) } } @@ -161,8 +159,8 @@ fn iter_err<T, E>(res: result<T, E>, f: fn(E)) { fn map<T, E: copy, U: copy>(res: result<T, E>, op: fn(T) -> U) -> result<U, E> { alt res { - ok(t) { ok(op(t)) } - err(e) { err(e) } + ok(t) => ok(op(t)), + err(e) => err(e) } } @@ -177,8 +175,8 @@ fn map<T, E: copy, U: copy>(res: result<T, E>, op: fn(T) -> U) fn map_err<T: copy, E, F: copy>(res: result<T, E>, op: fn(E) -> F) -> result<T, F> { alt res { - ok(t) { ok(t) } - err(e) { err(op(e)) } + ok(t) => ok(t), + err(e) => err(op(e)) } } @@ -189,15 +187,15 @@ impl extensions<T, E> for result<T, E> { fn iter(f: fn(T)) { alt self { - ok(t) { f(t) } - err(_) { } + ok(t) => f(t), + err(_) => () } } fn iter_err(f: fn(E)) { alt self { - ok(_) { } - err(e) { f(e) } + ok(_) => (), + err(e) => f(e) } } } @@ -207,8 +205,8 @@ impl extensions<T:copy, E> for result<T, E> { fn map_err<F:copy>(op: fn(E) -> F) -> result<T,F> { alt self { - ok(t) { ok(t) } - err(e) { err(op(e)) } + ok(t) => ok(t), + err(e) => err(op(e)) } } } @@ -218,8 +216,8 @@ impl extensions<T, E:copy> for result<T, E> { fn map<U:copy>(op: fn(T) -> U) -> result<U,E> { alt self { - ok(t) { ok(op(t)) } - err(e) { err(e) } + ok(t) => ok(op(t)), + err(e) => err(e) } } } @@ -258,8 +256,8 @@ fn map_vec<T,U:copy,V:copy>( vec::reserve(vs, vec::len(ts)); for vec::each(ts) |t| { alt op(t) { - ok(v) { vec::push(vs, v); } - err(u) { return err(u); } + ok(v) => vec::push(vs, v), + err(u) => return err(u) } } return ok(vs); @@ -269,12 +267,10 @@ fn map_opt<T,U:copy,V:copy>( o_t: option<T>, op: fn(T) -> result<V,U>) -> result<option<V>,U> { alt o_t { - none { ok(none) } - some(t) { - alt op(t) { - ok(v) { ok(some(v)) } - err(e) { err(e) } - } + none => ok(none), + some(t) => alt op(t) { + ok(v) => ok(some(v)), + err(e) => err(e) } } } @@ -298,8 +294,8 @@ fn map_vec2<S,T,U:copy,V:copy>(ss: ~[S], ts: ~[T], let mut i = 0u; while i < n { alt op(ss[i],ts[i]) { - ok(v) { vec::push(vs, v); } - err(u) { return err(u); } + ok(v) => vec::push(vs, v), + err(u) => return err(u) } i += 1u; } @@ -319,8 +315,8 @@ fn iter_vec2<S,T,U:copy>(ss: ~[S], ts: ~[T], let mut i = 0u; while i < n { alt op(ss[i],ts[i]) { - ok(()) { } - err(u) { return err(u); } + ok(()) => (), + err(u) => return err(u) } i += 1u; } @@ -331,8 +327,8 @@ fn iter_vec2<S,T,U:copy>(ss: ~[S], ts: ~[T], fn unwrap<T, U>(-res: result<T, U>) -> T { unsafe { let addr = alt res { - ok(x) { ptr::addr_of(x) } - err(_) { fail ~"error result" } + ok(x) => ptr::addr_of(x), + err(_) => fail ~"error result" }; let liberated_value = unsafe::reinterpret_cast(*addr); unsafe::forget(res); diff --git a/src/libcore/run.rs b/src/libcore/run.rs index bb604d7748a..60527e786bd 100644 --- a/src/libcore/run.rs +++ b/src/libcore/run.rs @@ -97,7 +97,7 @@ fn with_envp<T>(env: option<~[(~str,~str)]>, // On posixy systems we can pass a char** for envp, which is // a null-terminated array of "k=v\n" strings. alt env { - some(es) if !vec::is_empty(es) { + some(es) if !vec::is_empty(es) => { let mut tmps = ~[]; let mut ptrs = ~[]; @@ -112,9 +112,7 @@ fn with_envp<T>(env: option<~[(~str,~str)]>, unsafe { cb(::unsafe::reinterpret_cast(p)) } ) } - _ { - cb(ptr::null()) - } + _ => cb(ptr::null()) } } @@ -126,7 +124,7 @@ fn with_envp<T>(env: option<~[(~str,~str)]>, // \0 to terminate. unsafe { alt env { - some(es) if !vec::is_empty(es) { + some(es) if !vec::is_empty(es) => { let mut blk : ~[u8] = ~[]; for vec::each(es) |e| { let (k,v) = e; @@ -138,9 +136,7 @@ fn with_envp<T>(env: option<~[(~str,~str)]>, blk += ~[0_u8]; vec::as_buf(blk, |p, _len| cb(::unsafe::reinterpret_cast(p))) } - _ { - cb(ptr::null()) - } + _ => cb(ptr::null()) } } } @@ -148,8 +144,8 @@ fn with_envp<T>(env: option<~[(~str,~str)]>, fn with_dirp<T>(d: option<~str>, cb: fn(*libc::c_char) -> T) -> T { alt d { - some(dir) { str::as_c_str(dir, cb) } - none { cb(ptr::null()) } + some(dir) => str::as_c_str(dir, cb), + none => cb(ptr::null()) } } @@ -314,10 +310,10 @@ fn program_output(prog: ~str, args: ~[~str]) -> while count > 0 { let stream = comm::recv(p); alt check stream { - (1, s) { + (1, s) => { outs = s; } - (2, s) { + (2, s) => { errs = s; } }; diff --git a/src/libcore/send_map.rs b/src/libcore/send_map.rs index f2976e67eeb..a242587a21c 100644 --- a/src/libcore/send_map.rs +++ b/src/libcore/send_map.rs @@ -116,14 +116,10 @@ mod linear { let _ = for self.bucket_sequence(hash) |i| { alt buckets[i] { - some(bkt) { - if bkt.hash == hash && self.eqfn(k, &bkt.key) { - return found_entry(i); - } - } - none => { - return found_hole(i); + some(bkt) => if bkt.hash == hash && self.eqfn(k, &bkt.key) { + return found_entry(i); } + none => return found_hole(i) } }; return table_full; @@ -162,7 +158,7 @@ mod linear { alt self.bucket_for_key_with_hash(self.buckets, hash, unsafe{borrow(k)}) { table_full => {fail ~"Internal logic error";} - found_hole(idx) { + found_hole(idx) => { debug!{"insert fresh (%?->%?) at idx %?, hash %?", k, v, idx, hash}; self.buckets[idx] = some({hash: hash, key: k, value: v}); diff --git a/src/libcore/str.rs b/src/libcore/str.rs index 0c58f425d7d..cec8ec52ee4 100644 --- a/src/libcore/str.rs +++ b/src/libcore/str.rs @@ -342,18 +342,16 @@ fn unshift_char(&s: ~str, ch: char) { s = from_char(ch) + s; } /// Returns a string with leading whitespace removed pure fn trim_left(s: &str) -> ~str { alt find(s, |c| !char::is_whitespace(c)) { - none { ~"" } - some(first) { - unsafe { unsafe::slice_bytes(s, first, len(s)) } - } + none => ~"", + some(first) => unsafe { unsafe::slice_bytes(s, first, len(s)) } } } /// Returns a string with trailing whitespace removed pure fn trim_right(s: &str) -> ~str { alt rfind(s, |c| !char::is_whitespace(c)) { - none { ~"" } - some(last) { + none => ~"", + some(last) => { let {next, _} = char_range_at(s, last); unsafe { unsafe::slice_bytes(s, 0u, next) } } @@ -2779,9 +2777,9 @@ mod tests { let mut i = 0; do chars_iter(~"x\u03c0y") |ch| { alt check i { - 0 { assert ch == 'x'; } - 1 { assert ch == '\u03c0'; } - 2 { assert ch == 'y'; } + 0 => assert ch == 'x', + 1 => assert ch == '\u03c0', + 2 => assert ch == 'y' } i += 1; } @@ -2795,9 +2793,9 @@ mod tests { do bytes_iter(~"xyz") |bb| { alt check i { - 0 { assert bb == 'x' as u8; } - 1 { assert bb == 'y' as u8; } - 2 { assert bb == 'z' as u8; } + 0 => assert bb == 'x' as u8, + 1 => assert bb == 'y' as u8, + 2 => assert bb == 'z' as u8 } i += 1; } @@ -2813,11 +2811,11 @@ mod tests { do split_char_iter(data, ' ') |xx| { alt ii { - 0 { assert ~"\nMary" == xx; } - 1 { assert ~"had" == xx; } - 2 { assert ~"a" == xx; } - 3 { assert ~"little" == xx; } - _ { () } + 0 => assert ~"\nMary" == xx, + 1 => assert ~"had" == xx, + 2 => assert ~"a" == xx, + 3 => assert ~"little" == xx, + _ => () } ii += 1; } @@ -2831,10 +2829,10 @@ mod tests { do splitn_char_iter(data, ' ', 2u) |xx| { alt ii { - 0 { assert ~"\nMary" == xx; } - 1 { assert ~"had" == xx; } - 2 { assert ~"a little lamb\nLittle lamb\n" == xx; } - _ { () } + 0 => assert ~"\nMary" == xx, + 1 => assert ~"had" == xx, + 2 => assert ~"a little lamb\nLittle lamb\n" == xx, + _ => () } ii += 1; } @@ -2848,11 +2846,11 @@ mod tests { do words_iter(data) |ww| { alt ii { - 0 { assert ~"Mary" == ww; } - 1 { assert ~"had" == ww; } - 2 { assert ~"a" == ww; } - 3 { assert ~"little" == ww; } - _ { () } + 0 => assert ~"Mary" == ww, + 1 => assert ~"had" == ww, + 2 => assert ~"a" == ww, + 3 => assert ~"little" == ww, + _ => () } ii += 1; } @@ -2868,11 +2866,11 @@ mod tests { do lines_iter(lf) |x| { alt ii { - 0 { assert ~"" == x; } - 1 { assert ~"Mary had a little lamb" == x; } - 2 { assert ~"Little lamb" == x; } - 3 { assert ~"" == x; } - _ { () } + 0 => assert ~"" == x, + 1 => assert ~"Mary had a little lamb" == x, + 2 => assert ~"Little lamb" == x, + 3 => assert ~"" == x, + _ => () } ii += 1; } diff --git a/src/libcore/task.rs b/src/libcore/task.rs index 576e7244b69..da25eb308ab 100644 --- a/src/libcore/task.rs +++ b/src/libcore/task.rs @@ -280,7 +280,7 @@ impl task_builder for task_builder { blk(do future::from_fn { alt comm::recv(po) { - exit(_, result) { result } + exit(_, result) => result } }); @@ -503,8 +503,8 @@ fn try<T:send>(+f: fn~() -> T) -> result<T,()> { comm::send(ch, f()); } alt future::get(option::unwrap(result)) { - success { result::ok(comm::recv(po)) } - failure { result::err(()) } + success => result::ok(comm::recv(po)), + failure => result::err(()) } } @@ -992,7 +992,7 @@ fn gen_child_taskgroup(linked: bool, supervised: bool) * Step 1. Get spawner's taskgroup info. *######################################################################*/ let spawner_group = alt unsafe { local_get(spawner, taskgroup_key()) } { - none { + none => { // Main task, doing first spawn ever. Lazily initialise here. let mut members = new_taskset(); taskset_insert(&mut members, spawner); @@ -1005,7 +1005,7 @@ fn gen_child_taskgroup(linked: bool, supervised: bool) unsafe { local_set(spawner, taskgroup_key(), group); } group } - some(group) { group } + some(group) => group }; /*######################################################################* * Step 2. Process spawn options for child. @@ -1029,8 +1029,8 @@ fn gen_child_taskgroup(linked: bool, supervised: bool) // it should be enabled only in debug builds. let new_generation = alt *old_ancestors { - some(arc) { access_ancestors(arc, |a| a.generation+1) } - none { 0 } // the actual value doesn't really matter. + some(arc) => access_ancestors(arc, |a| a.generation+1), + none => 0 // the actual value doesn't really matter. }; assert new_generation < uint::max_value; // Build a new node in the ancestor list. @@ -1074,8 +1074,8 @@ fn spawn_raw(opts: task_opts, +f: fn~()) { let (child_tg, ancestors, f) = option::swap_unwrap(child_data); // Create child task. let new_task = alt opts.sched { - none { rustrt::new_task() } - some(sched_opts) { new_task_in_new_sched(sched_opts) } + none => rustrt::new_task(), + some(sched_opts) => new_task_in_new_sched(sched_opts) }; assert !new_task.is_null(); // Getting killed after here would leak the task. @@ -1163,20 +1163,20 @@ fn spawn_raw(opts: task_opts, +f: fn~()) { } let num_threads = alt opts.mode { - single_threaded { 1u } - thread_per_core { + single_threaded => 1u, + thread_per_core => { fail ~"thread_per_core scheduling mode unimplemented" } - thread_per_task { + thread_per_task => { fail ~"thread_per_task scheduling mode unimplemented" } - manual_threads(threads) { + manual_threads(threads) => { if threads == 0u { fail ~"can not create a scheduler with no threads"; } threads } - osmain { 0u /* Won't be used */ } + osmain => 0u /* Won't be used */ }; let sched_id = if opts.mode != osmain { @@ -1273,7 +1273,10 @@ unsafe fn local_data_lookup<T: owned>( let key_value = key_to_key_value(key); let map_pos = (*map).position(|entry| - alt entry { some((k,_,_)) { k == key_value } none { false } } + alt entry { + some((k,_,_)) => k == key_value, + none => false + } ); do map_pos.map |index| { // .get() is guaranteed because of "none { false }" above. @@ -1334,20 +1337,16 @@ unsafe fn local_set<T: owned>( let new_entry = some((keyval, data_ptr, data_box)); // Find a place to put it. alt local_data_lookup(map, key) { - some((index, _old_data_ptr)) { + some((index, _old_data_ptr)) => { // Key already had a value set, _old_data_ptr, whose reference // will get dropped when the local_data box is overwritten. (*map).set_elt(index, new_entry); } - none { + none => { // Find an empty slot. If not, grow the vector. alt (*map).position(|x| x == none) { - some(empty_index) { - (*map).set_elt(empty_index, new_entry); - } - none { - (*map).push(new_entry); - } + some(empty_index) => (*map).set_elt(empty_index, new_entry), + none => (*map).push(new_entry) } } } @@ -1698,8 +1697,8 @@ fn test_try_success() { alt do try { ~"Success!" } { - result::ok(~"Success!") { } - _ { fail; } + result::ok(~"Success!") => (), + _ => fail } } @@ -1709,8 +1708,8 @@ fn test_try_fail() { alt do try { fail } { - result::err(()) { } - result::ok(()) { fail; } + result::err(()) => (), + result::ok(()) => fail } } @@ -2054,15 +2053,15 @@ fn test_tls_modify() unsafe { fn my_key(+_x: @~str) { } local_data_modify(my_key, |data| { alt data { - some(@val) { fail ~"unwelcome value: " + val } - none { some(@~"first data") } + some(@val) => fail ~"unwelcome value: " + val, + none => some(@~"first data") } }); local_data_modify(my_key, |data| { alt data { - some(@~"first data") { some(@~"next data") } - some(@val) { fail ~"wrong value: " + val } - none { fail ~"missing value" } + some(@~"first data") => some(@~"next data"), + some(@val) => fail ~"wrong value: " + val, + none => fail ~"missing value" } }); assert *(local_data_pop(my_key).get()) == ~"next data"; diff --git a/src/libcore/uint-template.rs b/src/libcore/uint-template.rs index d3e1fb41ca2..d3b0e8cea24 100644 --- a/src/libcore/uint-template.rs +++ b/src/libcore/uint-template.rs @@ -128,8 +128,8 @@ fn parse_buf(buf: ~[u8], radix: uint) -> option<T> { let mut n = 0u as T; loop { alt char::to_digit(buf[i] as char, radix) { - some(d) { n += d as T * power; } - none { return none; } + some(d) => n += d as T * power, + none => return none } power *= radix as T; if i == 0u { return some(n); } @@ -147,8 +147,8 @@ fn from_str_radix(buf: ~str, radix: u64) -> option<u64> { let mut power = 1u64, n = 0u64; loop { alt char::to_digit(buf[i] as char, radix as uint) { - some(d) { n += d as u64 * power; } - none { return none; } + some(d) => n += d as u64 * power, + none => return none } power *= radix; if i == 0u { return some(n); } diff --git a/src/libcore/unicode.rs b/src/libcore/unicode.rs index 61fd8d40f23..343bf7954e6 100644 --- a/src/libcore/unicode.rs +++ b/src/libcore/unicode.rs @@ -2,9 +2,8 @@ mod general_category { pure fn Cc(c: char) -> bool { return alt c { '\x00' to '\x1f' - | '\x7f' to '\x9f' - { true } - _ { false } + | '\x7f' to '\x9f' => true, + _ => false }; } @@ -22,25 +21,22 @@ mod general_category { | '\ufff9' to '\ufffb' | '\U000110bd' | '\U0001d173' to '\U0001d17a' - | '\U000e0001' to '\U000e007f' - { true } - _ { false } + | '\U000e0001' to '\U000e007f' => true, + _ => false }; } pure fn Co(c: char) -> bool { return alt c { - '\ue000' to '\uf8ff' - { true } - _ { false } + '\ue000' to '\uf8ff' => true, + _ => false }; } pure fn Cs(c: char) -> bool { return alt c { - '\ud800' to '\udfff' - { true } - _ { false } + '\ud800' to '\udfff' => true, + _ => false }; } @@ -644,8 +640,8 @@ mod general_category { | '\U0001d7aa' to '\U0001d7c2' | '\U0001d7c4' to '\U0001d7c9' | '\U0001d7cb' - { true } - _ { false } + => true, + _ => false }; } @@ -700,8 +696,8 @@ mod general_category { | '\uaadd' | '\uff70' | '\uff9e' to '\uff9f' - { true } - _ { false } + => true, + _ => false }; } @@ -886,8 +882,8 @@ mod general_category { | '\U00012000' to '\U0001236e' | '\U00013000' to '\U0001b001' | '\U00020000' to '\U0002fa1d' - { true } - _ { false } + => true, + _ => false }; } @@ -903,8 +899,8 @@ mod general_category { | '\u1fbc' | '\u1fcc' | '\u1ffc' - { true } - _ { false } + => true, + _ => false }; } @@ -1495,8 +1491,8 @@ mod general_category { | '\U0001d756' to '\U0001d76e' | '\U0001d790' to '\U0001d7a8' | '\U0001d7ca' - { true } - _ { false } + => true, + _ => false }; } @@ -1606,8 +1602,8 @@ mod general_category { | '\U000110b7' to '\U000110b8' | '\U0001d165' to '\U0001d166' | '\U0001d16d' to '\U0001d172' - { true } - _ { false } + => true, + _ => false }; } @@ -1617,8 +1613,8 @@ mod general_category { | '\u20dd' to '\u20e0' | '\u20e2' to '\u20e4' | '\ua670' to '\ua672' - { true } - _ { false } + => true, + _ => false }; } @@ -1810,8 +1806,8 @@ mod general_category { | '\U0001d1aa' to '\U0001d1ad' | '\U0001d242' to '\U0001d244' | '\U000e0100' to '\U000e01ef' - { true } - _ { false } + => true, + _ => false }; } @@ -1854,8 +1850,8 @@ mod general_category { | '\U000104a0' to '\U000104a9' | '\U00011066' to '\U0001106f' | '\U0001d7ce' to '\U0001d7ff' - { true } - _ { false } + => true, + _ => false }; } @@ -1873,8 +1869,8 @@ mod general_category { | '\U0001034a' | '\U000103d1' to '\U000103d5' | '\U00012400' to '\U00012462' - { true } - _ { false } + => true, + _ => false }; } @@ -1921,8 +1917,8 @@ mod general_category { | '\U00011052' to '\U00011065' | '\U0001d360' to '\U0001d371' | '\U0001f100' to '\U0001f10a' - { true } - _ { false } + => true, + _ => false }; } @@ -1934,8 +1930,8 @@ mod general_category { | '\ufe33' to '\ufe34' | '\ufe4d' to '\ufe4f' | '\uff3f' - { true } - _ { false } + => true, + _ => false }; } @@ -1956,8 +1952,8 @@ mod general_category { | '\ufe58' | '\ufe63' | '\uff0d' - { true } - _ { false } + => true, + _ => false }; } @@ -2033,8 +2029,8 @@ mod general_category { | '\uff5d' | '\uff60' | '\uff63' - { true } - _ { false } + => true, + _ => false }; } @@ -2050,8 +2046,8 @@ mod general_category { | '\u2e0d' | '\u2e1d' | '\u2e21' - { true } - _ { false } + => true, + _ => false }; } @@ -2068,8 +2064,8 @@ mod general_category { | '\u2e0c' | '\u2e1c' | '\u2e20' - { true } - _ { false } + => true, + _ => false }; } @@ -2201,8 +2197,8 @@ mod general_category { | '\U000110bb' to '\U000110bc' | '\U000110be' to '\U000110c1' | '\U00012470' to '\U00012473' - { true } - _ { false } + => true, + _ => false }; } @@ -2280,8 +2276,8 @@ mod general_category { | '\uff5b' | '\uff5f' | '\uff62' - { true } - _ { false } + => true, + _ => false }; } @@ -2303,8 +2299,8 @@ mod general_category { | '\uff04' | '\uffe0' to '\uffe1' | '\uffe5' to '\uffe6' - { true } - _ { false } + => true, + _ => false }; } @@ -2337,8 +2333,8 @@ mod general_category { | '\uff3e' | '\uff40' | '\uffe3' - { true } - _ { false } + => true, + _ => false }; } @@ -2408,8 +2404,8 @@ mod general_category { | '\U0001d789' | '\U0001d7a9' | '\U0001d7c3' - { true } - _ { false } + => true, + _ => false }; } @@ -2527,24 +2523,22 @@ mod general_category { | '\U0001d245' to '\U0001d356' | '\U0001f000' to '\U0001f0df' | '\U0001f110' to '\U0001f773' - { true } - _ { false } + => true, + _ => false }; } pure fn Zl(c: char) -> bool { return alt c { - '\u2028' - { true } - _ { false } + '\u2028' => true, + _ => false }; } pure fn Zp(c: char) -> bool { return alt c { - '\u2029' - { true } - _ { false } + '\u2029' => true, + _ => false }; } @@ -2558,8 +2552,8 @@ mod general_category { | '\u202f' | '\u205f' | '\u3000' - { true } - _ { false } + => true, + _ => false }; } @@ -3299,8 +3293,8 @@ mod derived_property { | '\U0002a700' to '\U0002b734' | '\U0002b740' to '\U0002b81d' | '\U0002f800' to '\U0002fa1d' - { true } - _ { false } + => true, + _ => false }; } @@ -4170,8 +4164,8 @@ mod derived_property { | '\U0002b740' to '\U0002b81d' | '\U0002f800' to '\U0002fa1d' | '\U000e0100' to '\U000e01ef' - { true } - _ { false } + => true, + _ => false }; } @@ -4676,8 +4670,8 @@ mod derived_property { | '\U0002a700' to '\U0002b734' | '\U0002b740' to '\U0002b81d' | '\U0002f800' to '\U0002fa1d' - { true } - _ { false } + => true, + _ => false }; } diff --git a/src/libcore/vec.rs b/src/libcore/vec.rs index 2606bdf72f8..93bdd53d90d 100644 --- a/src/libcore/vec.rs +++ b/src/libcore/vec.rs @@ -357,8 +357,8 @@ fn split<T: copy>(v: &[T], f: fn(T) -> bool) -> ~[~[T]] { let mut result = ~[]; while start < ln { alt position_between(v, start, ln, f) { - none { break } - some(i) { + none => break, + some(i) => { push(result, slice(v, start, i)); start = i + 1u; } @@ -381,8 +381,8 @@ fn splitn<T: copy>(v: &[T], n: uint, f: fn(T) -> bool) -> ~[~[T]] { let mut result = ~[]; while start < ln && count > 0u { alt position_between(v, start, ln, f) { - none { break } - some(i) { + none => break, + some(i) => { push(result, slice(v, start, i)); // Make sure to skip the separator. start = i + 1u; @@ -406,8 +406,8 @@ fn rsplit<T: copy>(v: &[T], f: fn(T) -> bool) -> ~[~[T]] { let mut result = ~[]; while end > 0u { alt rposition_between(v, 0u, end, f) { - none { break } - some(i) { + none => break, + some(i) => { push(result, slice(v, i + 1u, end)); end = i; } @@ -430,8 +430,8 @@ fn rsplitn<T: copy>(v: &[T], n: uint, f: fn(T) -> bool) -> ~[~[T]] { let mut result = ~[]; while end > 0u && count > 0u { alt rposition_between(v, 0u, end, f) { - none { break } - some(i) { + none => break, + some(i) => { push(result, slice(v, i + 1u, end)); // Make sure to skip the separator. end = i; @@ -714,8 +714,8 @@ pure fn filter_map<T, U: copy>(v: &[T], f: fn(T) -> option<U>) let mut result = ~[]; for each(v) |elem| { alt f(elem) { - none {/* no-op */ } - some(result_elem) { unsafe { push(result, result_elem); } } + none => {/* no-op */ } + some(result_elem) => unsafe { push(result, result_elem); } } } return result; diff --git a/src/libstd/base64.rs b/src/libstd/base64.rs index 8ee0253ba40..e76d3093c17 100644 --- a/src/libstd/base64.rs +++ b/src/libstd/base64.rs @@ -31,15 +31,15 @@ impl of to_base64 for ~[u8] { } alt check len % 3u { - 0u { } - 1u { + 0u => (), + 1u => { let n = (self[i] as uint) << 16u; str::push_char(s, chars[(n >> 18u) & 63u]); str::push_char(s, chars[(n >> 12u) & 63u]); str::push_char(s, '='); str::push_char(s, '='); } - 2u { + 2u => { let n = (self[i] as uint) << 16u | (self[i + 1u] as uint) << 8u; str::push_char(s, chars[(n >> 18u) & 63u]); str::push_char(s, chars[(n >> 12u) & 63u]); @@ -97,18 +97,16 @@ impl of from_base64 for ~[u8] { n |= 0x3Fu; } else if ch == '=' { alt len - i { - 1u { + 1u => { vec::push(r, ((n >> 16u) & 0xFFu) as u8); vec::push(r, ((n >> 8u ) & 0xFFu) as u8); return copy r; } - 2u { + 2u => { vec::push(r, ((n >> 10u) & 0xFFu) as u8); return copy r; } - _ { - fail ~"invalid base64 padding"; - } + _ => fail ~"invalid base64 padding" } } else { fail ~"invalid base64 character"; diff --git a/src/libstd/bitv.rs b/src/libstd/bitv.rs index 94a4f1ba977..de51e2b7f51 100644 --- a/src/libstd/bitv.rs +++ b/src/libstd/bitv.rs @@ -180,35 +180,25 @@ class bitv { self.die(); } alt self.rep { - small(s) { - alt other.rep { - small(s1) { - alt op { - union { s.union(s1) } - intersect { s.intersect(s1) } - assign { s.become(s1) } - difference { s.difference(s1) } - } - } - big(s1) { - self.die(); - } + small(s) => alt other.rep { + small(s1) => alt op { + union => s.union(s1), + intersect => s.intersect(s1), + assign => s.become(s1), + difference => s.difference(s1) + } + big(s1) => self.die() } - } - big(s) { - alt other.rep { - small(_) { self.die(); } - big(s1) { - alt op { - union { s.union(s1) } - intersect { s.intersect(s1) } - assign { s.become(s1) } - difference { s.difference(s1) } - } - } + big(s) => alt other.rep { + small(_) => self.die(), + big(s1) => alt op { + union => s.union(s1), + intersect => s.intersect(s1), + assign => s.become(s1), + difference => s.difference(s1) } + } } - } } } @@ -243,10 +233,10 @@ class bitv { #[inline(always)] fn clone() -> ~bitv { ~alt self.rep { - small(b) { + small(b) => { bitv{nbits: self.nbits, rep: small(~small_bitv{bits: b.bits})} } - big(b) { + big(b) => { let st = to_mut(from_elem(self.nbits / uint_bits + 1, 0)); let len = st.len(); for uint::range(0, len) |i| { st[i] = b.storage[i]; }; @@ -260,8 +250,8 @@ class bitv { pure fn get(i: uint) -> bool { assert (i < self.nbits); alt self.rep { - big(b) { b.get(i) } - small(s) { s.get(i) } + big(b) => b.get(i), + small(s) => s.get(i) } } @@ -274,8 +264,8 @@ class bitv { fn set(i: uint, x: bool) { assert (i < self.nbits); alt self.rep { - big(b) { b.set(i, x); } - small(s) { s.set(i, x); } + big(b) => b.set(i, x), + small(s) => s.set(i, x) } } @@ -289,19 +279,13 @@ class bitv { fn equal(v1: bitv) -> bool { if self.nbits != v1.nbits { return false; } alt self.rep { - small(b) { - alt v1.rep { - small(b1) { b.equals(b1) } - _ { false } - } + small(b) => alt v1.rep { + small(b1) => b.equals(b1), + _ => false } - big(s) { - alt v1.rep { - big(s1) { - s.equals(s1) - } - small(_) { return false; } - } + big(s) => alt v1.rep { + big(s1) => s.equals(s1), + small(_) => return false } } } @@ -310,10 +294,8 @@ class bitv { #[inline(always)] fn clear() { alt self.rep { - small(b) { b.clear(); } - big(s) { - for s.each_storage() |w| { w = 0u } - } + small(b) => b.clear(), + big(s) => for s.each_storage() |w| { w = 0u } } } @@ -321,20 +303,16 @@ class bitv { #[inline(always)] fn set_all() { alt self.rep { - small(b) { b.set_all(); } - big(s) { - for s.each_storage() |w| { w = !0u } } - } + small(b) => b.set_all(), + big(s) => for s.each_storage() |w| { w = !0u } } } /// Invert all bits #[inline(always)] fn invert() { alt self.rep { - small(b) { b.invert(); } - big(s) { - for s.each_storage() |w| { w = !w } } - } + small(b) => b.invert(), + big(s) => for s.each_storage() |w| { w = !w } } } /** @@ -352,8 +330,8 @@ class bitv { #[inline(always)] fn is_true() -> bool { alt self.rep { - small(b) { b.is_true() } - _ { + small(b) => b.is_true(), + _ => { for self.each() |i| { if !i { return false; } } true } @@ -373,8 +351,8 @@ class bitv { fn is_false() -> bool { alt self.rep { - small(b) { b.is_false() } - big(_) { + small(b) => b.is_false(), + big(_) => { for self.each() |i| { if i { return false; } } true } diff --git a/src/libstd/c_vec.rs b/src/libstd/c_vec.rs index b80ec82bcf3..e00ee13949b 100644 --- a/src/libstd/c_vec.rs +++ b/src/libstd/c_vec.rs @@ -47,8 +47,8 @@ class dtor_res { new(dtor: option<fn@()>) { self.dtor = dtor; } drop { alt self.dtor { - option::none { } - option::some(f) { f(); } + option::none => (), + option::some(f) => f() } } } diff --git a/src/libstd/deque.rs b/src/libstd/deque.rs index f3feb26ebb6..5e98f3c7054 100644 --- a/src/libstd/deque.rs +++ b/src/libstd/deque.rs @@ -41,7 +41,7 @@ fn create<T: copy>() -> t<T> { return rv; } fn get<T: copy>(elts: dvec<cell<T>>, i: uint) -> T { - alt elts.get_elt(i) { some(t) { t } _ { fail } } + alt elts.get_elt(i) { some(t) => t, _ => fail } } type repr<T> = {mut nelts: uint, @@ -239,45 +239,35 @@ mod tests { fn intboxeq(&&a: @int, &&b: @int) -> bool { return a == b; } fn taggyeq(a: taggy, b: taggy) -> bool { alt a { - one(a1) { - alt b { one(b1) {return a1 == b1; } _ { return false; } } + one(a1) => alt b { + one(b1) => return a1 == b1, + _ => return false } - two(a1, a2) { - alt b { - two(b1, b2) { return a1 == b1 && a2 == b2; } - _ { return false; } - } + two(a1, a2) => alt b { + two(b1, b2) => return a1 == b1 && a2 == b2, + _ => return false } - three(a1, a2, a3) { - alt b { - three(b1, b2, b3) { - return a1 == b1 && a2 == b2 && a3 == b3; - } - _ { return false; } - } + three(a1, a2, a3) => alt b { + three(b1, b2, b3) => return a1 == b1 && a2 == b2 && a3 == b3, + _ => return false } } } fn taggypareq<T>(a: taggypar<T>, b: taggypar<T>) -> bool { alt a { - onepar::<T>(a1) { - alt b { - onepar::<T>(b1) { return a1 == b1; } _ { return false; } - } + onepar::<T>(a1) => alt b { + onepar::<T>(b1) => return a1 == b1, + _ => return false } - twopar::<T>(a1, a2) { - alt b { - twopar::<T>(b1, b2) { return a1 == b1 && a2 == b2; } - _ { return false; } - } + twopar::<T>(a1, a2) => alt b { + twopar::<T>(b1, b2) => return a1 == b1 && a2 == b2, + _ => return false } - threepar::<T>(a1, a2, a3) { - alt b { - threepar::<T>(b1, b2, b3) { - return a1 == b1 && a2 == b2 && a3 == b3; - } - _ { return false; } + threepar::<T>(a1, a2, a3) => alt b { + threepar::<T>(b1, b2, b3) => { + return a1 == b1 && a2 == b2 && a3 == b3 } + _ => return false } } } diff --git a/src/libstd/ebml.rs b/src/libstd/ebml.rs index 46ccaa2d096..78ec45659cc 100644 --- a/src/libstd/ebml.rs +++ b/src/libstd/ebml.rs @@ -114,8 +114,8 @@ fn maybe_get_doc(d: doc, tg: uint) -> option<doc> { fn get_doc(d: doc, tg: uint) -> doc { alt maybe_get_doc(d, tg) { - some(d) { return d; } - none { + some(d) => return d, + none => { error!{"failed to find block with tag %u", tg}; fail; } @@ -190,21 +190,13 @@ enum writer { fn write_sized_vuint(w: io::writer, n: uint, size: uint) { alt size { - 1u { - w.write(&[0x80u8 | (n as u8)]); - } - 2u { - w.write(&[0x40u8 | ((n >> 8_u) as u8), n as u8]); - } - 3u { - w.write(&[0x20u8 | ((n >> 16_u) as u8), (n >> 8_u) as u8, - n as u8]); - } - 4u { - w.write(&[0x10u8 | ((n >> 24_u) as u8), (n >> 16_u) as u8, - (n >> 8_u) as u8, n as u8]); - } - _ { fail fmt!{"vint to write too big: %?", n}; } + 1u => w.write(&[0x80u8 | (n as u8)]), + 2u => w.write(&[0x40u8 | ((n >> 8_u) as u8), n as u8]), + 3u => w.write(&[0x20u8 | ((n >> 16_u) as u8), (n >> 8_u) as u8, + n as u8]), + 4u => w.write(&[0x10u8 | ((n >> 24_u) as u8), (n >> 16_u) as u8, + (n >> 8_u) as u8, n as u8]), + _ => fail fmt!{"vint to write too big: %?", n} }; } @@ -602,10 +594,9 @@ fn test_option_int() { fn serialize_0<S: serialization::serializer>(s: S, v: option<int>) { do s.emit_enum(~"core::option::t") { alt v { - none { - s.emit_enum_variant(~"core::option::none", 0u, 0u, || { } ); - } - some(v0) { + none => s.emit_enum_variant( + ~"core::option::none", 0u, 0u, || { } ), + some(v0) => { do s.emit_enum_variant(~"core::option::some", 1u, 1u) { s.emit_enum_variant_arg(0u, || serialize_1(s, v0)); } @@ -622,8 +613,8 @@ fn test_option_int() { do s.read_enum(~"core::option::t") { do s.read_enum_variant |i| { alt check i { - 0u { none } - 1u { + 0u => none, + 1u => { let v0 = do s.read_enum_variant_arg(0u) { deserialize_1(s) }; diff --git a/src/libstd/fun_treemap.rs b/src/libstd/fun_treemap.rs index 6a3b40b88ff..e849d77ded6 100644 --- a/src/libstd/fun_treemap.rs +++ b/src/libstd/fun_treemap.rs @@ -31,8 +31,8 @@ fn init<K, V>() -> treemap<K, V> { @empty } /// Insert a value into the map fn insert<K: copy, V: copy>(m: treemap<K, V>, k: K, v: V) -> treemap<K, V> { @alt m { - @empty { node(@k, @v, @empty, @empty) } - @node(@kk, vv, left, right) { + @empty => node(@k, @v, @empty, @empty), + @node(@kk, vv, left, right) => { if k < kk { node(@kk, vv, insert(left, k, v), right) } else if k == kk { @@ -45,8 +45,8 @@ fn insert<K: copy, V: copy>(m: treemap<K, V>, k: K, v: V) -> treemap<K, V> { /// Find a value based on the key fn find<K, V: copy>(m: treemap<K, V>, k: K) -> option<V> { alt *m { - empty { none } - node(@kk, @v, left, right) { + empty => none, + node(@kk, @v, left, right) => { if k == kk { some(v) } else if k < kk { find(left, k) } else { find(right, k) } @@ -57,13 +57,13 @@ fn find<K, V: copy>(m: treemap<K, V>, k: K) -> option<V> { /// Visit all pairs in the map in order. fn traverse<K, V: copy>(m: treemap<K, V>, f: fn(K, V)) { alt *m { - empty { } + empty => (), /* Previously, this had what looked like redundant matches to me, so I changed it. but that may be a de-optimization -- tjc */ - node(@k, @v, left, right) { + node(@k, @v, left, right) => { // copy v to make aliases work out let v1 = v; traverse(left, f); diff --git a/src/libstd/getopts.rs b/src/libstd/getopts.rs index ed0ee4ff5ed..c05c685daa8 100644 --- a/src/libstd/getopts.rs +++ b/src/libstd/getopts.rs @@ -140,7 +140,10 @@ fn is_arg(arg: ~str) -> bool { } fn name_str(nm: name) -> ~str { - return alt nm { short(ch) { str::from_char(ch) } long(s) { s } }; + return alt nm { + short(ch) => str::from_char(ch), + long(s) => s + }; } fn find_opt(opts: ~[opt], nm: name) -> option<uint> { @@ -162,18 +165,14 @@ enum fail_ { /// Convert a `fail_` enum into an error string fn fail_str(f: fail_) -> ~str { return alt f { - argument_missing(nm) { - ~"Argument to option '" + nm + ~"' missing." - } - unrecognized_option(nm) { ~"Unrecognized option: '" + nm + ~"'." } - option_missing(nm) { ~"Required option '" + nm + ~"' missing." } - option_duplicated(nm) { - ~"Option '" + nm + ~"' given more than once." - } - unexpected_argument(nm) { - ~"Option " + nm + ~" does not take an argument." - } - }; + argument_missing(nm) => ~"Argument to option '" + nm + ~"' missing.", + unrecognized_option(nm) => ~"Unrecognized option: '" + nm + ~"'.", + option_missing(nm) => ~"Required option '" + nm + ~"' missing.", + option_duplicated(nm) => ~"Option '" + nm + ~"' given more than once.", + unexpected_argument(nm) => { + ~"Option " + nm + ~" does not take an argument." + } + }; } /** @@ -235,15 +234,13 @@ fn getopts(args: ~[~str], opts: ~[opt]) -> result unsafe { */ alt find_opt(opts, opt) { - some(id) { - last_valid_opt_id = option::some(id); - } - none { + some(id) => last_valid_opt_id = option::some(id), + none => { let arg_follows = option::is_some(last_valid_opt_id) && alt opts[option::get(last_valid_opt_id)].hasarg { - yes | maybe { true } - no { false } + yes | maybe => true, + no => false }; if arg_follows && j + 1 < curlen { i_arg = option::some(str::slice(cur, j, curlen)); @@ -261,17 +258,17 @@ fn getopts(args: ~[~str], opts: ~[opt]) -> result unsafe { for vec::each(names) |nm| { name_pos += 1u; let optid = alt find_opt(opts, nm) { - some(id) { id } - none { return err(unrecognized_option(name_str(nm))); } + some(id) => id, + none => return err(unrecognized_option(name_str(nm))) }; alt opts[optid].hasarg { - no { + no => { if !option::is_none::<~str>(i_arg) { return err(unexpected_argument(name_str(nm))); } vec::push(vals[optid], given); } - maybe { + maybe => { if !option::is_none::<~str>(i_arg) { vec::push(vals[optid], val(option::get(i_arg))); } else if name_pos < vec::len::<name>(names) || @@ -279,7 +276,7 @@ fn getopts(args: ~[~str], opts: ~[opt]) -> result unsafe { vec::push(vals[optid], given); } else { i += 1u; vec::push(vals[optid], val(args[i])); } } - yes { + yes => { if !option::is_none::<~str>(i_arg) { vec::push(vals[optid], val(option::get::<~str>(i_arg))); @@ -313,9 +310,12 @@ fn getopts(args: ~[~str], opts: ~[opt]) -> result unsafe { fn opt_vals(m: matches, nm: ~str) -> ~[optval] { return alt find_opt(m.opts, mkname(nm)) { - some(id) { m.vals[id] } - none { error!{"No option '%s' defined", nm}; fail } - }; + some(id) => m.vals[id], + none => { + error!{"No option '%s' defined", nm}; + fail + } + }; } fn opt_val(m: matches, nm: ~str) -> optval { return opt_vals(m, nm)[0]; } @@ -329,8 +329,8 @@ fn opt_present(m: matches, nm: ~str) -> bool { fn opts_present(m: matches, names: ~[~str]) -> bool { for vec::each(names) |nm| { alt find_opt(m.opts, mkname(nm)) { - some(_) { return true; } - _ { } + some(_) => return true, + _ => () } } return false; @@ -344,7 +344,7 @@ fn opts_present(m: matches, names: ~[~str]) -> bool { * argument */ fn opt_str(m: matches, nm: ~str) -> ~str { - return alt opt_val(m, nm) { val(s) { s } _ { fail } }; + return alt opt_val(m, nm) { val(s) => s, _ => fail }; } /** @@ -356,8 +356,8 @@ fn opt_str(m: matches, nm: ~str) -> ~str { fn opts_str(m: matches, names: ~[~str]) -> ~str { for vec::each(names) |nm| { alt opt_val(m, nm) { - val(s) { return s } - _ { } + val(s) => return s, + _ => () } } fail; @@ -373,7 +373,7 @@ fn opts_str(m: matches, names: ~[~str]) -> ~str { fn opt_strs(m: matches, nm: ~str) -> ~[~str] { let mut acc: ~[~str] = ~[]; for vec::each(opt_vals(m, nm)) |v| { - alt v { val(s) { vec::push(acc, s); } _ { } } + alt v { val(s) => vec::push(acc, s), _ => () } } return acc; } @@ -382,7 +382,7 @@ fn opt_strs(m: matches, nm: ~str) -> ~[~str] { fn opt_maybe_str(m: matches, nm: ~str) -> option<~str> { let vals = opt_vals(m, nm); if vec::len::<optval>(vals) == 0u { return none::<~str>; } - return alt vals[0] { val(s) { some::<~str>(s) } _ { none::<~str> } }; + return alt vals[0] { val(s) => some::<~str>(s), _ => none::<~str> }; } @@ -396,7 +396,7 @@ fn opt_maybe_str(m: matches, nm: ~str) -> option<~str> { fn opt_default(m: matches, nm: ~str, def: ~str) -> option<~str> { let vals = opt_vals(m, nm); if vec::len::<optval>(vals) == 0u { return none::<~str>; } - return alt vals[0] { val(s) { some::<~str>(s) } _ { some::<~str>(def) } } + return alt vals[0] { val(s) => some::<~str>(s), _ => some::<~str>(def) } } #[cfg(test)] @@ -414,11 +414,11 @@ mod tests { fn check_fail_type(f: fail_, ft: fail_type) { alt f { - argument_missing(_) { assert (ft == argument_missing_); } - unrecognized_option(_) { assert (ft == unrecognized_option_); } - option_missing(_) { assert (ft == option_missing_); } - option_duplicated(_) { assert (ft == option_duplicated_); } - unexpected_argument(_) { assert (ft == unexpected_argument_); } + argument_missing(_) => assert ft == argument_missing_, + unrecognized_option(_) => assert ft == unrecognized_option_, + option_missing(_) => assert ft == option_missing_, + option_duplicated(_) => assert ft == option_duplicated_, + unexpected_argument(_) => assert ft == unexpected_argument_ } } @@ -430,7 +430,7 @@ mod tests { let opts = ~[reqopt(~"test")]; let rs = getopts(args, opts); alt check rs { - ok(m) { + ok(m) => { assert (opt_present(m, ~"test")); assert (opt_str(m, ~"test") == ~"20"); } @@ -443,8 +443,8 @@ mod tests { let opts = ~[reqopt(~"test")]; let rs = getopts(args, opts); alt rs { - err(f) { check_fail_type(f, option_missing_); } - _ { fail; } + err(f) => check_fail_type(f, option_missing_), + _ => fail } } @@ -454,8 +454,8 @@ mod tests { let opts = ~[reqopt(~"test")]; let rs = getopts(args, opts); alt rs { - err(f) { check_fail_type(f, argument_missing_); } - _ { fail; } + err(f) => check_fail_type(f, argument_missing_), + _ => fail } } @@ -465,8 +465,8 @@ mod tests { let opts = ~[reqopt(~"test")]; let rs = getopts(args, opts); alt rs { - err(f) { check_fail_type(f, option_duplicated_); } - _ { fail; } + err(f) => check_fail_type(f, option_duplicated_), + _ => fail } } @@ -476,11 +476,11 @@ mod tests { let opts = ~[reqopt(~"t")]; let rs = getopts(args, opts); alt rs { - ok(m) { + ok(m) => { assert (opt_present(m, ~"t")); assert (opt_str(m, ~"t") == ~"20"); } - _ { fail; } + _ => fail } } @@ -490,8 +490,8 @@ mod tests { let opts = ~[reqopt(~"t")]; let rs = getopts(args, opts); alt rs { - err(f) { check_fail_type(f, option_missing_); } - _ { fail; } + err(f) => check_fail_type(f, option_missing_), + _ => fail } } @@ -501,8 +501,8 @@ mod tests { let opts = ~[reqopt(~"t")]; let rs = getopts(args, opts); alt rs { - err(f) { check_fail_type(f, argument_missing_); } - _ { fail; } + err(f) => check_fail_type(f, argument_missing_), + _ => fail } } @@ -512,8 +512,8 @@ mod tests { let opts = ~[reqopt(~"t")]; let rs = getopts(args, opts); alt rs { - err(f) { check_fail_type(f, option_duplicated_); } - _ { fail; } + err(f) => check_fail_type(f, option_duplicated_), + _ => fail } } @@ -525,11 +525,11 @@ mod tests { let opts = ~[optopt(~"test")]; let rs = getopts(args, opts); alt rs { - ok(m) { + ok(m) => { assert (opt_present(m, ~"test")); assert (opt_str(m, ~"test") == ~"20"); } - _ { fail; } + _ => fail } } @@ -539,8 +539,8 @@ mod tests { let opts = ~[optopt(~"test")]; let rs = getopts(args, opts); alt rs { - ok(m) { assert (!opt_present(m, ~"test")); } - _ { fail; } + ok(m) => assert (!opt_present(m, ~"test")), + _ => fail } } @@ -550,8 +550,8 @@ mod tests { let opts = ~[optopt(~"test")]; let rs = getopts(args, opts); alt rs { - err(f) { check_fail_type(f, argument_missing_); } - _ { fail; } + err(f) => check_fail_type(f, argument_missing_), + _ => fail } } @@ -561,8 +561,8 @@ mod tests { let opts = ~[optopt(~"test")]; let rs = getopts(args, opts); alt rs { - err(f) { check_fail_type(f, option_duplicated_); } - _ { fail; } + err(f) => check_fail_type(f, option_duplicated_), + _ => fail } } @@ -572,11 +572,11 @@ mod tests { let opts = ~[optopt(~"t")]; let rs = getopts(args, opts); alt rs { - ok(m) { + ok(m) => { assert (opt_present(m, ~"t")); assert (opt_str(m, ~"t") == ~"20"); } - _ { fail; } + _ => fail } } @@ -586,8 +586,8 @@ mod tests { let opts = ~[optopt(~"t")]; let rs = getopts(args, opts); alt rs { - ok(m) { assert (!opt_present(m, ~"t")); } - _ { fail; } + ok(m) => assert (!opt_present(m, ~"t")), + _ => fail } } @@ -597,8 +597,8 @@ mod tests { let opts = ~[optopt(~"t")]; let rs = getopts(args, opts); alt rs { - err(f) { check_fail_type(f, argument_missing_); } - _ { fail; } + err(f) => check_fail_type(f, argument_missing_), + _ => fail } } @@ -608,8 +608,8 @@ mod tests { let opts = ~[optopt(~"t")]; let rs = getopts(args, opts); alt rs { - err(f) { check_fail_type(f, option_duplicated_); } - _ { fail; } + err(f) => check_fail_type(f, option_duplicated_), + _ => fail } } @@ -621,8 +621,8 @@ mod tests { let opts = ~[optflag(~"test")]; let rs = getopts(args, opts); alt rs { - ok(m) { assert (opt_present(m, ~"test")); } - _ { fail; } + ok(m) => assert (opt_present(m, ~"test")), + _ => fail } } @@ -632,8 +632,8 @@ mod tests { let opts = ~[optflag(~"test")]; let rs = getopts(args, opts); alt rs { - ok(m) { assert (!opt_present(m, ~"test")); } - _ { fail; } + ok(m) => assert (!opt_present(m, ~"test")), + _ => fail } } @@ -643,11 +643,11 @@ mod tests { let opts = ~[optflag(~"test")]; let rs = getopts(args, opts); alt rs { - err(f) { + err(f) => { log(error, fail_str(f)); check_fail_type(f, unexpected_argument_); } - _ { fail; } + _ => fail } } @@ -657,8 +657,8 @@ mod tests { let opts = ~[optflag(~"test")]; let rs = getopts(args, opts); alt rs { - err(f) { check_fail_type(f, option_duplicated_); } - _ { fail; } + err(f) => check_fail_type(f, option_duplicated_), + _ => fail } } @@ -668,8 +668,8 @@ mod tests { let opts = ~[optflag(~"t")]; let rs = getopts(args, opts); alt rs { - ok(m) { assert (opt_present(m, ~"t")); } - _ { fail; } + ok(m) => assert (opt_present(m, ~"t")), + _ => fail } } @@ -679,8 +679,8 @@ mod tests { let opts = ~[optflag(~"t")]; let rs = getopts(args, opts); alt rs { - ok(m) { assert (!opt_present(m, ~"t")); } - _ { fail; } + ok(m) => assert (!opt_present(m, ~"t")), + _ => fail } } @@ -690,12 +690,12 @@ mod tests { let opts = ~[optflag(~"t")]; let rs = getopts(args, opts); alt rs { - ok(m) { + ok(m) => { // The next variable after the flag is just a free argument assert (m.free[0] == ~"20"); } - _ { fail; } + _ => fail } } @@ -705,8 +705,8 @@ mod tests { let opts = ~[optflag(~"t")]; let rs = getopts(args, opts); alt rs { - err(f) { check_fail_type(f, option_duplicated_); } - _ { fail; } + err(f) => check_fail_type(f, option_duplicated_), + _ => fail } } @@ -718,11 +718,11 @@ mod tests { let opts = ~[optmulti(~"test")]; let rs = getopts(args, opts); alt rs { - ok(m) { + ok(m) => { assert (opt_present(m, ~"test")); assert (opt_str(m, ~"test") == ~"20"); } - _ { fail; } + _ => fail } } @@ -732,8 +732,8 @@ mod tests { let opts = ~[optmulti(~"test")]; let rs = getopts(args, opts); alt rs { - ok(m) { assert (!opt_present(m, ~"test")); } - _ { fail; } + ok(m) => assert (!opt_present(m, ~"test")), + _ => fail } } @@ -743,8 +743,8 @@ mod tests { let opts = ~[optmulti(~"test")]; let rs = getopts(args, opts); alt rs { - err(f) { check_fail_type(f, argument_missing_); } - _ { fail; } + err(f) => check_fail_type(f, argument_missing_), + _ => fail } } @@ -754,13 +754,13 @@ mod tests { let opts = ~[optmulti(~"test")]; let rs = getopts(args, opts); alt rs { - ok(m) { + ok(m) => { assert (opt_present(m, ~"test")); assert (opt_str(m, ~"test") == ~"20"); assert (opt_strs(m, ~"test")[0] == ~"20"); assert (opt_strs(m, ~"test")[1] == ~"30"); } - _ { fail; } + _ => fail } } @@ -770,11 +770,11 @@ mod tests { let opts = ~[optmulti(~"t")]; let rs = getopts(args, opts); alt rs { - ok(m) { + ok(m) => { assert (opt_present(m, ~"t")); assert (opt_str(m, ~"t") == ~"20"); } - _ { fail; } + _ => fail } } @@ -784,8 +784,8 @@ mod tests { let opts = ~[optmulti(~"t")]; let rs = getopts(args, opts); alt rs { - ok(m) { assert (!opt_present(m, ~"t")); } - _ { fail; } + ok(m) => assert (!opt_present(m, ~"t")), + _ => fail } } @@ -795,8 +795,8 @@ mod tests { let opts = ~[optmulti(~"t")]; let rs = getopts(args, opts); alt rs { - err(f) { check_fail_type(f, argument_missing_); } - _ { fail; } + err(f) => check_fail_type(f, argument_missing_), + _ => fail } } @@ -806,13 +806,13 @@ mod tests { let opts = ~[optmulti(~"t")]; let rs = getopts(args, opts); alt rs { - ok(m) { + ok(m) => { assert (opt_present(m, ~"t")); assert (opt_str(m, ~"t") == ~"20"); assert (opt_strs(m, ~"t")[0] == ~"20"); assert (opt_strs(m, ~"t")[1] == ~"30"); } - _ { fail; } + _ => fail } } @@ -822,8 +822,8 @@ mod tests { let opts = ~[optmulti(~"t")]; let rs = getopts(args, opts); alt rs { - err(f) { check_fail_type(f, unrecognized_option_); } - _ { fail; } + err(f) => check_fail_type(f, unrecognized_option_), + _ => fail } } @@ -833,8 +833,8 @@ mod tests { let opts = ~[optmulti(~"test")]; let rs = getopts(args, opts); alt rs { - err(f) { check_fail_type(f, unrecognized_option_); } - _ { fail; } + err(f) => check_fail_type(f, unrecognized_option_), + _ => fail } } @@ -850,7 +850,7 @@ mod tests { optopt(~"notpresent")]; let rs = getopts(args, opts); alt rs { - ok(m) { + ok(m) => { assert (m.free[0] == ~"prog"); assert (m.free[1] == ~"free1"); assert (opt_str(m, ~"s") == ~"20"); @@ -864,7 +864,7 @@ mod tests { assert (opt_strs(m, ~"n")[1] == ~"-60 70"); assert (!opt_present(m, ~"notpresent")); } - _ { fail; } + _ => fail } } @@ -873,8 +873,8 @@ mod tests { let args = ~[~"-e", ~"foo", ~"--encrypt", ~"foo"]; let opts = ~[optopt(~"e"), optopt(~"encrypt")]; let matches = alt getopts(args, opts) { - result::ok(m) { m } - result::err(f) { fail; } + result::ok(m) => m, + result::err(f) => fail }; assert opts_present(matches, ~[~"e"]); assert opts_present(matches, ~[~"encrypt"]); @@ -894,8 +894,8 @@ mod tests { let args = ~[~"-Lfoo"]; let opts = ~[optmulti(~"L")]; let matches = alt getopts(args, opts) { - result::ok(m) { m } - result::err(f) { fail; } + result::ok(m) => m, + result::err(f) => fail }; assert opts_present(matches, ~[~"L"]); assert opts_str(matches, ~[~"L"]) == ~"foo"; diff --git a/src/libstd/json.rs b/src/libstd/json.rs index 9faea572338..82a0f7d8084 100644 --- a/src/libstd/json.rs +++ b/src/libstd/json.rs @@ -46,14 +46,10 @@ type error = { /// Serializes a json value into a io::writer fn to_writer(wr: io::writer, j: json) { alt j { - num(n) { wr.write_str(float::to_str(n, 6u)); } - string(s) { - wr.write_str(escape_str(*s)); - } - boolean(b) { - wr.write_str(if b { ~"true" } else { ~"false" }); - } - list(v) { + num(n) => wr.write_str(float::to_str(n, 6u)), + string(s) => wr.write_str(escape_str(*s)), + boolean(b) => wr.write_str(if b { ~"true" } else { ~"false" }), + list(v) => { wr.write_char('['); let mut first = true; for (*v).each |item| { @@ -65,7 +61,7 @@ fn to_writer(wr: io::writer, j: json) { }; wr.write_char(']'); } - dict(d) { + dict(d) => { if d.size() == 0u { wr.write_str(~"{}"); return; @@ -84,9 +80,7 @@ fn to_writer(wr: io::writer, j: json) { }; wr.write_str(~" }"); } - null { - wr.write_str(~"null"); - } + null => wr.write_str(~"null") } } @@ -94,14 +88,14 @@ fn escape_str(s: ~str) -> ~str { let mut escaped = ~"\""; do str::chars_iter(s) |c| { alt c { - '"' { escaped += ~"\\\""; } - '\\' { escaped += ~"\\\\"; } - '\x08' { escaped += ~"\\b"; } - '\x0c' { escaped += ~"\\f"; } - '\n' { escaped += ~"\\n"; } - '\r' { escaped += ~"\\r"; } - '\t' { escaped += ~"\\t"; } - _ { escaped += str::from_char(c); } + '"' => escaped += ~"\\\"", + '\\' => escaped += ~"\\\\", + '\x08' => escaped += ~"\\b", + '\x0c' => escaped += ~"\\f", + '\n' => escaped += ~"\\n", + '\r' => escaped += ~"\\r", + '\t' => escaped += ~"\\t", + _ => escaped += str::from_char(c) } }; @@ -151,7 +145,7 @@ impl parser for parser { fn parse() -> result<json, error> { alt self.parse_value() { - ok(value) { + ok(value) => { // Skip trailing whitespaces. self.parse_whitespace(); // Make sure there is no trailing characters. @@ -161,7 +155,7 @@ impl parser for parser { self.error(~"trailing characters") } } - e { e } + e => e } } @@ -171,19 +165,17 @@ impl parser for parser { if self.eof() { return self.error(~"EOF while parsing value"); } alt self.ch { - 'n' { self.parse_ident(~"ull", null) } - 't' { self.parse_ident(~"rue", boolean(true)) } - 'f' { self.parse_ident(~"alse", boolean(false)) } - '0' to '9' | '-' { self.parse_number() } - '"' { - alt self.parse_str() { - ok(s) { ok(string(s)) } - err(e) { err(e) } - } + 'n' => self.parse_ident(~"ull", null), + 't' => self.parse_ident(~"rue", boolean(true)), + 'f' => self.parse_ident(~"alse", boolean(false)), + '0' to '9' | '-' => self.parse_number(), + '"' => alt self.parse_str() { + ok(s) => ok(string(s)), + err(e) => err(e) } - '[' { self.parse_list() } - '{' { self.parse_object() } - _ { self.error(~"invalid syntax") } + '[' => self.parse_list(), + '{' => self.parse_object(), + _ => self.error(~"invalid syntax") } } @@ -209,21 +201,21 @@ impl parser for parser { } let mut res = alt self.parse_integer() { - ok(res) { res } - err(e) { return err(e); } + ok(res) => res, + err(e) => return err(e) }; if self.ch == '.' { alt self.parse_decimal(res) { - ok(r) { res = r; } - err(e) { return err(e); } + ok(r) => res = r, + err(e) => return err(e) } } if self.ch == 'e' || self.ch == 'E' { alt self.parse_exponent(res) { - ok(r) { res = r; } - err(e) { return err(e); } + ok(r) => res = r, + err(e) => return err(e) } } @@ -234,29 +226,29 @@ impl parser for parser { let mut res = 0f; alt self.ch { - '0' { + '0' => { self.bump(); // There can be only one leading '0'. alt self.ch { - '0' to '9' { return self.error(~"invalid number"); } - _ {} + '0' to '9' => return self.error(~"invalid number"), + _ => () } } - '1' to '9' { + '1' to '9' => { while !self.eof() { alt self.ch { - '0' to '9' { + '0' to '9' => { res *= 10f; res += ((self.ch as int) - ('0' as int)) as float; self.bump(); } - _ { break; } + _ => break } } } - _ { return self.error(~"invalid number"); } + _ => return self.error(~"invalid number") } ok(res) @@ -267,21 +259,21 @@ impl parser for parser { // Make sure a digit follows the decimal place. alt self.ch { - '0' to '9' {} - _ { return self.error(~"invalid number"); } + '0' to '9' => (), + _ => return self.error(~"invalid number") } let mut res = res; let mut dec = 1f; while !self.eof() { alt self.ch { - '0' to '9' { + '0' to '9' => { dec /= 10f; res += (((self.ch as int) - ('0' as int)) as float) * dec; self.bump(); } - _ { break; } + _ => break } } @@ -296,26 +288,26 @@ impl parser for parser { let mut neg_exp = false; alt self.ch { - '+' { self.bump(); } - '-' { self.bump(); neg_exp = true; } - _ {} + '+' => self.bump(), + '-' => { self.bump(); neg_exp = true; } + _ => () } // Make sure a digit follows the exponent place. alt self.ch { - '0' to '9' {} - _ { return self.error(~"invalid number"); } + '0' to '9' => (), + _ => return self.error(~"invalid number") } while !self.eof() { alt self.ch { - '0' to '9' { + '0' to '9' => { exp *= 10u; exp += (self.ch as uint) - ('0' as uint); self.bump(); } - _ { break; } + _ => break } } @@ -338,25 +330,25 @@ impl parser for parser { if (escape) { alt self.ch { - '"' { str::push_char(res, '"'); } - '\\' { str::push_char(res, '\\'); } - '/' { str::push_char(res, '/'); } - 'b' { str::push_char(res, '\x08'); } - 'f' { str::push_char(res, '\x0c'); } - 'n' { str::push_char(res, '\n'); } - 'r' { str::push_char(res, '\r'); } - 't' { str::push_char(res, '\t'); } - 'u' { + '"' => str::push_char(res, '"'), + '\\' => str::push_char(res, '\\'), + '/' => str::push_char(res, '/'), + 'b' => str::push_char(res, '\x08'), + 'f' => str::push_char(res, '\x0c'), + 'n' => str::push_char(res, '\n'), + 'r' => str::push_char(res, '\r'), + 't' => str::push_char(res, '\t'), + 'u' => { // Parse \u1234. let mut i = 0u; let mut n = 0u; while i < 4u { alt self.next_char() { - '0' to '9' { + '0' to '9' => { n = n * 10u + (self.ch as uint) - ('0' as uint); } - _ { return self.error(~"invalid \\u escape"); } + _ => return self.error(~"invalid \\u escape") } i += 1u; } @@ -368,7 +360,7 @@ impl parser for parser { str::push_char(res, n as char); } - _ { return self.error(~"invalid escape"); } + _ => return self.error(~"invalid escape") } escape = false; } else if self.ch == '\\' { @@ -398,8 +390,8 @@ impl parser for parser { loop { alt self.parse_value() { - ok(v) { vec::push(values, v); } - e { return e; } + ok(v) => vec::push(values, v), + e => return e } self.parse_whitespace(); @@ -408,9 +400,9 @@ impl parser for parser { } alt self.ch { - ',' { self.bump(); } - ']' { self.bump(); return ok(list(@values)); } - _ { return self.error(~"expected `,` or `]`"); } + ',' => self.bump(), + ']' => { self.bump(); return ok(list(@values)); } + _ => return self.error(~"expected `,` or `]`") } }; } @@ -434,8 +426,8 @@ impl parser for parser { } let key = alt self.parse_str() { - ok(key) { key } - err(e) { return err(e); } + ok(key) => key, + err(e) => return err(e) }; self.parse_whitespace(); @@ -447,15 +439,15 @@ impl parser for parser { self.bump(); alt self.parse_value() { - ok(value) { values.insert(copy *key, value); } - e { return e; } + ok(value) => { values.insert(copy *key, value); } + e => return e } self.parse_whitespace(); alt self.ch { - ',' { self.bump(); } - '}' { self.bump(); return ok(dict(values)); } - _ { + ',' => self.bump(), + '}' => { self.bump(); return ok(dict(values)); } + _ => { if self.eof() { break; } return self.error(~"expected `,` or `}`"); } @@ -486,18 +478,17 @@ fn from_str(s: ~str) -> result<json, error> { /// Test if two json values are equal fn eq(value0: json, value1: json) -> bool { alt (value0, value1) { - (num(f0), num(f1)) { f0 == f1 } - (string(s0), string(s1)) { s0 == s1 } - (boolean(b0), boolean(b1)) { b0 == b1 } - (list(l0), list(l1)) { vec::all2(*l0, *l1, eq) } - (dict(d0), dict(d1)) { + (num(f0), num(f1)) => f0 == f1, + (string(s0), string(s1)) => s0 == s1, + (boolean(b0), boolean(b1)) => b0 == b1, + (list(l0), list(l1)) => vec::all2(*l0, *l1, eq), + (dict(d0), dict(d1)) => { if d0.size() == d1.size() { let mut equal = true; for d0.each |k, v0| { alt d1.find(k) { - some(v1) { - if !eq(v0, v1) { equal = false; } } - none { equal = false; } + some(v1) => if !eq(v0, v1) { equal = false }, + none => equal = false } }; equal @@ -505,8 +496,8 @@ fn eq(value0: json, value1: json) -> bool { false } } - (null, null) { true } - _ { false } + (null, null) => true, + _ => false } } @@ -626,8 +617,8 @@ impl <A: to_json copy> of to_json for hashmap<~str, A> { impl <A: to_json> of to_json for option<A> { fn to_json() -> json { alt self { - none { null } - some(value) { value.to_json() } + none => null, + some(value) => value.to_json() } } } diff --git a/src/libstd/list.rs b/src/libstd/list.rs index 019c9cce632..3538929e728 100644 --- a/src/libstd/list.rs +++ b/src/libstd/list.rs @@ -44,11 +44,11 @@ fn find<T: copy>(ls: @list<T>, f: fn(T) -> bool) -> option<T> { let mut ls = ls; loop { ls = alt *ls { - cons(hd, tl) { + cons(hd, tl) => { if f(hd) { return some(hd); } tl } - nil { return none; } + nil => return none } }; } @@ -64,8 +64,8 @@ fn has<T: copy>(ls: @list<T>, elt: T) -> bool { /// Returns true if the list is empty pure fn is_empty<T: copy>(ls: @list<T>) -> bool { alt *ls { - nil { true } - _ { false } + nil => true, + _ => false } } @@ -84,21 +84,24 @@ fn len<T>(ls: @list<T>) -> uint { /// Returns all but the first element of a list pure fn tail<T: copy>(ls: @list<T>) -> @list<T> { alt *ls { - cons(_, tl) { return tl; } - nil { fail ~"list empty" } + cons(_, tl) => return tl, + nil => fail ~"list empty" } } /// Returns the first element of a list pure fn head<T: copy>(ls: @list<T>) -> T { - alt check *ls { cons(hd, _) { hd } } + alt check *ls { cons(hd, _) => hd } } /// Appends one list to another pure fn append<T: copy>(l: @list<T>, m: @list<T>) -> @list<T> { alt *l { - nil { return m; } - cons(x, xs) { let rest = append(xs, m); return @cons(x, rest); } + nil => return m, + cons(x, xs) => { + let rest = append(xs, m); + return @cons(x, rest); + } } } @@ -112,11 +115,11 @@ fn iter<T>(l: @list<T>, f: fn(T)) { let mut cur = l; loop { cur = alt *cur { - cons(hd, tl) { + cons(hd, tl) => { f(hd); tl } - nil { break; } + nil => break } } } @@ -126,11 +129,11 @@ fn each<T>(l: @list<T>, f: fn(T) -> bool) { let mut cur = l; loop { cur = alt *cur { - cons(hd, tl) { + cons(hd, tl) => { if !f(hd) { return; } tl } - nil { break; } + nil => break } } } diff --git a/src/libstd/map.rs b/src/libstd/map.rs index e4d1471017f..2b99c4cb8aa 100644 --- a/src/libstd/map.rs +++ b/src/libstd/map.rs @@ -134,12 +134,12 @@ mod chained { let mut comp = 1u; // for logging loop { alt copy e0.next { - none { + none => { debug!{"search_tbl: absent, comp %u, hash %u, idx %u", comp, h, idx}; return not_found; } - some(e1) { + some(e1) => { comp += 1u; if e1.hash == h && self.eqer(&e1.key, k) { debug!{"search_tbl: present, comp %u, \ @@ -157,12 +157,12 @@ mod chained { fn search_tbl(k: &K, h: uint) -> search_result<K,V> { let idx = h % vec::len(self.chains); alt copy self.chains[idx] { - none { + none => { debug!{"search_tbl: none, comp %u, hash %u, idx %u", 0u, h, idx}; return not_found; } - some(e) { + some(e) => { if e.hash == h && self.eqer(&e.key, k) { debug!{"search_tbl: present, comp %u, hash %u, idx %u", 1u, h, idx}; @@ -194,8 +194,8 @@ mod chained { let mut chain = self.chains[i]; loop { chain = alt chain { - none { break; } - some(entry) { + none => break, + some(entry) => { let next = entry.next; if !blk(entry) { return; } next @@ -217,15 +217,15 @@ mod chained { fn contains_key_ref(k: &K) -> bool { let hash = self.hasher(k); alt self.search_tbl(k, hash) { - not_found {false} - found_first(*) | found_after(*) {true} + not_found => false, + found_first(*) | found_after(*) => true } } fn insert(+k: K, +v: V) -> bool { let hash = self.hasher(&k); alt self.search_tbl(&k, hash) { - not_found { + not_found => { self.count += 1u; let idx = hash % vec::len(self.chains); let old_chain = self.chains[idx]; @@ -245,7 +245,7 @@ mod chained { return true; } - found_first(idx, entry) { + found_first(idx, entry) => { self.chains[idx] = some(@entry { hash: hash, key: k, @@ -253,7 +253,7 @@ mod chained { next: entry.next}); return false; } - found_after(prev, entry) { + found_after(prev, entry) => { prev.next = some(@entry { hash: hash, key: k, @@ -266,9 +266,9 @@ mod chained { fn find(+k: K) -> option<V> { alt self.search_tbl(&k, self.hasher(&k)) { - not_found {none} - found_first(_, entry) {some(entry.value)} - found_after(_, entry) {some(entry.value)} + not_found => none, + found_first(_, entry) => some(entry.value), + found_after(_, entry) => some(entry.value) } } @@ -282,13 +282,13 @@ mod chained { fn remove(+k: K) -> option<V> { alt self.search_tbl(&k, self.hasher(&k)) { - not_found {none} - found_first(idx, entry) { + not_found => none, + found_first(idx, entry) => { self.count -= 1u; self.chains[idx] = entry.next; some(entry.value) } - found_after(eprev, entry) { + found_after(eprev, entry) => { self.count -= 1u; eprev.next = entry.next; some(entry.value) @@ -639,8 +639,8 @@ mod tests { while i < num_to_insert { let v = hm.remove(i); alt v { - option::some(u) { assert (u == i * i); } - option::none { fail; } + option::some(u) => assert (u == i * i), + option::none => fail } i += 2u; } diff --git a/src/libstd/net_ip.rs b/src/libstd/net_ip.rs index cb77f72038a..1cc8dd3bed9 100644 --- a/src/libstd/net_ip.rs +++ b/src/libstd/net_ip.rs @@ -48,23 +48,19 @@ type parse_addr_err = { */ fn format_addr(ip: ip_addr) -> ~str { alt ip { - ipv4(addr) { - unsafe { - let result = uv_ip4_name(&addr); - if result == ~"" { - fail ~"failed to convert inner sockaddr_in address to str" - } - result + ipv4(addr) => unsafe { + let result = uv_ip4_name(&addr); + if result == ~"" { + fail ~"failed to convert inner sockaddr_in address to str" } + result } - ipv6(addr) { - unsafe { - let result = uv_ip6_name(&addr); - if result == ~"" { - fail ~"failed to convert inner sockaddr_in address to str" - } - result + ipv6(addr) => unsafe { + let result = uv_ip6_name(&addr); + if result == ~"" { + fail ~"failed to convert inner sockaddr_in address to str" } + result } } } @@ -108,10 +104,10 @@ fn get_addr(++node: ~str, iotask: iotask) ptr::null(), ptr::null()); alt result { - 0i32 { + 0i32 => { set_data_for_req(handle_ptr, handle_data_ptr); } - _ { + _ => { output_ch.send(result::err(get_addr_unknown_error)); } } @@ -139,10 +135,8 @@ mod v4 { */ fn parse_addr(ip: ~str) -> ip_addr { alt try_parse_addr(ip) { - result::ok(addr) { copy(addr) } - result::err(err_data) { - fail err_data.err_msg - } + result::ok(addr) => copy(addr), + result::err(err_data) => fail err_data.err_msg } } // the simple, old style numberic representation of @@ -162,8 +156,8 @@ mod v4 { fn parse_to_ipv4_rep(ip: ~str) -> result::result<ipv4_rep, ~str> { let parts = vec::map(str::split_char(ip, '.'), |s| { alt uint::from_str(s) { - some(n) if n <= 255u { n } - _ { 256u } + some(n) if n <= 255u => n, + _ => 256u } }); if vec::len(parts) != 4u { @@ -227,10 +221,8 @@ mod v6 { */ fn parse_addr(ip: ~str) -> ip_addr { alt try_parse_addr(ip) { - result::ok(addr) { copy(addr) } - result::err(err_data) { - fail err_data.err_msg - } + result::ok(addr) => copy(addr), + result::err(err_data) => fail err_data.err_msg } } fn try_parse_addr(ip: ~str) -> result::result<ip_addr,parse_addr_err> { @@ -335,11 +327,11 @@ mod test { #[test] fn test_ip_ipv4_bad_parse() { alt v4::try_parse_addr(~"b4df00d") { - result::err(err_info) { + result::err(err_info) => { log(debug, fmt!{"got error as expected %?", err_info}); assert true; } - result::ok(addr) { + result::ok(addr) => { fail fmt!{"Expected failure, but got addr %?", addr}; } } @@ -348,11 +340,11 @@ mod test { #[ignore(target_os="win32")] fn test_ip_ipv6_bad_parse() { alt v6::try_parse_addr(~"::,~2234k;") { - result::err(err_info) { + result::err(err_info) => { log(debug, fmt!{"got error as expected %?", err_info}); assert true; } - result::ok(addr) { + result::ok(addr) => { fail fmt!{"Expected failure, but got addr %?", addr}; } } @@ -373,12 +365,8 @@ mod test { localhost_name, vec::len(results)}); for vec::each(results) |r| { let ipv_prefix = alt r { - ipv4(_) { - ~"IPv4" - } - ipv6(_) { - ~"IPv6" - } + ipv4(_) => ~"IPv4", + ipv6(_) => ~"IPv6" }; log(debug, fmt!{"test_get_addr: result %s: '%s'", ipv_prefix, format_addr(r)}); diff --git a/src/libstd/net_tcp.rs b/src/libstd/net_tcp.rs index 2cacd9de475..2ce47a641c1 100644 --- a/src/libstd/net_tcp.rs +++ b/src/libstd/net_tcp.rs @@ -152,16 +152,16 @@ fn connect(-input_ip: ip::ip_addr, port: uint, log(debug, fmt!{"stream_handle_ptr in interact %?", stream_handle_ptr}); alt uv::ll::tcp_init( loop_ptr, stream_handle_ptr) { - 0i32 { + 0i32 => { log(debug, ~"tcp_init successful"); alt input_ip { - ipv4 { + ipv4 => { log(debug, ~"dealing w/ ipv4 connection.."); let connect_req_ptr = ptr::addr_of((*socket_data_ptr).connect_req); let addr_str = ip::format_addr(input_ip); let connect_result = alt input_ip { - ip::ipv4(addr) { + ip::ipv4(addr) => { // have to "recreate" the sockaddr_in/6 // since the ip_addr discards the port // info.. should probably add an additional @@ -175,7 +175,7 @@ fn connect(-input_ip: ip::ip_addr, port: uint, ptr::addr_of(in_addr), tcp_connect_on_connect_cb) } - ip::ipv6(addr) { + ip::ipv6(addr) => { log(debug, fmt!{"addr: %?", addr}); let in_addr = uv::ll::ip6_addr(addr_str, port as int); uv::ll::tcp_connect6( @@ -186,7 +186,7 @@ fn connect(-input_ip: ip::ip_addr, port: uint, } }; alt connect_result { - 0i32 { + 0i32 => { log(debug, ~"tcp_connect successful"); // reusable data that we'll have for the // duration.. @@ -201,7 +201,7 @@ fn connect(-input_ip: ip::ip_addr, port: uint, // let tcp_connect_on_connect_cb send on // the result_ch, now.. } - _ { + _ => { // immediate connect failure.. probably a garbage // ip or somesuch let err_data = uv::ll::get_last_err_data(loop_ptr); @@ -215,7 +215,7 @@ fn connect(-input_ip: ip::ip_addr, port: uint, } } } - _ { + _ => { // failure to create a tcp handle let err_data = uv::ll::get_last_err_data(loop_ptr); comm::send((*conn_data_ptr).result_ch, @@ -224,19 +224,19 @@ fn connect(-input_ip: ip::ip_addr, port: uint, } }; alt comm::recv(result_po) { - conn_success { + conn_success => { log(debug, ~"tcp::connect - received success on result_po"); result::ok(tcp_socket(socket_data)) } - conn_failure(err_data) { + conn_failure(err_data) => { comm::recv(closed_signal_po); log(debug, ~"tcp::connect - received failure on result_po"); // still have to free the malloc'd stream handle.. rustrt::rust_uv_current_kernel_free(stream_handle_ptr as *libc::c_void); let tcp_conn_err = alt err_data.err_name { - ~"ECONNREFUSED" { connection_refused } - _ { generic_connect_err(err_data.err_name, err_data.err_msg) } + ~"ECONNREFUSED" => connection_refused, + _ => generic_connect_err(err_data.err_name, err_data.err_msg) }; result::err(tcp_conn_err) } @@ -470,7 +470,7 @@ fn accept(new_conn: tcp_new_connection) -> result::result<tcp_socket, tcp_err_data> unsafe { alt new_conn{ - new_tcp_conn(server_handle_ptr) { + new_tcp_conn(server_handle_ptr) => { let server_data_ptr = uv::ll::get_data_for_uv_handle( server_handle_ptr) as *tcp_listen_fc_data; let reader_po = comm::port::<result::result<~[u8], tcp_err_data>>(); @@ -502,26 +502,26 @@ fn accept(new_conn: tcp_new_connection) let loop_ptr = uv::ll::get_loop_for_uv_handle( server_handle_ptr); alt uv::ll::tcp_init(loop_ptr, client_stream_handle_ptr) { - 0i32 { + 0i32 => { log(debug, ~"uv_tcp_init successful for client stream"); alt uv::ll::accept( server_handle_ptr as *libc::c_void, client_stream_handle_ptr as *libc::c_void) { - 0i32 { + 0i32 => { log(debug, ~"successfully accepted client connection"); uv::ll::set_data_for_uv_handle(client_stream_handle_ptr, client_socket_data_ptr as *libc::c_void); comm::send(result_ch, none); } - _ { + _ => { log(debug, ~"failed to accept client conn"); comm::send(result_ch, some( uv::ll::get_last_err_data(loop_ptr).to_tcp_err())); } } } - _ { + _ => { log(debug, ~"failed to init client stream"); comm::send(result_ch, some( uv::ll::get_last_err_data(loop_ptr).to_tcp_err())); @@ -529,12 +529,8 @@ fn accept(new_conn: tcp_new_connection) } // UNSAFE LIBUV INTERACTION END alt comm::recv(result_po) { - some(err_data) { - result::err(err_data) - } - none { - result::ok(tcp_socket(client_socket_data)) - } + some(err_data) => result::err(err_data), + none => result::ok(tcp_socket(client_socket_data)) } } } @@ -615,19 +611,19 @@ fn listen_common(-host_ip: ip::ip_addr, port: uint, backlog: uint, let loc_ip = copy(host_ip); do iotask::interact(iotask) |loop_ptr| { alt uv::ll::tcp_init(loop_ptr, server_stream_ptr) { - 0i32 { + 0i32 => { uv::ll::set_data_for_uv_handle( server_stream_ptr, server_data_ptr); let addr_str = ip::format_addr(loc_ip); let bind_result = alt loc_ip { - ip::ipv4(addr) { + ip::ipv4(addr) => { log(debug, fmt!{"addr: %?", addr}); let in_addr = uv::ll::ip4_addr(addr_str, port as int); uv::ll::tcp_bind(server_stream_ptr, ptr::addr_of(in_addr)) } - ip::ipv6(addr) { + ip::ipv6(addr) => { log(debug, fmt!{"addr: %?", addr}); let in_addr = uv::ll::ip6_addr(addr_str, port as int); uv::ll::tcp_bind6(server_stream_ptr, @@ -635,28 +631,26 @@ fn listen_common(-host_ip: ip::ip_addr, port: uint, backlog: uint, } }; alt bind_result { - 0i32 { + 0i32 => { alt uv::ll::listen(server_stream_ptr, backlog as libc::c_int, tcp_lfc_on_connection_cb) { - 0i32 { - comm::send(setup_ch, none); - } - _ { + 0i32 => comm::send(setup_ch, none), + _ => { log(debug, ~"failure to uv_listen()"); let err_data = uv::ll::get_last_err_data(loop_ptr); comm::send(setup_ch, some(err_data)); } } } - _ { + _ => { log(debug, ~"failure to uv_tcp_bind"); let err_data = uv::ll::get_last_err_data(loop_ptr); comm::send(setup_ch, some(err_data)); } } } - _ { + _ => { log(debug, ~"failure to uv_tcp_init"); let err_data = uv::ll::get_last_err_data(loop_ptr); comm::send(setup_ch, some(err_data)); @@ -666,7 +660,7 @@ fn listen_common(-host_ip: ip::ip_addr, port: uint, backlog: uint, setup_ch.recv() }; alt setup_result { - some(err_data) { + some(err_data) => { do iotask::interact(iotask) |loop_ptr| { log(debug, fmt!{"tcp::listen post-kill recv hl interact %?", loop_ptr}); @@ -675,15 +669,15 @@ fn listen_common(-host_ip: ip::ip_addr, port: uint, backlog: uint, }; stream_closed_po.recv(); alt err_data.err_name { - ~"EACCES" { + ~"EACCES" => { log(debug, ~"Got EACCES error"); result::err(access_denied) } - ~"EADDRINUSE" { + ~"EADDRINUSE" => { log(debug, ~"Got EADDRINUSE error"); result::err(address_in_use) } - _ { + _ => { log(debug, fmt!{"Got '%s' '%s' libuv error", err_data.err_name, err_data.err_msg}); result::err( @@ -691,7 +685,7 @@ fn listen_common(-host_ip: ip::ip_addr, port: uint, backlog: uint, } } } - none { + none => { on_establish_cb(kill_ch); let kill_result = comm::recv(kill_po); do iotask::interact(iotask) |loop_ptr| { @@ -703,14 +697,10 @@ fn listen_common(-host_ip: ip::ip_addr, port: uint, backlog: uint, stream_closed_po.recv(); alt kill_result { // some failure post bind/listen - some(err_data) { - result::err(generic_listen_err(err_data.err_name, - err_data.err_msg)) - } + some(err_data) => result::err(generic_listen_err(err_data.err_name, + err_data.err_msg)), // clean exit - none { - result::ok(()) - } + none => result::ok(()) } } } @@ -889,7 +879,7 @@ fn read_common_impl(socket_data: *tcp_socket_data, timeout_msecs: uint) }; log(debug, ~"tcp::read after recv_timeout"); alt read_result { - none { + none => { log(debug, ~"tcp::read: timed out.."); let err_data = { err_name: ~"TIMEOUT", @@ -898,7 +888,7 @@ fn read_common_impl(socket_data: *tcp_socket_data, timeout_msecs: uint) read_stop_common_impl(socket_data); result::err(err_data) } - some(data_result) { + some(data_result) => { log(debug, ~"tcp::read got data"); read_stop_common_impl(socket_data); data_result @@ -916,11 +906,11 @@ fn read_stop_common_impl(socket_data: *tcp_socket_data) -> do iotask::interact((*socket_data).iotask) |loop_ptr| { log(debug, ~"in interact cb for tcp::read_stop"); alt uv::ll::read_stop(stream_handle_ptr as *uv::ll::uv_stream_t) { - 0i32 { + 0i32 => { log(debug, ~"successfully called uv_read_stop"); comm::send(stop_ch, none); } - _ { + _ => { log(debug, ~"failure in calling uv_read_stop"); let err_data = uv::ll::get_last_err_data(loop_ptr); comm::send(stop_ch, some(err_data.to_tcp_err())); @@ -928,12 +918,8 @@ fn read_stop_common_impl(socket_data: *tcp_socket_data) -> } }; alt comm::recv(stop_po) { - some(err_data) { - result::err(err_data.to_tcp_err()) - } - none { - result::ok(()) - } + some(err_data) => result::err(err_data.to_tcp_err()), + none => result::ok(()) } } @@ -950,11 +936,11 @@ fn read_start_common_impl(socket_data: *tcp_socket_data) alt uv::ll::read_start(stream_handle_ptr as *uv::ll::uv_stream_t, on_alloc_cb, on_tcp_read_cb) { - 0i32 { + 0i32 => { log(debug, ~"success doing uv_read_start"); comm::send(start_ch, none); } - _ { + _ => { log(debug, ~"error attempting uv_read_start"); let err_data = uv::ll::get_last_err_data(loop_ptr); comm::send(start_ch, some(err_data)); @@ -962,12 +948,8 @@ fn read_start_common_impl(socket_data: *tcp_socket_data) } }; alt comm::recv(start_po) { - some(err_data) { - result::err(err_data.to_tcp_err()) - } - none { - result::ok((*socket_data).reader_po) - } + some(err_data) => result::err(err_data.to_tcp_err()), + none => result::ok((*socket_data).reader_po) } } @@ -995,11 +977,11 @@ fn write_common_impl(socket_data_ptr: *tcp_socket_data, stream_handle_ptr, write_buf_vec_ptr, tcp_write_complete_cb) { - 0i32 { + 0i32 => { log(debug, ~"uv_write() invoked successfully"); uv::ll::set_data_for_req(write_req_ptr, write_data_ptr); } - _ { + _ => { log(debug, ~"error invoking uv_write()"); let err_data = uv::ll::get_last_err_data(loop_ptr); comm::send((*write_data_ptr).result_ch, @@ -1012,8 +994,8 @@ fn write_common_impl(socket_data_ptr: *tcp_socket_data, // ownership of everything to the I/O task and let it deal with the // aftermath, so we don't have to sit here blocking. alt comm::recv(result_po) { - tcp_write_success { result::ok(()) } - tcp_write_error(err_data) { result::err(err_data.to_tcp_err()) } + tcp_write_success => result::ok(()), + tcp_write_error(err_data) => result::err(err_data.to_tcp_err()) } } @@ -1043,10 +1025,8 @@ extern fn tcp_lfc_on_connection_cb(handle: *uv::ll::uv_tcp_t, let kill_ch = (*server_data_ptr).kill_ch; if (*server_data_ptr).active { alt status { - 0i32 { - (*server_data_ptr).on_connect_cb(handle); - } - _ { + 0i32 => (*server_data_ptr).on_connect_cb(handle), + _ => { let loop_ptr = uv::ll::get_loop_for_uv_handle(handle); comm::send(kill_ch, some(uv::ll::get_last_err_data(loop_ptr) @@ -1103,7 +1083,7 @@ extern fn on_tcp_read_cb(stream: *uv::ll::uv_stream_t, as *tcp_socket_data; alt nread as int { // incoming err.. probably eof - -1 { + -1 => { let err_data = uv::ll::get_last_err_data(loop_ptr).to_tcp_err(); log(debug, fmt!{"on_tcp_read_cb: incoming err.. name %? msg %?", err_data.err_name, err_data.err_msg}); @@ -1111,9 +1091,9 @@ extern fn on_tcp_read_cb(stream: *uv::ll::uv_stream_t, comm::send(reader_ch, result::err(err_data)); } // do nothing .. unneeded buf - 0 {} + 0 => (), // have data - _ { + _ => { // we have data log(debug, fmt!{"tcp on_read_cb nread: %d", nread as int}); let reader_ch = (*socket_data_ptr).reader_ch; @@ -1196,11 +1176,11 @@ extern fn tcp_connect_on_connect_cb(connect_req_ptr: *uv::ll::uv_connect_t, let tcp_stream_ptr = uv::ll::get_stream_handle_from_connect_req(connect_req_ptr); alt status { - 0i32 { + 0i32 => { log(debug, ~"successful tcp connection!"); comm::send(result_ch, conn_success); } - _ { + _ => { log(debug, ~"error in tcp_connect_on_connect_cb"); let loop_ptr = uv::ll::get_loop_for_uv_handle(tcp_stream_ptr); let err_data = uv::ll::get_last_err_data(loop_ptr); @@ -1357,11 +1337,8 @@ mod test { hl_loop) }; alt actual_resp_result.get_err() { - connection_refused { - } - _ { - fail ~"unknown error.. expected connection_refused" - } + connection_refused => (), + _ => fail ~"unknown error.. expected connection_refused" } } fn impl_gl_tcp_ipv4_server_address_in_use() { @@ -1406,12 +1383,12 @@ mod test { hl_loop) }; alt listen_err { - address_in_use { + address_in_use => { assert true; } - _ { + _ => { fail ~"expected address_in_use listen error,"+ - ~"but got a different error varient. check logs."; + ~"but got a different error varient. check logs."; } } } @@ -1425,10 +1402,10 @@ mod test { server_port, hl_loop); alt listen_err { - access_denied { + access_denied => { assert true; } - _ { + _ => { fail ~"expected address_in_use listen error,"+ ~"but got a different error varient. check logs."; } @@ -1539,7 +1516,7 @@ mod test { ~"connection!"); let received_req_bytes = read(sock, 0u); alt received_req_bytes { - result::ok(data) { + result::ok(data) => { log(debug, ~"SERVER: got REQ str::from_bytes.."); log(debug, fmt!{"SERVER: REQ data len: %?", vec::len(data)}); @@ -1550,7 +1527,7 @@ mod test { log(debug, ~"SERVER: after write.. die"); comm::send(kill_ch, none); } - result::err(err_data) { + result::err(err_data) => { log(debug, fmt!{"SERVER: error recvd: %s %s", err_data.err_name, err_data.err_msg}); comm::send(kill_ch, some(err_data)); @@ -1568,14 +1545,14 @@ mod test { // err check on listen_result if result::is_err(listen_result) { alt result::get_err(listen_result) { - generic_listen_err(name, msg) { + generic_listen_err(name, msg) => { fail fmt!{"SERVER: exited abnormally name %s msg %s", name, msg}; } - access_denied { + access_denied => { fail ~"SERVER: exited abnormally, got access denied.."; } - address_in_use { + address_in_use => { fail ~"SERVER: exited abnormally, got address in use..."; } } diff --git a/src/libstd/net_url.rs b/src/libstd/net_url.rs index dd97c1fdeb2..d43a8add1cc 100644 --- a/src/libstd/net_url.rs +++ b/src/libstd/net_url.rs @@ -52,22 +52,22 @@ fn encode_inner(s: ~str, full_url: bool) -> ~str { 'A' to 'Z' | 'a' to 'z' | '0' to '9' | - '-' | '.' | '_' | '~' { + '-' | '.' | '_' | '~' => { str::push_char(out, ch); } - _ { - if full_url { + _ => { + if full_url { match ch { // gen-delims: ':' | '/' | '?' | '#' | '[' | ']' | '@' | // sub-delims: '!' | '$' | '&' | '"' | '(' | ')' | '*' | - '+' | ',' | ';' | '=' { + '+' | ',' | ';' | '=' => { str::push_char(out, ch); } - _ { out += #fmt("%%%X", ch as uint); } + _ => out += #fmt("%%%X", ch as uint) } } else { out += #fmt("%%%X", ch as uint); @@ -106,7 +106,7 @@ fn decode_inner(s: ~str, full_url: bool) -> ~str { while !rdr.eof() { match rdr.read_char() { - '%' { + '%' => { let bytes = rdr.read_bytes(2u); let ch = uint::parse_buf(bytes, 16u).get() as char; @@ -118,19 +118,19 @@ fn decode_inner(s: ~str, full_url: bool) -> ~str { // sub-delims: '!' | '$' | '&' | '"' | '(' | ')' | '*' | - '+' | ',' | ';' | '=' { + '+' | ',' | ';' | '=' => { str::push_char(out, '%'); str::push_char(out, bytes[0u] as char); str::push_char(out, bytes[1u] as char); } - ch { str::push_char(out, ch); } + ch => str::push_char(out, ch) } } else { str::push_char(out, ch); } } - ch { str::push_char(out, ch); } + ch => str::push_char(out, ch) } } @@ -161,11 +161,11 @@ fn encode_plus(s: ~str) -> ~str { while !rdr.eof() { let ch = rdr.read_byte() as char; match ch { - 'A' to 'Z' | 'a' to 'z' | '0' to '9' | '_' | '.' | '-' { + 'A' to 'Z' | 'a' to 'z' | '0' to '9' | '_' | '.' | '-' => { str::push_char(out, ch); } - ' ' { str::push_char(out, '+'); } - _ { out += #fmt("%%%X", ch as uint); } + ' ' => str::push_char(out, '+'), + _ => out += #fmt("%%%X", ch as uint) } } @@ -212,11 +212,11 @@ fn decode_form_urlencoded(s: ~[u8]) -> while !rdr.eof() { match rdr.read_char() { - '&' | ';' { + '&' | ';' => { if key != ~"" && value != ~"" { let values = match m.find(key) { - some(values) { values } - none { + some(values) => values, + none => { let values = @dvec(); m.insert(key, values); values @@ -229,14 +229,14 @@ fn decode_form_urlencoded(s: ~[u8]) -> key = ~""; value = ~""; } - '=' { parsing_key = false; } - ch { + '=' => parsing_key = false, + ch => { let ch = match ch { - '%' { + '%' => { uint::parse_buf(rdr.read_bytes(2u), 16u).get() as char } - '+' { ' ' } - ch { ch } + '+' => ' ', + ch => ch }; if parsing_key { @@ -250,8 +250,8 @@ fn decode_form_urlencoded(s: ~[u8]) -> if key != ~"" && value != ~"" { let values = match m.find(key) { - some(values) { values } - none { + some(values) => values, + none => { let values = @dvec(); m.insert(key, values); values @@ -333,14 +333,14 @@ fn query_to_str(query: query) -> ~str { fn get_scheme(rawurl: ~str) -> result::result<(~str, ~str), @~str> { for str::each_chari(rawurl) |i,c| { match c { - 'A' to 'Z' | 'a' to 'z' { again; } - '0' to '9' | '+' | '-' | '.' { + 'A' to 'Z' | 'a' to 'z' => again, + '0' to '9' | '+' | '-' | '.' => { if i == 0 { return result::err(@~"url: Scheme must begin with a letter."); } again; } - ':' { + ':' => { if i == 0 { return result::err(@~"url: Scheme cannot be empty."); } else { @@ -348,7 +348,7 @@ fn get_scheme(rawurl: ~str) -> result::result<(~str, ~str), @~str> { rawurl.slice(i+1,str::len(rawurl)))); } } - _ { + _ => { return result::err(@~"url: Invalid character in scheme."); } } @@ -393,34 +393,34 @@ fn get_authority(rawurl: ~str) -> // deal with input class first match c { - '0' to '9' { } - 'A' to 'F' | 'a' to 'f' { + '0' to '9' => (), + 'A' to 'F' | 'a' to 'f' => { if in == digit { in = hex; } } 'G' to 'Z' | 'g' to 'z' | '-' | '.' | '_' | '~' | '%' | - '&' |'\'' | '(' | ')' | '+' | '!' | '*' | ',' | ';' | '=' { + '&' |'\'' | '(' | ')' | '+' | '!' | '*' | ',' | ';' | '=' => { in = unreserved; } - ':' | '@' | '?' | '#' | '/' { + ':' | '@' | '?' | '#' | '/' => { // separators, don't change anything } - _ { + _ => { return result::err(@~"Illegal character in authority"); } } // now process states match c { - ':' { + ':' => { colon_count += 1; match st { - start { + start => { pos = i; st = pass_host_port; } - pass_host_port { + pass_host_port => { // multiple colons means ipv6 address. if in == unreserved { return result::err( @@ -428,7 +428,7 @@ fn get_authority(rawurl: ~str) -> } st = ip6_host; } - in_host { + in_host => { pos = i; // can't be sure whether this is an ipv6 address or a port if in == unreserved { @@ -436,55 +436,55 @@ fn get_authority(rawurl: ~str) -> } st = ip6_port; } - ip6_port { + ip6_port => { if in == unreserved { return result::err(@~"Illegal characters in authority."); } st = ip6_host; } - ip6_host { + ip6_host => { if colon_count > 7 { host = str::slice(rawurl, begin, i); pos = i; st = in_port; } } - _ { + _ => { return result::err(@~"Invalid ':' in authority."); } } in = digit; // reset input class } - '@' { + '@' => { in = digit; // reset input class colon_count = 0; // reset count match st { - start { + start => { let user = str::slice(rawurl, begin, i); userinfo = option::some({user : user, pass: option::none}); st = in_host; } - pass_host_port { + pass_host_port => { let user = str::slice(rawurl, begin, pos); let pass = str::slice(rawurl, pos+1, i); userinfo = option::some({user: user, pass: option::some(pass)}); st = in_host; } - _ { + _ => { return result::err(@~"Invalid '@' in authority."); } } begin = i+1; } - '?' | '#' | '/' { + '?' | '#' | '/' => { end = i; break; } - _ { } + _ => () } end = i; } @@ -498,24 +498,24 @@ fn get_authority(rawurl: ~str) -> // finish up match st { - start { + start => { if host_is_end_plus_one() { host = str::slice(rawurl, begin, end+1); } else { host = str::slice(rawurl, begin, end); } } - pass_host_port | ip6_port { + pass_host_port | ip6_port => { if in != digit { return result::err(@~"Non-digit characters in port."); } host = str::slice(rawurl, begin, pos); port = option::some(str::slice(rawurl, pos+1, end)); } - ip6_host | in_host { + ip6_host | in_host => { host = str::slice(rawurl, begin, end); } - in_port { + in_port => { if in != digit { return result::err(@~"Non-digit characters in port."); } @@ -537,14 +537,14 @@ fn get_path(rawurl: ~str, authority : bool) -> for str::each_chari(rawurl) |i,c| { match c { 'A' to 'Z' | 'a' to 'z' | '0' to '9' | '&' |'\'' | '(' | ')' | '.' - | '@' | ':' | '%' | '/' | '+' | '!' | '*' | ',' | ';' | '=' { + | '@' | ':' | '%' | '/' | '+' | '!' | '*' | ',' | ';' | '=' => { again; } - '?' | '#' { + '?' | '#' => { end = i; break; } - _ { return result::err(@~"Invalid character in path.") } + _ => return result::err(@~"Invalid character in path.") } } diff --git a/src/libstd/rope.rs b/src/libstd/rope.rs index 8debc45a0e9..5c779e37507 100644 --- a/src/libstd/rope.rs +++ b/src/libstd/rope.rs @@ -134,13 +134,13 @@ fn prepend_str(rope: rope, str: @~str) -> rope { /// Concatenate two ropes fn append_rope(left: rope, right: rope) -> rope { alt(left) { - node::empty { return right; } - node::content(left_content) { + node::empty => return right, + node::content(left_content) => { alt(right) { - node::empty { return left; } - node::content(right_content) { + node::empty => return left, + node::content(right_content) => { return node::content(node::concat2(left_content, right_content)); - } + } } } } @@ -198,12 +198,10 @@ Section: Keeping ropes healthy */ fn bal(rope:rope) -> rope { alt(rope) { - node::empty { return rope } - node::content(x) { - alt(node::bal(x)) { - option::none { rope } - option::some(y) { node::content(y) } - } + node::empty => return rope, + node::content(x) => alt(node::bal(x)) { + option::none => rope, + option::some(y) => node::content(y) } } } @@ -229,12 +227,11 @@ Section: Transforming ropes fn sub_chars(rope: rope, char_offset: uint, char_len: uint) -> rope { if char_len == 0u { return node::empty; } alt(rope) { - node::empty { fail } - node::content(node) { - if char_len > node::char_len(node) { fail } - else { - return node::content(node::sub_chars(node, char_offset, char_len)) - } + node::empty => fail, + node::content(node) => if char_len > node::char_len(node) { + fail + } else { + return node::content(node::sub_chars(node, char_offset, char_len)) } } } @@ -255,12 +252,11 @@ fn sub_chars(rope: rope, char_offset: uint, char_len: uint) -> rope { fn sub_bytes(rope: rope, byte_offset: uint, byte_len: uint) -> rope { if byte_len == 0u { return node::empty; } alt(rope) { - node::empty { fail } - node::content(node) { - if byte_len > node::byte_len(node) { fail } - else { - return node::content(node::sub_bytes(node, byte_offset, byte_len)) - } + node::empty => fail, + node::content(node) =>if byte_len > node::byte_len(node) { + fail + } else { + return node::content(node::sub_bytes(node, byte_offset, byte_len)) } } } @@ -281,10 +277,10 @@ Section: Comparing ropes */ fn cmp(left: rope, right: rope) -> int { alt((left, right)) { - (node::empty, node::empty) { return 0; } - (node::empty, _) { return -1;} - (_, node::empty) { return 1;} - (node::content(a), node::content(b)) { + (node::empty, node::empty) => return 0, + (node::empty, _) => return -1, + (_, node::empty) => return 1, + (node::content(a), node::content(b)) => { return node::cmp(a, b); } } @@ -384,8 +380,8 @@ Section: Iterating */ fn loop_chars(rope: rope, it: fn(char) -> bool) -> bool { alt(rope) { - node::empty { return true } - node::content(x) { return node::loop_chars(x, it) } + node::empty => return true, + node::content(x) => return node::loop_chars(x, it) } } @@ -427,8 +423,8 @@ fn iter_chars(rope: rope, it: fn(char)) { */ fn loop_leaves(rope: rope, it: fn(node::leaf) -> bool) -> bool{ alt(rope) { - node::empty { return true } - node::content(x) {return node::loop_leaves(x, it)} + node::empty => return true, + node::content(x) => return node::loop_leaves(x, it) } } @@ -436,8 +432,8 @@ mod iterator { mod leaf { fn start(rope: rope) -> node::leaf_iterator::t { alt(rope) { - node::empty { return node::leaf_iterator::empty() } - node::content(x) { return node::leaf_iterator::start(x) } + node::empty => return node::leaf_iterator::empty(), + node::content(x) => return node::leaf_iterator::start(x) } } fn next(it: node::leaf_iterator::t) -> option<node::leaf> { @@ -447,8 +443,8 @@ mod iterator { mod char { fn start(rope: rope) -> node::char_iterator::t { alt(rope) { - node::empty { return node::char_iterator::empty() } - node::content(x) { return node::char_iterator::start(x) } + node::empty => return node::char_iterator::empty(), + node::content(x) => return node::char_iterator::start(x) } } fn next(it: node::char_iterator::t) -> option<char> { @@ -474,8 +470,8 @@ mod iterator { */ fn height(rope: rope) -> uint { alt(rope) { - node::empty { return 0u; } - node::content(x) { return node::height(x); } + node::empty => return 0u, + node::content(x) => return node::height(x) } } @@ -490,8 +486,8 @@ fn height(rope: rope) -> uint { */ pure fn char_len(rope: rope) -> uint { alt(rope) { - node::empty { return 0u; } - node::content(x) { return node::char_len(x) } + node::empty => return 0u, + node::content(x) => return node::char_len(x) } } @@ -504,8 +500,8 @@ pure fn char_len(rope: rope) -> uint { */ pure fn byte_len(rope: rope) -> uint { alt(rope) { - node::empty { return 0u; } - node::content(x) { return node::byte_len(x) } + node::empty => return 0u, + node::content(x) => return node::byte_len(x) } } @@ -527,8 +523,8 @@ pure fn byte_len(rope: rope) -> uint { */ fn char_at(rope: rope, pos: uint) -> char { alt(rope) { - node::empty { fail } - node::content(x) { return node::char_at(x, pos) } + node::empty => fail, + node::content(x) => return node::char_at(x, pos) } } @@ -735,15 +731,15 @@ mod node { pure fn byte_len(node: @node) -> uint { //FIXME (#2744): Could we do this without the pattern-matching? alt(*node) { - leaf(y) { return y.byte_len; } - concat(y){ return y.byte_len; } + leaf(y) => return y.byte_len, + concat(y) => return y.byte_len } } pure fn char_len(node: @node) -> uint { alt(*node) { - leaf(y) { return y.char_len; } - concat(y) { return y.char_len; } + leaf(y) => return y.char_len, + concat(y) => return y.char_len } } @@ -805,8 +801,8 @@ mod node { let it = leaf_iterator::start(node); loop { alt(leaf_iterator::next(it)) { - option::none { break; } - option::some(x) { + option::none => break, + option::some(x) => { //FIXME (#2744): Replace with memcpy or something similar let mut local_buf: ~[u8] = unsafe::reinterpret_cast(*x.content); @@ -832,8 +828,8 @@ mod node { */ fn flatten(node: @node) -> @node unsafe { alt(*node) { - leaf(_) { return node } - concat(x) { + leaf(_) => return node, + concat(x) => { return @leaf({ byte_offset: 0u, byte_len: x.byte_len, @@ -866,8 +862,8 @@ mod node { let it = leaf_iterator::start(node); loop { alt (leaf_iterator::next(it)) { - option::none { break; } - option::some(x) { vec::push(forest, @leaf(x)); } + option::none => break, + option::some(x) => vec::push(forest, @leaf(x)) } } //2. Rebuild tree from forest @@ -903,7 +899,7 @@ mod node { return node; } alt(*node) { - node::leaf(x) { + node::leaf(x) => { let char_len = str::count_chars(*x.content, byte_offset, byte_len); return @leaf({byte_offset: byte_offset, @@ -911,7 +907,7 @@ mod node { char_len: char_len, content: x.content}); } - node::concat(x) { + node::concat(x) => { let left_len: uint = node::byte_len(x.left); if byte_offset <= left_len { if byte_offset + byte_len <= left_len { @@ -961,7 +957,7 @@ mod node { let mut char_offset = char_offset; loop { alt(*node) { - node::leaf(x) { + node::leaf(x) => { if char_offset == 0u && char_len == x.char_len { return node; } @@ -974,7 +970,7 @@ mod node { char_len: char_len, content: x.content}); } - node::concat(x) { + node::concat(x) => { if char_offset == 0u && char_len == x.char_len {return node;} let left_len : uint = node::char_len(x.left); if char_offset <= left_len { @@ -1012,8 +1008,8 @@ mod node { fn height(node: @node) -> uint { alt(*node) { - leaf(_) { return 0u; } - concat(x) { return x.height; } + leaf(_) => return 0u, + concat(x) => return x.height } } @@ -1023,16 +1019,14 @@ mod node { let mut result = 0; while result == 0 { alt((char_iterator::next(ita), char_iterator::next(itb))) { - (option::none, option::none) { - break; - } - (option::some(chara), option::some(charb)) { + (option::none, option::none) => break, + (option::some(chara), option::some(charb)) => { result = char::cmp(chara, charb); } - (option::some(_), _) { + (option::some(_), _) => { result = 1; } - (_, option::some(_)) { + (_, option::some(_)) => { result = -1; } } @@ -1066,15 +1060,11 @@ mod node { let mut current = node; loop { alt(*current) { - leaf(x) { - return it(x); - } - concat(x) { - if loop_leaves(x.left, it) { //non tail call - current = x.right; //tail call - } else { - return false; - } + leaf(x) => return it(x), + concat(x) => if loop_leaves(x.left, it) { //non tail call + current = x.right; //tail call + } else { + return false; } } }; @@ -1102,10 +1092,8 @@ mod node { let mut pos = pos; loop { alt *node { - leaf(x) { - return str::char_at(*x.content, pos); - } - concat({left, right, _}) { + leaf(x) => return str::char_at(*x.content, pos), + concat({left, right, _}) => { let left_len = char_len(left); node = if left_len > pos { left } else { pos -= left_len; right }; @@ -1139,15 +1127,13 @@ mod node { let current = it.stack[it.stackpos]; it.stackpos -= 1; alt(*current) { - concat(x) { + concat(x) => { it.stackpos += 1; it.stack[it.stackpos] = x.right; it.stackpos += 1; it.stack[it.stackpos] = x.left; } - leaf(x) { - return option::some(x); - } + leaf(x) => return option::some(x) } }; } @@ -1179,16 +1165,12 @@ mod node { fn next(it: t) -> option<char> { loop { alt(get_current_or_next_leaf(it)) { - option::none { return option::none; } - option::some(_) { + option::none => return option::none, + option::some(_) => { let next_char = get_next_char_in_leaf(it); alt(next_char) { - option::none { - again; - } - option::some(_) { - return next_char; - } + option::none => again, + option::some(_) => return next_char } } } @@ -1197,12 +1179,12 @@ mod node { fn get_current_or_next_leaf(it: t) -> option<leaf> { alt(it.leaf) { - option::some(_) { return it.leaf } - option::none { + option::some(_) => return it.leaf, + option::none => { let next = leaf_iterator::next(it.leaf_iterator); alt(next) { - option::none { return option::none } - option::some(_) { + option::none => return option::none, + option::some(_) => { it.leaf = next; it.leaf_byte_pos = 0u; return next; @@ -1214,8 +1196,8 @@ mod node { fn get_next_char_in_leaf(it: t) -> option<char> { alt copy it.leaf { - option::none { return option::none } - option::some(aleaf) { + option::none => return option::none, + option::some(aleaf) => { if it.leaf_byte_pos >= aleaf.byte_len { //We are actually past the end of the leaf it.leaf = option::none; @@ -1239,17 +1221,17 @@ mod tests { //Utility function, used for sanity check fn rope_to_string(r: rope) -> ~str { alt(r) { - node::empty { return ~"" } - node::content(x) { + node::empty => return ~"", + node::content(x) => { let str = @mut ~""; fn aux(str: @mut ~str, node: @node::node) unsafe { alt(*node) { - node::leaf(x) { + node::leaf(x) => { *str += str::slice( *x.content, x.byte_offset, x.byte_offset + x.byte_len); } - node::concat(x) { + node::concat(x) => { aux(str, x.left); aux(str, x.right); } @@ -1293,11 +1275,11 @@ mod tests { let mut equal = true; while equal { alt(node::char_iterator::next(rope_iter)) { - option::none { + option::none => { if string_iter < string_len { equal = false; } break; } - option::some(c) { + option::some(c) => { let {ch, next} = str::char_range_at(*sample, string_iter); string_iter = next; if ch != c { equal = false; break; } @@ -1320,8 +1302,8 @@ mod tests { let it = iterator::char::start(r); loop { alt(node::char_iterator::next(it)) { - option::none { break; } - option::some(_) { len += 1u; } + option::none => break, + option::some(_) => len += 1u } } diff --git a/src/libstd/serialization.rs b/src/libstd/serialization.rs index 5be0ac26d23..622d31c00b9 100644 --- a/src/libstd/serialization.rs +++ b/src/libstd/serialization.rs @@ -244,16 +244,12 @@ fn deserialize_bool<D: deserializer>(d: D) -> bool { fn serialize_option<S: serializer,T>(s: S, v: option<T>, st: fn(T)) { do s.emit_enum(~"option") { alt v { - none { - do s.emit_enum_variant(~"none", 0u, 0u) { - } + none => do s.emit_enum_variant(~"none", 0u, 0u) { } - some(v) { - do s.emit_enum_variant(~"some", 1u, 1u) { - do s.emit_enum_variant_arg(0u) { - st(v) - } + some(v) => do s.emit_enum_variant(~"some", 1u, 1u) { + do s.emit_enum_variant_arg(0u) { + st(v) } } } @@ -265,14 +261,8 @@ fn deserialize_option<D: deserializer,T: copy>(d: D, st: fn() -> T) do d.read_enum(~"option") { do d.read_enum_variant |i| { alt check i { - 0u { // none - none - } - 1u { // some(v) - some(d.read_enum_variant_arg(0u, || { - st() - })) - } + 0u => none, + 1u => some(d.read_enum_variant_arg(0u, || st() )) } } } diff --git a/src/libstd/smallintmap.rs b/src/libstd/smallintmap.rs index b8bdf581218..2fe09f75d56 100644 --- a/src/libstd/smallintmap.rs +++ b/src/libstd/smallintmap.rs @@ -49,8 +49,11 @@ pure fn find<T: copy>(self: smallintmap<T>, key: uint) -> option<T> { */ pure fn get<T: copy>(self: smallintmap<T>, key: uint) -> T { alt find(self, key) { - none { error!{"smallintmap::get(): key not present"}; fail; } - some(v) { return v; } + none => { + error!{"smallintmap::get(): key not present"}; + fail; + } + some(v) => return v } } @@ -64,7 +67,10 @@ impl <V: copy> of map::map<uint, V> for smallintmap<V> { fn size() -> uint { let mut sz = 0u; for self.v.each |item| { - alt item { some(_) { sz += 1u; } _ {} } + alt item { + some(_) => sz += 1u, + _ => () + } } sz } @@ -98,10 +104,8 @@ impl <V: copy> of map::map<uint, V> for smallintmap<V> { let mut idx = 0u, l = self.v.len(); while idx < l { alt self.v.get_elt(idx) { - some(elt) { - if !it(idx, elt) { break; } - } - none { } + some(elt) => if !it(idx, elt) { break } + none => () } idx += 1u; } @@ -116,10 +120,8 @@ impl <V: copy> of map::map<uint, V> for smallintmap<V> { let mut idx = 0u, l = self.v.len(); while idx < l { alt self.v.get_elt(idx) { - some(elt) { - if !it(&idx, &elt) { break; } - } - none { } + some(elt) => if !it(&idx, &elt) { break } + none => () } idx += 1u; } diff --git a/src/libstd/tempfile.rs b/src/libstd/tempfile.rs index 80a075dbe53..a67164ee107 100644 --- a/src/libstd/tempfile.rs +++ b/src/libstd/tempfile.rs @@ -22,10 +22,10 @@ fn mkdtemp(prefix: ~str, suffix: ~str) -> option<~str> { fn test_mkdtemp() { let r = mkdtemp(~"./", ~"foobar"); alt r { - some(p) { + some(p) => { os::remove_dir(p); assert(str::ends_with(p, ~"foobar")); } - _ { assert(false); } + _ => assert(false) } } diff --git a/src/libstd/term.rs b/src/libstd/term.rs index 20fb9622e3d..1d2ae7bca5d 100644 --- a/src/libstd/term.rs +++ b/src/libstd/term.rs @@ -36,13 +36,13 @@ fn color_supported() -> bool { let supported_terms = ~[~"xterm-color", ~"xterm", ~"screen-bce", ~"xterm-256color"]; return alt os::getenv(~"TERM") { - option::some(env) { + option::some(env) => { for vec::each(supported_terms) |term| { if term == env { return true; } } false } - option::none { false } + option::none => false }; } diff --git a/src/libstd/test.rs b/src/libstd/test.rs index 8d2673df5c6..890bddb3519 100644 --- a/src/libstd/test.rs +++ b/src/libstd/test.rs @@ -53,8 +53,8 @@ type test_desc = { fn test_main(args: ~[~str], tests: ~[test_desc]) { let opts = alt parse_opts(args) { - either::left(o) { o } - either::right(m) { fail m } + either::left(o) => o, + either::right(m) => fail m }; if !run_tests_console(opts, tests) { fail ~"Some tests failed"; } } @@ -70,8 +70,8 @@ fn parse_opts(args: ~[~str]) -> opt_res { let opts = ~[getopts::optflag(~"ignored"), getopts::optopt(~"logfile")]; let matches = alt getopts::getopts(args_, opts) { - ok(m) { m } - err(f) { return either::right(getopts::fail_str(f)) } + ok(m) => m, + err(f) => return either::right(getopts::fail_str(f)) }; let filter = @@ -106,32 +106,30 @@ fn run_tests_console(opts: test_opts, fn callback(event: testevent, st: console_test_state) { alt event { - te_filtered(filtered_tests) { + te_filtered(filtered_tests) => { st.total = vec::len(filtered_tests); let noun = if st.total != 1u { ~"tests" } else { ~"test" }; st.out.write_line(fmt!{"\nrunning %u %s", st.total, noun}); } - te_wait(test) { st.out.write_str(fmt!{"test %s ... ", test.name}); } - te_result(test, result) { + te_wait(test) => st.out.write_str(fmt!{"test %s ... ", test.name}), + te_result(test, result) => { alt st.log_out { - some(f) { - write_log(f, result, test); - } - none {} + some(f) => write_log(f, result, test), + none => () } alt result { - tr_ok { + tr_ok => { st.passed += 1u; write_ok(st.out, st.use_color); st.out.write_line(~""); } - tr_failed { + tr_failed => { st.failed += 1u; write_failed(st.out, st.use_color); st.out.write_line(~""); vec::push(st.failures, copy test); } - tr_ignored { + tr_ignored => { st.ignored += 1u; write_ignored(st.out, st.use_color); st.out.write_line(~""); @@ -142,15 +140,13 @@ fn run_tests_console(opts: test_opts, } let log_out = alt opts.logfile { - some(path) { - alt io::file_writer(path, ~[io::create, io::truncate]) { - result::ok(w) { some(w) } - result::err(s) { - fail(fmt!{"can't open output file: %s", s}) - } - } + some(path) => alt io::file_writer(path, ~[io::create, io::truncate]) { + result::ok(w) => some(w), + result::err(s) => { + fail(fmt!{"can't open output file: %s", s}) + } } - none { none } + none => none }; let st = @@ -185,9 +181,9 @@ fn run_tests_console(opts: test_opts, fn write_log(out: io::writer, result: test_result, test: test_desc) { out.write_line(fmt!{"%s %s", alt result { - tr_ok { ~"ok" } - tr_failed { ~"failed" } - tr_ignored { ~"ignored" } + tr_ok => ~"ok", + tr_failed => ~"failed", + tr_ignored => ~"ignored" }, test.name}); } @@ -339,8 +335,8 @@ fn filter_tests(opts: test_opts, } else { let filter_str = alt opts.filter { - option::some(f) { f } - option::none { ~"" } + option::some(f) => f, + option::none => ~"" }; fn filter_fn(test: test_desc, filter_str: ~str) -> @@ -483,16 +479,20 @@ mod tests { #[test] fn first_free_arg_should_be_a_filter() { let args = ~[~"progname", ~"filter"]; - let opts = alt parse_opts(args) { either::left(o) { o } - _ { fail ~"Malformed arg in first_free_arg_should_be_a_filter"; } }; + let opts = alt parse_opts(args) { + either::left(o) => o, + _ => fail ~"Malformed arg in first_free_arg_should_be_a_filter" + }; assert ~"filter" == option::get(opts.filter); } #[test] fn parse_ignored_flag() { let args = ~[~"progname", ~"filter", ~"--ignored"]; - let opts = alt parse_opts(args) { either::left(o) { o } - _ { fail ~"Malformed arg in parse_ignored_flag"; } }; + let opts = alt parse_opts(args) { + either::left(o) => o, + _ => fail ~"Malformed arg in parse_ignored_flag" + }; assert (opts.run_ignored); } diff --git a/src/libstd/time.rs b/src/libstd/time.rs index 3ec2975db18..23b6bf22276 100644 --- a/src/libstd/time.rs +++ b/src/libstd/time.rs @@ -182,11 +182,11 @@ fn strptime(s: ~str, format: ~str) -> result<tm, ~str> { pos = next; alt ch { - '0' to '9' { + '0' to '9' => { value = value * 10_i32 + (ch as i32 - '0' as i32); } - ' ' if ws { } - _ { return none; } + ' ' if ws => (), + _ => return none } i += 1u; } @@ -209,83 +209,73 @@ fn strptime(s: ~str, format: ~str) -> result<tm, ~str> { fn parse_type(s: ~str, pos: uint, ch: char, tm: tm_mut) -> result<uint, ~str> { alt ch { - 'A' { - alt match_strs(s, pos, ~[ - (~"Sunday", 0_i32), - (~"Monday", 1_i32), - (~"Tuesday", 2_i32), - (~"Wednesday", 3_i32), - (~"Thursday", 4_i32), - (~"Friday", 5_i32), - (~"Saturday", 6_i32) - ]) { - some(item) { let (v, pos) = item; tm.tm_wday = v; ok(pos) } - none { err(~"Invalid day") } - } + 'A' => alt match_strs(s, pos, ~[ + (~"Sunday", 0_i32), + (~"Monday", 1_i32), + (~"Tuesday", 2_i32), + (~"Wednesday", 3_i32), + (~"Thursday", 4_i32), + (~"Friday", 5_i32), + (~"Saturday", 6_i32) + ]) { + some(item) => { let (v, pos) = item; tm.tm_wday = v; ok(pos) } + none => err(~"Invalid day") } - 'a' { - alt match_strs(s, pos, ~[ - (~"Sun", 0_i32), - (~"Mon", 1_i32), - (~"Tue", 2_i32), - (~"Wed", 3_i32), - (~"Thu", 4_i32), - (~"Fri", 5_i32), - (~"Sat", 6_i32) - ]) { - some(item) { let (v, pos) = item; tm.tm_wday = v; ok(pos) } - none { err(~"Invalid day") } - } + 'a' => alt match_strs(s, pos, ~[ + (~"Sun", 0_i32), + (~"Mon", 1_i32), + (~"Tue", 2_i32), + (~"Wed", 3_i32), + (~"Thu", 4_i32), + (~"Fri", 5_i32), + (~"Sat", 6_i32) + ]) { + some(item) => { let (v, pos) = item; tm.tm_wday = v; ok(pos) } + none => err(~"Invalid day") } - 'B' { - alt match_strs(s, pos, ~[ - (~"January", 0_i32), - (~"February", 1_i32), - (~"March", 2_i32), - (~"April", 3_i32), - (~"May", 4_i32), - (~"June", 5_i32), - (~"July", 6_i32), - (~"August", 7_i32), - (~"September", 8_i32), - (~"October", 9_i32), - (~"November", 10_i32), - (~"December", 11_i32) - ]) { - some(item) { let (v, pos) = item; tm.tm_mon = v; ok(pos) } - none { err(~"Invalid month") } - } + 'B' => alt match_strs(s, pos, ~[ + (~"January", 0_i32), + (~"February", 1_i32), + (~"March", 2_i32), + (~"April", 3_i32), + (~"May", 4_i32), + (~"June", 5_i32), + (~"July", 6_i32), + (~"August", 7_i32), + (~"September", 8_i32), + (~"October", 9_i32), + (~"November", 10_i32), + (~"December", 11_i32) + ]) { + some(item) => { let (v, pos) = item; tm.tm_mon = v; ok(pos) } + none => err(~"Invalid month") } - 'b' | 'h' { - alt match_strs(s, pos, ~[ - (~"Jan", 0_i32), - (~"Feb", 1_i32), - (~"Mar", 2_i32), - (~"Apr", 3_i32), - (~"May", 4_i32), - (~"Jun", 5_i32), - (~"Jul", 6_i32), - (~"Aug", 7_i32), - (~"Sep", 8_i32), - (~"Oct", 9_i32), - (~"Nov", 10_i32), - (~"Dec", 11_i32) - ]) { - some(item) { let (v, pos) = item; tm.tm_mon = v; ok(pos) } - none { err(~"Invalid month") } - } + 'b' | 'h' => alt match_strs(s, pos, ~[ + (~"Jan", 0_i32), + (~"Feb", 1_i32), + (~"Mar", 2_i32), + (~"Apr", 3_i32), + (~"May", 4_i32), + (~"Jun", 5_i32), + (~"Jul", 6_i32), + (~"Aug", 7_i32), + (~"Sep", 8_i32), + (~"Oct", 9_i32), + (~"Nov", 10_i32), + (~"Dec", 11_i32) + ]) { + some(item) => { let (v, pos) = item; tm.tm_mon = v; ok(pos) } + none => err(~"Invalid month") } - 'C' { - alt match_digits(s, pos, 2u, false) { - some(item) { + 'C' => alt match_digits(s, pos, 2u, false) { + some(item) => { let (v, pos) = item; - tm.tm_year += (v * 100_i32) - 1900_i32; - ok(pos) + tm.tm_year += (v * 100_i32) - 1900_i32; + ok(pos) } - none { err(~"Invalid year") } - } + none => err(~"Invalid year") } - 'c' { + 'c' => { parse_type(s, pos, 'a', tm) .chain(|pos| parse_char(s, pos, ' ')) .chain(|pos| parse_type(s, pos, 'b', tm)) @@ -296,116 +286,108 @@ fn strptime(s: ~str, format: ~str) -> result<tm, ~str> { .chain(|pos| parse_char(s, pos, ' ')) .chain(|pos| parse_type(s, pos, 'Y', tm)) } - 'D' | 'x' { + 'D' | 'x' => { parse_type(s, pos, 'm', tm) .chain(|pos| parse_char(s, pos, '/')) .chain(|pos| parse_type(s, pos, 'd', tm)) .chain(|pos| parse_char(s, pos, '/')) .chain(|pos| parse_type(s, pos, 'y', tm)) } - 'd' { - alt match_digits(s, pos, 2u, false) { - some(item) { let (v, pos) = item; tm.tm_mday = v; ok(pos) } - none { err(~"Invalid day of the month") } - } + 'd' => alt match_digits(s, pos, 2u, false) { + some(item) => { let (v, pos) = item; tm.tm_mday = v; ok(pos) } + none => err(~"Invalid day of the month") } - 'e' { - alt match_digits(s, pos, 2u, true) { - some(item) { let (v, pos) = item; tm.tm_mday = v; ok(pos) } - none { err(~"Invalid day of the month") } - } + 'e' => alt match_digits(s, pos, 2u, true) { + some(item) => { let (v, pos) = item; tm.tm_mday = v; ok(pos) } + none => err(~"Invalid day of the month") } - 'F' { + 'F' => { parse_type(s, pos, 'Y', tm) .chain(|pos| parse_char(s, pos, '-')) .chain(|pos| parse_type(s, pos, 'm', tm)) .chain(|pos| parse_char(s, pos, '-')) .chain(|pos| parse_type(s, pos, 'd', tm)) } - 'H' { + 'H' => { // FIXME (#2350): range check. alt match_digits(s, pos, 2u, false) { - some(item) { let (v, pos) = item; tm.tm_hour = v; ok(pos) } - none { err(~"Invalid hour") } + some(item) => { let (v, pos) = item; tm.tm_hour = v; ok(pos) } + none => err(~"Invalid hour") } } - 'I' { + 'I' => { // FIXME (#2350): range check. alt match_digits(s, pos, 2u, false) { - some(item) { + some(item) => { let (v, pos) = item; tm.tm_hour = if v == 12_i32 { 0_i32 } else { v }; ok(pos) } - none { err(~"Invalid hour") } + none => err(~"Invalid hour") } } - 'j' { + 'j' => { // FIXME (#2350): range check. alt match_digits(s, pos, 3u, false) { - some(item) { + some(item) => { let (v, pos) = item; tm.tm_yday = v - 1_i32; ok(pos) } - none { err(~"Invalid year") } + none => err(~"Invalid year") } } - 'k' { + 'k' => { // FIXME (#2350): range check. alt match_digits(s, pos, 2u, true) { - some(item) { let (v, pos) = item; tm.tm_hour = v; ok(pos) } - none { err(~"Invalid hour") } + some(item) => { let (v, pos) = item; tm.tm_hour = v; ok(pos) } + none => err(~"Invalid hour") } } - 'l' { + 'l' => { // FIXME (#2350): range check. alt match_digits(s, pos, 2u, true) { - some(item) { + some(item) => { let (v, pos) = item; tm.tm_hour = if v == 12_i32 { 0_i32 } else { v }; ok(pos) } - none { err(~"Invalid hour") } + none => err(~"Invalid hour") } } - 'M' { + 'M' => { // FIXME (#2350): range check. alt match_digits(s, pos, 2u, false) { - some(item) { let (v, pos) = item; tm.tm_min = v; ok(pos) } - none { err(~"Invalid minute") } + some(item) => { let (v, pos) = item; tm.tm_min = v; ok(pos) } + none => err(~"Invalid minute") } } - 'm' { + 'm' => { // FIXME (#2350): range check. alt match_digits(s, pos, 2u, false) { - some(item) { + some(item) => { let (v, pos) = item; tm.tm_mon = v - 1_i32; ok(pos) } - none { err(~"Invalid month") } + none => err(~"Invalid month") } } - 'n' { parse_char(s, pos, '\n') } - 'P' { - alt match_strs(s, pos, ~[(~"am", 0_i32), (~"pm", 12_i32)]) { - some(item) { let (v, pos) = item; tm.tm_hour += v; ok(pos) } - none { err(~"Invalid hour") } - } + 'n' => parse_char(s, pos, '\n'), + 'P' => alt match_strs(s, pos, ~[(~"am", 0_i32), (~"pm", 12_i32)]) { + some(item) => { let (v, pos) = item; tm.tm_hour += v; ok(pos) } + none => err(~"Invalid hour") } - 'p' { - alt match_strs(s, pos, ~[(~"AM", 0_i32), (~"PM", 12_i32)]) { - some(item) { let (v, pos) = item; tm.tm_hour += v; ok(pos) } - none { err(~"Invalid hour") } - } + 'p' => alt match_strs(s, pos, ~[(~"AM", 0_i32), (~"PM", 12_i32)]) { + some(item) => { let (v, pos) = item; tm.tm_hour += v; ok(pos) } + none => err(~"Invalid hour") } - 'R' { + 'R' => { parse_type(s, pos, 'H', tm) .chain(|pos| parse_char(s, pos, ':')) .chain(|pos| parse_type(s, pos, 'M', tm)) } - 'r' { + 'r' => { parse_type(s, pos, 'I', tm) .chain(|pos| parse_char(s, pos, ':')) .chain(|pos| parse_type(s, pos, 'M', tm)) @@ -414,38 +396,38 @@ fn strptime(s: ~str, format: ~str) -> result<tm, ~str> { .chain(|pos| parse_char(s, pos, ' ')) .chain(|pos| parse_type(s, pos, 'p', tm)) } - 'S' { + 'S' => { // FIXME (#2350): range check. alt match_digits(s, pos, 2u, false) { - some(item) { + some(item) => { let (v, pos) = item; tm.tm_sec = v; ok(pos) } - none { err(~"Invalid second") } + none => err(~"Invalid second") } } //'s' {} - 'T' | 'X' { + 'T' | 'X' => { parse_type(s, pos, 'H', tm) .chain(|pos| parse_char(s, pos, ':')) .chain(|pos| parse_type(s, pos, 'M', tm)) .chain(|pos| parse_char(s, pos, ':')) .chain(|pos| parse_type(s, pos, 'S', tm)) } - 't' { parse_char(s, pos, '\t') } - 'u' { + 't' => parse_char(s, pos, '\t'), + 'u' => { // FIXME (#2350): range check. alt match_digits(s, pos, 1u, false) { - some(item) { + some(item) => { let (v, pos) = item; tm.tm_wday = v; ok(pos) } - none { err(~"Invalid weekday") } + none => err(~"Invalid weekday") } } - 'v' { + 'v' => { parse_type(s, pos, 'e', tm) .chain(|pos| parse_char(s, pos, '-')) .chain(|pos| parse_type(s, pos, 'b', tm)) @@ -453,38 +435,38 @@ fn strptime(s: ~str, format: ~str) -> result<tm, ~str> { .chain(|pos| parse_type(s, pos, 'Y', tm)) } //'W' {} - 'w' { + 'w' => { // FIXME (#2350): range check. alt match_digits(s, pos, 1u, false) { - some(item) { let (v, pos) = item; tm.tm_wday = v; ok(pos) } - none { err(~"Invalid weekday") } + some(item) => { let (v, pos) = item; tm.tm_wday = v; ok(pos) } + none => err(~"Invalid weekday") } } //'X' {} //'x' {} - 'Y' { + 'Y' => { // FIXME (#2350): range check. alt match_digits(s, pos, 4u, false) { - some(item) { + some(item) => { let (v, pos) = item; tm.tm_year = v - 1900_i32; ok(pos) } - none { err(~"Invalid weekday") } + none => err(~"Invalid weekday") } } - 'y' { + 'y' => { // FIXME (#2350): range check. alt match_digits(s, pos, 2u, false) { - some(item) { + some(item) => { let (v, pos) = item; tm.tm_year = v - 1900_i32; ok(pos) } - none { err(~"Invalid weekday") } + none => err(~"Invalid weekday") } } - 'Z' { + 'Z' => { if match_str(s, pos, ~"UTC") || match_str(s, pos, ~"GMT") { tm.tm_gmtoff = 0_i32; tm.tm_zone = ~"UTC"; @@ -503,12 +485,12 @@ fn strptime(s: ~str, format: ~str) -> result<tm, ~str> { ok(pos) } } - 'z' { + 'z' => { let {ch, next} = str::char_range_at(s, pos); if ch == '+' || ch == '-' { alt match_digits(s, next, 4u, false) { - some(item) { + some(item) => { let (v, pos) = item; if v == 0_i32 { tm.tm_gmtoff = 0_i32; @@ -517,14 +499,14 @@ fn strptime(s: ~str, format: ~str) -> result<tm, ~str> { ok(pos) } - none { err(~"Invalid zone offset") } + none => err(~"Invalid zone offset") } } else { err(~"Invalid zone offset") } } - '%' { parse_char(s, pos, '%') } - ch { + '%' => parse_char(s, pos, '%'), + ch => { err(fmt!{"unknown formatting type: %?", str::from_char(ch)}) } } @@ -553,13 +535,11 @@ fn strptime(s: ~str, format: ~str) -> result<tm, ~str> { let {ch, next} = str::char_range_at(s, pos); alt rdr.read_char() { - '%' { - alt parse_type(s, pos, rdr.read_char(), tm) { - ok(next) { pos = next; } - err(e) { result = err(e); break; } - } + '%' => alt parse_type(s, pos, rdr.read_char(), tm) { + ok(next) => pos = next, + err(e) => { result = err(e); break; } } - c { + c => { if c != ch { break } pos = next; } @@ -589,62 +569,54 @@ fn strftime(format: ~str, tm: tm) -> ~str { fn parse_type(ch: char, tm: tm) -> ~str { //FIXME (#2350): Implement missing types. alt check ch { - 'A' { - alt check tm.tm_wday as int { - 0 { ~"Sunday" } - 1 { ~"Monday" } - 2 { ~"Tuesday" } - 3 { ~"Wednesday" } - 4 { ~"Thursday" } - 5 { ~"Friday" } - 6 { ~"Saturday" } - } + 'A' => alt check tm.tm_wday as int { + 0 => ~"Sunday", + 1 => ~"Monday", + 2 => ~"Tuesday", + 3 => ~"Wednesday", + 4 => ~"Thursday", + 5 => ~"Friday", + 6 => ~"Saturday" } - 'a' { - alt check tm.tm_wday as int { - 0 { ~"Sun" } - 1 { ~"Mon" } - 2 { ~"Tue" } - 3 { ~"Wed" } - 4 { ~"Thu" } - 5 { ~"Fri" } - 6 { ~"Sat" } - } + 'a' => alt check tm.tm_wday as int { + 0 => ~"Sun", + 1 => ~"Mon", + 2 => ~"Tue", + 3 => ~"Wed", + 4 => ~"Thu", + 5 => ~"Fri", + 6 => ~"Sat" } - 'B' { - alt check tm.tm_mon as int { - 0 { ~"January" } - 1 { ~"February" } - 2 { ~"March" } - 3 { ~"April" } - 4 { ~"May" } - 5 { ~"June" } - 6 { ~"July" } - 7 { ~"August" } - 8 { ~"September" } - 9 { ~"October" } - 10 { ~"November" } - 11 { ~"December" } - } + 'B' => alt check tm.tm_mon as int { + 0 => ~"January", + 1 => ~"February", + 2 => ~"March", + 3 => ~"April", + 4 => ~"May", + 5 => ~"June", + 6 => ~"July", + 7 => ~"August", + 8 => ~"September", + 9 => ~"October", + 10 => ~"November", + 11 => ~"December" } - 'b' | 'h' { - alt check tm.tm_mon as int { - 0 { ~"Jan" } - 1 { ~"Feb" } - 2 { ~"Mar" } - 3 { ~"Apr" } - 4 { ~"May" } - 5 { ~"Jun" } - 6 { ~"Jul" } - 7 { ~"Aug" } - 8 { ~"Sep" } - 9 { ~"Oct" } - 10 { ~"Nov" } - 11 { ~"Dec" } - } + 'b' | 'h' => alt check tm.tm_mon as int { + 0 => ~"Jan", + 1 => ~"Feb", + 2 => ~"Mar", + 3 => ~"Apr", + 4 => ~"May", + 5 => ~"Jun", + 6 => ~"Jul", + 7 => ~"Aug", + 8 => ~"Sep", + 9 => ~"Oct", + 10 => ~"Nov", + 11 => ~"Dec", } - 'C' { fmt!{"%02d", (tm.tm_year as int + 1900) / 100} } - 'c' { + 'C' => fmt!{"%02d", (tm.tm_year as int + 1900) / 100}, + 'c' => { fmt!{"%s %s %s %s %s", parse_type('a', tm), parse_type('b', tm), @@ -652,15 +624,15 @@ fn strftime(format: ~str, tm: tm) -> ~str { parse_type('T', tm), parse_type('Y', tm)} } - 'D' | 'x' { + 'D' | 'x' => { fmt!{"%s/%s/%s", parse_type('m', tm), parse_type('d', tm), parse_type('y', tm)} } - 'd' { fmt!{"%02d", tm.tm_mday as int} } - 'e' { fmt!{"%2d", tm.tm_mday as int} } - 'F' { + 'd' => fmt!{"%02d", tm.tm_mday as int}, + 'e' => fmt!{"%2d", tm.tm_mday as int}, + 'F' => { fmt!{"%s-%s-%s", parse_type('Y', tm), parse_type('m', tm), @@ -668,67 +640,67 @@ fn strftime(format: ~str, tm: tm) -> ~str { } //'G' {} //'g' {} - 'H' { fmt!{"%02d", tm.tm_hour as int} } - 'I' { + 'H' => fmt!{"%02d", tm.tm_hour as int}, + 'I' => { let mut h = tm.tm_hour as int; if h == 0 { h = 12 } if h > 12 { h -= 12 } fmt!{"%02d", h} } - 'j' { fmt!{"%03d", tm.tm_yday as int + 1} } - 'k' { fmt!{"%2d", tm.tm_hour as int} } - 'l' { + 'j' => fmt!{"%03d", tm.tm_yday as int + 1}, + 'k' => fmt!{"%2d", tm.tm_hour as int}, + 'l' => { let mut h = tm.tm_hour as int; if h == 0 { h = 12 } if h > 12 { h -= 12 } fmt!{"%2d", h} } - 'M' { fmt!{"%02d", tm.tm_min as int} } - 'm' { fmt!{"%02d", tm.tm_mon as int + 1} } - 'n' { ~"\n" } - 'P' { if tm.tm_hour as int < 12 { ~"am" } else { ~"pm" } } - 'p' { if tm.tm_hour as int < 12 { ~"AM" } else { ~"PM" } } - 'R' { + 'M' => fmt!{"%02d", tm.tm_min as int}, + 'm' => fmt!{"%02d", tm.tm_mon as int + 1}, + 'n' => ~"\n", + 'P' => if tm.tm_hour as int < 12 { ~"am" } else { ~"pm" } + 'p' => if tm.tm_hour as int < 12 { ~"AM" } else { ~"PM" } + 'R' => { fmt!{"%s:%s", parse_type('H', tm), parse_type('M', tm)} } - 'r' { + 'r' => { fmt!{"%s:%s:%s %s", parse_type('I', tm), parse_type('M', tm), parse_type('S', tm), parse_type('p', tm)} } - 'S' { fmt!{"%02d", tm.tm_sec as int} } - 's' { fmt!{"%d", tm.to_timespec().sec as int} } - 'T' | 'X' { + 'S' => fmt!{"%02d", tm.tm_sec as int}, + 's' => fmt!{"%d", tm.to_timespec().sec as int}, + 'T' | 'X' => { fmt!{"%s:%s:%s", parse_type('H', tm), parse_type('M', tm), parse_type('S', tm)} } - 't' { ~"\t" } + 't' => ~"\t", //'U' {} - 'u' { + 'u' => { let i = tm.tm_wday as int; int::str(if i == 0 { 7 } else { i }) } //'V' {} - 'v' { + 'v' => { fmt!{"%s-%s-%s", parse_type('e', tm), parse_type('b', tm), parse_type('Y', tm)} } //'W' {} - 'w' { int::str(tm.tm_wday as int) } + 'w' => int::str(tm.tm_wday as int), //'X' {} //'x' {} - 'Y' { int::str(tm.tm_year as int + 1900) } - 'y' { fmt!{"%02d", (tm.tm_year as int + 1900) % 100} } - 'Z' { tm.tm_zone } - 'z' { + 'Y' => int::str(tm.tm_year as int + 1900), + 'y' => fmt!{"%02d", (tm.tm_year as int + 1900) % 100}, + 'Z' => tm.tm_zone, + 'z' => { let sign = if tm.tm_gmtoff > 0_i32 { '+' } else { '-' }; let mut m = i32::abs(tm.tm_gmtoff) / 60_i32; let h = m / 60_i32; @@ -736,7 +708,7 @@ fn strftime(format: ~str, tm: tm) -> ~str { fmt!{"%c%02d%02d", sign, h as int, m as int} } //'+' {} - '%' { ~"%" } + '%' => ~"%" } } @@ -745,8 +717,8 @@ fn strftime(format: ~str, tm: tm) -> ~str { do io::with_str_reader(format) |rdr| { while !rdr.eof() { alt rdr.read_char() { - '%' { buf += parse_type(rdr.read_char(), tm); } - ch { str::push_char(buf, ch); } + '%' => buf += parse_type(rdr.read_char(), tm), + ch => str::push_char(buf, ch) } } } @@ -961,7 +933,7 @@ mod tests { tzset(); alt strptime(~"", ~"") { - ok(tm) { + ok(tm) => { assert tm.tm_sec == 0_i32; assert tm.tm_min == 0_i32; assert tm.tm_hour == 0_i32; @@ -974,7 +946,7 @@ mod tests { assert tm.tm_zone == ~""; assert tm.tm_nsec == 0_i32; } - err(_) {} + err(_) => () } let format = ~"%a %b %e %T %Y"; @@ -983,8 +955,8 @@ mod tests { == err(~"Invalid time"); alt strptime(~"Fri Feb 13 15:31:30 2009", format) { - err(e) { fail e } - ok(tm) { + err(e) => fail e, + ok(tm) => { assert tm.tm_sec == 30_i32; assert tm.tm_min == 31_i32; assert tm.tm_hour == 15_i32; @@ -1002,8 +974,8 @@ mod tests { fn test(s: ~str, format: ~str) -> bool { alt strptime(s, format) { - ok(tm) { tm.strftime(format) == s } - err(e) { fail e } + ok(tm) => tm.strftime(format) == s, + err(e) => fail e } } diff --git a/src/libstd/timer.rs b/src/libstd/timer.rs index 6b0b4eb2f17..de629d98d63 100644 --- a/src/libstd/timer.rs +++ b/src/libstd/timer.rs @@ -216,8 +216,11 @@ mod test { }; alt recv_timeout(hl_loop, 10u, test_po) { - some(val) { assert val == expected; successes += 1; } - _ { failures += 1; } + some(val) => { + assert val == expected; + successes += 1; + } + _ => failures += 1 }; } @@ -241,8 +244,8 @@ mod test { }; alt recv_timeout(hl_loop, 1u, test_po) { - none { successes += 1; } - _ { failures += 1; } + none => successes += 1, + _ => failures += 1 }; } diff --git a/src/libstd/treemap.rs b/src/libstd/treemap.rs index b6dc2bfa579..ab7330fb1ee 100644 --- a/src/libstd/treemap.rs +++ b/src/libstd/treemap.rs @@ -31,14 +31,14 @@ fn treemap<K, V>() -> treemap<K, V> { @mut none } /// Insert a value into the map fn insert<K: copy, V: copy>(m: &mut tree_edge<K, V>, k: K, v: V) { alt copy *m { - none { + none => { *m = some(@tree_node({key: k, mut value: v, mut left: none, mut right: none})); return; } - some(node) { + some(node) => { if k == node.key { node.value = v; } else if k < node.key { @@ -53,10 +53,10 @@ fn insert<K: copy, V: copy>(m: &mut tree_edge<K, V>, k: K, v: V) { /// Find a value based on the key fn find<K: copy, V: copy>(m: &const tree_edge<K, V>, k: K) -> option<V> { alt copy *m { - none { none } + none => none, // FIXME (#2808): was that an optimization? - some(node) { + some(node) => { if k == node.key { some(node.value) } else if k < node.key { @@ -71,8 +71,8 @@ fn find<K: copy, V: copy>(m: &const tree_edge<K, V>, k: K) -> option<V> { /// Visit all pairs in the map in order. fn traverse<K, V: copy>(m: &const tree_edge<K, V>, f: fn(K, V)) { alt copy *m { - none { } - some(node) { + none => (), + some(node) => { traverse(&const node.left, f); // copy of value is req'd as f() requires an immutable ptr f(node.key, copy node.value); diff --git a/src/libstd/uv_global_loop.rs b/src/libstd/uv_global_loop.rs index 2b5beda2e37..52e4879c0b2 100644 --- a/src/libstd/uv_global_loop.rs +++ b/src/libstd/uv_global_loop.rs @@ -57,14 +57,14 @@ fn get_monitor_task_gl() -> iotask unsafe { loop { debug!{"in outer_loop..."}; alt select2(weak_exit_po, msg_po) { - left(weak_exit) { + left(weak_exit) => { // all normal tasks have ended, tell the // libuv loop to tear_down, then exit debug!{"weak_exit_po recv'd msg: %?", weak_exit}; iotask::exit(hl_loop); break; } - right(fetch_ch) { + right(fetch_ch) => { debug!{"hl_loop req recv'd: %?", fetch_ch}; fetch_ch.send(hl_loop); } diff --git a/src/libstd/uv_iotask.rs b/src/libstd/uv_iotask.rs index d7de26228ca..5b9d3b1f2f2 100644 --- a/src/libstd/uv_iotask.rs +++ b/src/libstd/uv_iotask.rs @@ -145,12 +145,8 @@ extern fn wake_up_cb(async_handle: *ll::uv_async_t, while msg_po.peek() { alt msg_po.recv() { - interaction(cb) { - cb(loop_ptr); - } - teardown_loop { - begin_teardown(data); - } + interaction(cb) => cb(loop_ptr), + teardown_loop => begin_teardown(data) } } } diff --git a/src/libstd/uv_ll.rs b/src/libstd/uv_ll.rs index 108abace1c9..9d120cce742 100644 --- a/src/libstd/uv_ll.rs +++ b/src/libstd/uv_ll.rs @@ -849,12 +849,8 @@ unsafe fn ip6_name(src: &sockaddr_in6) -> ~str { let result = rustrt::rust_uv_ip6_name(src_unsafe_ptr, dst_buf, size as libc::size_t); alt result { - 0i32 { - str::unsafe::from_buf(dst_buf) - } - _ { - ~"" - } + 0i32 => str::unsafe::from_buf(dst_buf), + _ => ~"" } } } diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index 27cd21d1d9f..1e43ae219ba 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -194,8 +194,8 @@ enum vstore { pure fn is_blockish(p: ast::proto) -> bool { alt p { - proto_block { true } - proto_bare | proto_uniq | proto_box { false } + proto_block => true, + proto_bare | proto_uniq | proto_box => false } } diff --git a/src/libsyntax/ast_map.rs b/src/libsyntax/ast_map.rs index c8daae0982d..f23385f2e17 100644 --- a/src/libsyntax/ast_map.rs +++ b/src/libsyntax/ast_map.rs @@ -13,8 +13,8 @@ type path = ~[path_elt]; fn path_to_str_with_sep(p: path, sep: ~str) -> ~str { let strs = do vec::map(p) |e| { alt e { - path_mod(s) { /* FIXME (#2543) */ copy *s } - path_name(s) { /* FIXME (#2543) */ copy *s } + path_mod(s) => /* FIXME (#2543) */ copy *s, + path_name(s) => /* FIXME (#2543) */ copy *s } }; str::connect(strs, sep) @@ -105,12 +105,12 @@ fn map_decoded_item(diag: span_handler, // don't decode and instantiate the impl, but just the method, we have to // add it to the table now: alt ii { - ii_item(*) | ii_ctor(*) | ii_dtor(*) { /* fallthrough */ } - ii_foreign(i) { + ii_item(*) | ii_ctor(*) | ii_dtor(*) => { /* fallthrough */ } + ii_foreign(i) => { cx.map.insert(i.id, node_foreign_item(i, foreign_abi_rust_intrinsic, @path)); } - ii_method(impl_did, m) { + ii_method(impl_did, m) => { map_method(impl_did, @path, m, cx); } } @@ -128,7 +128,7 @@ fn map_fn(fk: visit::fn_kind, decl: fn_decl, body: blk, cx.local_id += 1u; } alt fk { - visit::fk_ctor(nm, attrs, tps, self_id, parent_id) { + visit::fk_ctor(nm, attrs, tps, self_id, parent_id) => { let ct = @{node: {id: id, attrs: attrs, self_id: self_id, @@ -140,14 +140,14 @@ fn map_fn(fk: visit::fn_kind, decl: fn_decl, body: blk, ct, parent_id, @/* FIXME (#2543) */ copy cx.path)); } - visit::fk_dtor(tps, attrs, self_id, parent_id) { + visit::fk_dtor(tps, attrs, self_id, parent_id) => { let dt = @{node: {id: id, attrs: attrs, self_id: self_id, body: /* FIXME (#2543) */ copy body}, span: sp}; cx.map.insert(id, node_dtor(/* FIXME (#2543) */ copy tps, dt, parent_id, @/* FIXME (#2543) */ copy cx.path)); } - _ {} + _ => () } visit::visit_fn(fk, decl, body, sp, id, cx, v); } @@ -160,11 +160,11 @@ fn map_block(b: blk, cx: ctx, v: vt) { fn number_pat(cx: ctx, pat: @pat) { do ast_util::walk_pat(pat) |p| { alt p.node { - pat_ident(*) { + pat_ident(*) => { cx.map.insert(p.id, node_local(cx.local_id)); cx.local_id += 1u; } - _ {} + _ => () } }; } @@ -190,24 +190,24 @@ fn map_item(i: @item, cx: ctx, v: vt) { let item_path = @/* FIXME (#2543) */ copy cx.path; cx.map.insert(i.id, node_item(i, item_path)); alt i.node { - item_impl(_, opt_ir, _, ms) { + item_impl(_, opt_ir, _, ms) => { let impl_did = ast_util::local_def(i.id); for ms.each |m| { map_method(impl_did, extend(cx, i.ident), m, cx); } } - item_enum(vs, _) { + item_enum(vs, _) => { for vs.each |v| { cx.map.insert(v.node.id, node_variant( /* FIXME (#2543) */ copy v, i, extend(cx, i.ident))); } } - item_foreign_mod(nm) { + item_foreign_mod(nm) => { let abi = alt attr::foreign_abi(i.attrs) { - either::left(msg) { cx.diag.span_fatal(i.span, msg); } - either::right(abi) { abi } + either::left(msg) => cx.diag.span_fatal(i.span, msg), + either::right(abi) => abi }; for nm.items.each |nitem| { cx.map.insert(nitem.id, @@ -216,7 +216,7 @@ fn map_item(i: @item, cx: ctx, v: vt) { extend(cx, i.ident))); } } - item_class(tps, traits, items, ctor, dtor) { + item_class(tps, traits, items, ctor, dtor) => { let (_, ms) = ast_util::split_class_items(items); // Map trait refs to their parent classes. This is // so we can find the self_ty @@ -231,7 +231,7 @@ fn map_item(i: @item, cx: ctx, v: vt) { // only need to handle methods do vec::iter(ms) |m| { map_method(d_id, p, m, cx); } } - item_trait(tps, traits, methods) { + item_trait(tps, traits, methods) => { // Map trait refs to their parent classes. This is // so we can find the self_ty for traits.each |p| { @@ -246,13 +246,13 @@ fn map_item(i: @item, cx: ctx, v: vt) { cx.map.insert(id, node_trait_method(@tm, d_id, item_path)); } } - _ { } + _ => () } alt i.node { - item_mod(_) | item_foreign_mod(_) { + item_mod(_) | item_foreign_mod(_) => { vec::push(cx.path, path_mod(i.ident)); } - _ { vec::push(cx.path, path_name(i.ident)); } + _ => vec::push(cx.path, path_name(i.ident)) } visit::visit_item(i, cx, v); vec::pop(cx.path); @@ -260,20 +260,18 @@ fn map_item(i: @item, cx: ctx, v: vt) { fn map_view_item(vi: @view_item, cx: ctx, _v: vt) { alt vi.node { - view_item_export(vps) { - for vps.each |vp| { - let (id, name) = alt vp.node { - view_path_simple(nm, _, id) { - (id, /* FIXME (#2543) */ copy nm) - } - view_path_glob(pth, id) | view_path_list(pth, _, id) { - (id, path_to_ident(pth)) - } - }; - cx.map.insert(id, node_export(vp, extend(cx, name))); - } + view_item_export(vps) => for vps.each |vp| { + let (id, name) = alt vp.node { + view_path_simple(nm, _, id) => { + (id, /* FIXME (#2543) */ copy nm) + } + view_path_glob(pth, id) | view_path_list(pth, _, id) => { + (id, path_to_ident(pth)) + } + }; + cx.map.insert(id, node_export(vp, extend(cx, name))); } - _ {} + _ => () } } @@ -284,51 +282,51 @@ fn map_expr(ex: @expr, cx: ctx, v: vt) { fn node_id_to_str(map: map, id: node_id) -> ~str { alt map.find(id) { - none { + none => { fmt!{"unknown node (id=%d)", id} } - some(node_item(item, path)) { + some(node_item(item, path)) => { fmt!{"item %s (id=%?)", path_ident_to_str(*path, item.ident), id} } - some(node_foreign_item(item, abi, path)) { + some(node_foreign_item(item, abi, path)) => { fmt!{"foreign item %s with abi %? (id=%?)", path_ident_to_str(*path, item.ident), abi, id} } - some(node_method(m, impl_did, path)) { + some(node_method(m, impl_did, path)) => { fmt!{"method %s in %s (id=%?)", *m.ident, path_to_str(*path), id} } - some(node_trait_method(tm, impl_did, path)) { + some(node_trait_method(tm, impl_did, path)) => { let m = ast_util::trait_method_to_ty_method(*tm); fmt!{"method %s in %s (id=%?)", *m.ident, path_to_str(*path), id} } - some(node_variant(variant, def_id, path)) { + some(node_variant(variant, def_id, path)) => { fmt!{"variant %s in %s (id=%?)", *variant.node.name, path_to_str(*path), id} } - some(node_expr(expr)) { + some(node_expr(expr)) => { fmt!{"expr %s (id=%?)", pprust::expr_to_str(expr), id} } // FIXMEs are as per #2410 - some(node_export(_, path)) { + some(node_export(_, path)) => { fmt!{"export %s (id=%?)", // add more info here path_to_str(*path), id} } - some(node_arg(_, _)) { // add more info here + some(node_arg(_, _)) => { // add more info here fmt!{"arg (id=%?)", id} } - some(node_local(_)) { // add more info here + some(node_local(_)) => { // add more info here fmt!{"local (id=%?)", id} } - some(node_ctor(*)) { // add more info here + some(node_ctor(*)) => { // add more info here fmt!{"node_ctor (id=%?)", id} } - some(node_dtor(*)) { // add more info here + some(node_dtor(*)) => { // add more info here fmt!{"node_dtor (id=%?)", id} } - some(node_block(_)) { + some(node_block(_)) => { fmt!{"block"} } } diff --git a/src/libsyntax/ast_util.rs b/src/libsyntax/ast_util.rs index d1c553ec5ae..cf5168fc6da 100644 --- a/src/libsyntax/ast_util.rs +++ b/src/libsyntax/ast_util.rs @@ -36,16 +36,19 @@ pure fn is_local(did: ast::def_id) -> bool { did.crate == local_crate } pure fn stmt_id(s: stmt) -> node_id { alt s.node { - stmt_decl(_, id) { id } - stmt_expr(_, id) { id } - stmt_semi(_, id) { id } + stmt_decl(_, id) => id, + stmt_expr(_, id) => id, + stmt_semi(_, id) => id } } fn variant_def_ids(d: def) -> {enm: def_id, var: def_id} { - alt d { def_variant(enum_id, var_id) { - return {enm: enum_id, var: var_id}; } - _ { fail ~"non-variant in variant_def_ids"; } } + alt d { + def_variant(enum_id, var_id) => { + return {enm: enum_id, var: var_id} + } + _ => fail ~"non-variant in variant_def_ids" + } } pure fn def_id_of_def(d: def) -> def_id { @@ -53,117 +56,129 @@ pure fn def_id_of_def(d: def) -> def_id { def_fn(id, _) | def_mod(id) | def_foreign_mod(id) | def_const(id) | def_variant(_, id) | def_ty(id) | def_ty_param(id, _) | - def_use(id) | def_class(id, _) { id } + def_use(id) | def_class(id, _) => { + id + } def_arg(id, _) | def_local(id, _) | def_self(id) | def_upvar(id, _, _) | def_binding(id, _) | def_region(id) - | def_typaram_binder(id) { + | def_typaram_binder(id) => { local_def(id) } - def_prim_ty(_) { fail; } + def_prim_ty(_) => fail } } pure fn binop_to_str(op: binop) -> ~str { alt op { - add { return ~"+"; } - subtract { return ~"-"; } - mul { return ~"*"; } - div { return ~"/"; } - rem { return ~"%"; } - and { return ~"&&"; } - or { return ~"||"; } - bitxor { return ~"^"; } - bitand { return ~"&"; } - bitor { return ~"|"; } - shl { return ~"<<"; } - shr { return ~">>"; } - eq { return ~"=="; } - lt { return ~"<"; } - le { return ~"<="; } - ne { return ~"!="; } - ge { return ~">="; } - gt { return ~">"; } + add => return ~"+", + subtract => return ~"-", + mul => return ~"*", + div => return ~"/", + rem => return ~"%", + and => return ~"&&", + or => return ~"||", + bitxor => return ~"^", + bitand => return ~"&", + bitor => return ~"|", + shl => return ~"<<", + shr => return ~">>", + eq => return ~"==", + lt => return ~"<", + le => return ~"<=", + ne => return ~"!=", + ge => return ~">=", + gt => return ~">" } } pure fn binop_to_method_name(op: binop) -> option<~str> { alt op { - add { return some(~"add"); } - subtract { return some(~"sub"); } - mul { return some(~"mul"); } - div { return some(~"div"); } - rem { return some(~"modulo"); } - bitxor { return some(~"bitxor"); } - bitand { return some(~"bitand"); } - bitor { return some(~"bitor"); } - shl { return some(~"shl"); } - shr { return some(~"shr"); } - and | or | eq | lt | le | ne | ge | gt { return none; } + add => return some(~"add"), + subtract => return some(~"sub"), + mul => return some(~"mul"), + div => return some(~"div"), + rem => return some(~"modulo"), + bitxor => return some(~"bitxor"), + bitand => return some(~"bitand"), + bitor => return some(~"bitor"), + shl => return some(~"shl"), + shr => return some(~"shr"), + and | or | eq | lt | le | ne | ge | gt => return none } } pure fn lazy_binop(b: binop) -> bool { - alt b { and { true } or { true } _ { false } } + alt b { + and => true, + or => true, + _ => false + } } pure fn is_shift_binop(b: binop) -> bool { alt b { - shl { true } - shr { true } - _ { false } + shl => true, + shr => true, + _ => false } } pure fn unop_to_str(op: unop) -> ~str { alt op { - box(mt) { if mt == m_mutbl { ~"@mut " } else { ~"@" } } - uniq(mt) { if mt == m_mutbl { ~"~mut " } else { ~"~" } } - deref { ~"*" } - not { ~"!" } - neg { ~"-" } + box(mt) => if mt == m_mutbl { ~"@mut " } else { ~"@" }, + uniq(mt) => if mt == m_mutbl { ~"~mut " } else { ~"~" }, + deref => ~"*", + not => ~"!", + neg => ~"-" } } pure fn is_path(e: @expr) -> bool { - return alt e.node { expr_path(_) { true } _ { false } }; + return alt e.node { expr_path(_) => true, _ => false }; } pure fn int_ty_to_str(t: int_ty) -> ~str { alt t { - ty_char { ~"u8" } // ??? - ty_i { ~"" } ty_i8 { ~"i8" } ty_i16 { ~"i16" } - ty_i32 { ~"i32" } ty_i64 { ~"i64" } + ty_char => ~"u8", // ??? + ty_i => ~"", + ty_i8 => ~"i8", + ty_i16 => ~"i16", + ty_i32 => ~"i32", + ty_i64 => ~"i64" } } pure fn int_ty_max(t: int_ty) -> u64 { alt t { - ty_i8 { 0x80u64 } - ty_i16 { 0x8000u64 } - ty_i | ty_char | ty_i32 { 0x80000000u64 } // actually ni about ty_i - ty_i64 { 0x8000000000000000u64 } + ty_i8 => 0x80u64, + ty_i16 => 0x8000u64, + ty_i | ty_char | ty_i32 => 0x80000000u64, // actually ni about ty_i + ty_i64 => 0x8000000000000000u64 } } pure fn uint_ty_to_str(t: uint_ty) -> ~str { alt t { - ty_u { ~"u" } ty_u8 { ~"u8" } ty_u16 { ~"u16" } - ty_u32 { ~"u32" } ty_u64 { ~"u64" } + ty_u => ~"u", + ty_u8 => ~"u8", + ty_u16 => ~"u16", + ty_u32 => ~"u32", + ty_u64 => ~"u64" } } pure fn uint_ty_max(t: uint_ty) -> u64 { alt t { - ty_u8 { 0xffu64 } - ty_u16 { 0xffffu64 } - ty_u | ty_u32 { 0xffffffffu64 } // actually ni about ty_u - ty_u64 { 0xffffffffffffffffu64 } + ty_u8 => 0xffu64, + ty_u16 => 0xffffu64, + ty_u | ty_u32 => 0xffffffffu64, // actually ni about ty_u + ty_u64 => 0xffffffffffffffffu64 } } pure fn float_ty_to_str(t: float_ty) -> ~str { - alt t { ty_f { ~"f" } ty_f32 { ~"f32" } ty_f64 { ~"f64" } } + alt t { ty_f => ~"f", ty_f32 => ~"f32", ty_f64 => ~"f64" } } fn is_exported(i: ident, m: _mod) -> bool { @@ -172,36 +187,34 @@ fn is_exported(i: ident, m: _mod) -> bool { for m.items.each |it| { if it.ident == i { local = true; } alt it.node { - item_enum(variants, _) { - for variants.each |v| { - if v.node.name == i { - local = true; - parent_enum = some(/* FIXME (#2543) */ copy it.ident); - } + item_enum(variants, _) => for variants.each |v| { + if v.node.name == i { + local = true; + parent_enum = some(/* FIXME (#2543) */ copy it.ident); } } - _ { } + _ => () } if local { break; } } let mut has_explicit_exports = false; for m.view_items.each |vi| { alt vi.node { - view_item_export(vps) { + view_item_export(vps) => { has_explicit_exports = true; for vps.each |vp| { alt vp.node { - ast::view_path_simple(id, _, _) { + ast::view_path_simple(id, _, _) => { if id == i { return true; } alt parent_enum { - some(parent_enum_id) { + some(parent_enum_id) => { if id == parent_enum_id { return true; } } - _ {} + _ => () } } - ast::view_path_list(path, ids, _) { + ast::view_path_list(path, ids, _) => { if vec::len(path.idents) == 1u { if i == path.idents[0] { return true; } for ids.each |id| { @@ -213,11 +226,11 @@ fn is_exported(i: ident, m: _mod) -> bool { } // FIXME: glob-exports aren't supported yet. (#2006) - _ {} + _ => () } } } - _ {} + _ => () } } // If there are no declared exports then @@ -227,7 +240,7 @@ fn is_exported(i: ident, m: _mod) -> bool { } pure fn is_call_expr(e: @expr) -> bool { - alt e.node { expr_call(_, _, _) { true } _ { false } } + alt e.node { expr_call(_, _, _) => true, _ => false } } pure fn eq_ty(a: &@ty, b: &@ty) -> bool { box::ptr_eq(*a, *b) } @@ -272,8 +285,8 @@ fn ident_to_path(s: span, +i: ident) -> @path { pure fn is_unguarded(&&a: arm) -> bool { alt a.guard { - none { true } - _ { false } + none => true, + _ => false } } @@ -283,8 +296,8 @@ pure fn unguarded_pat(a: arm) -> option<~[@pat]> { pure fn class_item_ident(ci: @class_member) -> ident { alt ci.node { - instance_var(i,_,_,_,_) { /* FIXME (#2543) */ copy i } - class_method(it) { /* FIXME (#2543) */ copy it.ident } + instance_var(i,_,_,_,_) => /* FIXME (#2543) */ copy i, + class_method(it) => /* FIXME (#2543) */ copy it.ident } } @@ -294,8 +307,8 @@ type ivar = {ident: ident, ty: @ty, cm: class_mutability, fn public_methods(ms: ~[@method]) -> ~[@method] { vec::filter(ms, |m| alt m.vis { - public { true } - _ { false } + public => true, + _ => false }) } @@ -303,14 +316,14 @@ fn split_class_items(cs: ~[@class_member]) -> (~[ivar], ~[@method]) { let mut vs = ~[], ms = ~[]; for cs.each |c| { alt c.node { - instance_var(i, t, cm, id, vis) { + instance_var(i, t, cm, id, vis) => { vec::push(vs, {ident: /* FIXME (#2543) */ copy i, ty: t, cm: cm, id: id, vis: vis}); } - class_method(m) { vec::push(ms, m); } + class_method(m) => vec::push(ms, m) } }; (vs, ms) @@ -320,8 +333,8 @@ fn split_class_items(cs: ~[@class_member]) -> (~[ivar], ~[@method]) { // a default, pull out the useful fields to make a ty_method fn trait_method_to_ty_method(method: trait_method) -> ty_method { alt method { - required(m) { m } - provided(m) { + required(m) => m, + provided(m) => { {ident: m.ident, attrs: m.attrs, decl: m.decl, tps: m.tps, self_ty: m.self_ty, id: m.id, span: m.span} @@ -334,8 +347,8 @@ fn split_trait_methods(trait_methods: ~[trait_method]) let mut reqd = ~[], provd = ~[]; for trait_methods.each |trt_method| { alt trt_method { - required(tm) { vec::push(reqd, tm); } - provided(m) { vec::push(provd, m); } + required(tm) => vec::push(reqd, tm), + provided(m) => vec::push(provd, m) } }; (reqd, provd) @@ -343,8 +356,8 @@ fn split_trait_methods(trait_methods: ~[trait_method]) pure fn class_member_visibility(ci: @class_member) -> visibility { alt ci.node { - instance_var(_, _, _, _, vis) { vis } - class_method(m) { m.vis } + instance_var(_, _, _, _, vis) => vis, + class_method(m) => m.vis } } @@ -357,33 +370,33 @@ trait inlined_item_utils { impl inlined_item_methods of inlined_item_utils for inlined_item { fn ident() -> ident { alt self { - ii_item(i) { /* FIXME (#2543) */ copy i.ident } - ii_foreign(i) { /* FIXME (#2543) */ copy i.ident } - ii_method(_, m) { /* FIXME (#2543) */ copy m.ident } - ii_ctor(_, nm, _, _) { /* FIXME (#2543) */ copy nm } - ii_dtor(_, nm, _, _) { /* FIXME (#2543) */ copy nm } + ii_item(i) => /* FIXME (#2543) */ copy i.ident, + ii_foreign(i) => /* FIXME (#2543) */ copy i.ident, + ii_method(_, m) => /* FIXME (#2543) */ copy m.ident, + ii_ctor(_, nm, _, _) => /* FIXME (#2543) */ copy nm, + ii_dtor(_, nm, _, _) => /* FIXME (#2543) */ copy nm } } fn id() -> ast::node_id { alt self { - ii_item(i) { i.id } - ii_foreign(i) { i.id } - ii_method(_, m) { m.id } - ii_ctor(ctor, _, _, _) { ctor.node.id } - ii_dtor(dtor, _, _, _) { dtor.node.id } + ii_item(i) => i.id, + ii_foreign(i) => i.id, + ii_method(_, m) => m.id, + ii_ctor(ctor, _, _, _) => ctor.node.id, + ii_dtor(dtor, _, _, _) => dtor.node.id } } fn accept<E>(e: E, v: visit::vt<E>) { alt self { - ii_item(i) { v.visit_item(i, e, v) } - ii_foreign(i) { v.visit_foreign_item(i, e, v) } - ii_method(_, m) { visit::visit_method_helper(m, e, v) } - ii_ctor(ctor, nm, tps, parent_id) { + ii_item(i) => v.visit_item(i, e, v), + ii_foreign(i) => v.visit_foreign_item(i, e, v), + ii_method(_, m) => visit::visit_method_helper(m, e, v), + ii_ctor(ctor, nm, tps, parent_id) => { visit::visit_class_ctor_helper(ctor, nm, tps, parent_id, e, v); } - ii_dtor(dtor, nm, tps, parent_id) { + ii_dtor(dtor, nm, tps, parent_id) => { visit::visit_class_dtor_helper(dtor, tps, parent_id, e, v); } } @@ -394,26 +407,26 @@ impl inlined_item_methods of inlined_item_utils for inlined_item { referring to a def_self */ fn is_self(d: ast::def) -> bool { alt d { - def_self(_) { true } - def_upvar(_, d, _) { is_self(*d) } - _ { false } + def_self(_) => true, + def_upvar(_, d, _) => is_self(*d), + _ => false } } /// Maps a binary operator to its precedence fn operator_prec(op: ast::binop) -> uint { alt op { - mul | div | rem { 12u } + mul | div | rem => 12u, // 'as' sits between here with 11 - add | subtract { 10u } - shl | shr { 9u } - bitand { 8u } - bitxor { 7u } - bitor { 6u } - lt | le | ge | gt { 4u } - eq | ne { 3u } - and { 2u } - or { 1u } + add | subtract => 10u, + shl | shr => 9u, + bitand => 8u, + bitxor => 7u, + bitor => 6u, + lt | le | ge | gt => 4u, + eq | ne => 3u, + and => 2u, + or => 1u } } @@ -443,13 +456,13 @@ fn id_visitor(vfn: fn@(node_id)) -> visit::vt<()> { visit_view_item: fn@(vi: @view_item) { alt vi.node { - view_item_use(_, _, id) { vfn(id) } - view_item_import(vps) | view_item_export(vps) { + view_item_use(_, _, id) => vfn(id), + view_item_import(vps) | view_item_export(vps) => { do vec::iter(vps) |vp| { alt vp.node { - view_path_simple(_, _, id) { vfn(id) } - view_path_glob(_, id) { vfn(id) } - view_path_list(_, _, id) { vfn(id) } + view_path_simple(_, _, id) => vfn(id), + view_path_glob(_, id) => vfn(id), + view_path_list(_, _, id) => vfn(id) } } } @@ -463,8 +476,8 @@ fn id_visitor(vfn: fn@(node_id)) -> visit::vt<()> { visit_item: fn@(i: @item) { vfn(i.id); alt i.node { - item_enum(vs, _) { for vs.each |v| { vfn(v.node.id); } } - _ {} + item_enum(vs, _) => for vs.each |v| { vfn(v.node.id); } + _ => () } }, @@ -499,10 +512,8 @@ fn id_visitor(vfn: fn@(node_id)) -> visit::vt<()> { visit_ty: fn@(t: @ty) { alt t.node { - ty_path(_, id) { - vfn(id) - } - _ { /* fall through */ } + ty_path(_, id) => vfn(id), + _ => { /* fall through */ } } }, @@ -515,27 +526,27 @@ fn id_visitor(vfn: fn@(node_id)) -> visit::vt<()> { vfn(id); alt fk { - visit::fk_ctor(nm, _, tps, self_id, parent_id) { + visit::fk_ctor(nm, _, tps, self_id, parent_id) => { vec::iter(tps, |tp| vfn(tp.id)); vfn(id); vfn(self_id); vfn(parent_id.node); } - visit::fk_dtor(tps, _, self_id, parent_id) { + visit::fk_dtor(tps, _, self_id, parent_id) => { vec::iter(tps, |tp| vfn(tp.id)); vfn(id); vfn(self_id); vfn(parent_id.node); } - visit::fk_item_fn(_, tps) { + visit::fk_item_fn(_, tps) => { vec::iter(tps, |tp| vfn(tp.id)); } - visit::fk_method(_, tps, m) { + visit::fk_method(_, tps, m) => { vfn(m.self_id); vec::iter(tps, |tp| vfn(tp.id)); } visit::fk_anon(_, capture_clause) - | visit::fk_fn_block(capture_clause) { + | visit::fk_fn_block(capture_clause) => { for vec::each(*capture_clause) |clause| { vfn(clause.id); } @@ -555,11 +566,8 @@ fn id_visitor(vfn: fn@(node_id)) -> visit::vt<()> { visit_class_item: fn@(c: @class_member) { alt c.node { - instance_var(_, _, _, id,_) { - vfn(id) - } - class_method(_) { - } + instance_var(_, _, _, id,_) => vfn(id), + class_method(_) => () } } }) @@ -585,31 +593,29 @@ fn compute_id_range_for_inlined_item(item: inlined_item) -> id_range { pure fn is_item_impl(item: @ast::item) -> bool { alt item.node { - item_impl(*) { true } - _ { false } + item_impl(*) => true, + _ => false } } fn walk_pat(pat: @pat, it: fn(@pat)) { it(pat); alt pat.node { - pat_ident(_, pth, some(p)) { walk_pat(p, it); } - pat_rec(fields, _) { - for fields.each |f| { walk_pat(f.pat, it); } - } - pat_enum(_, some(s)) | pat_tup(s) { - for s.each |p| { walk_pat(p, it); } + pat_ident(_, pth, some(p)) => walk_pat(p, it), + pat_rec(fields, _) => for fields.each |f| { walk_pat(f.pat, it) } + pat_enum(_, some(s)) | pat_tup(s) => for s.each |p| { + walk_pat(p, it) } - pat_box(s) | pat_uniq(s) { walk_pat(s, it); } + pat_box(s) | pat_uniq(s) => walk_pat(s, it), pat_wild | pat_lit(_) | pat_range(_, _) | pat_ident(_, _, _) - | pat_enum(_, _) {} + | pat_enum(_, _) => () } } fn view_path_id(p: @view_path) -> node_id { alt p.node { view_path_simple(_, _, id) | view_path_glob(_, id) | - view_path_list(_, _, id) { id } + view_path_list(_, _, id) => id } } diff --git a/src/libsyntax/attr.rs b/src/libsyntax/attr.rs index da0dec061bb..f04a8e42ab7 100644 --- a/src/libsyntax/attr.rs +++ b/src/libsyntax/attr.rs @@ -115,9 +115,9 @@ fn get_attr_name(attr: ast::attribute) -> ast::ident { // All "bad" FIXME copies are as per #2543 fn get_meta_item_name(meta: @ast::meta_item) -> ast::ident { alt meta.node { - ast::meta_word(n) { /* FIXME (#2543) */ copy n } - ast::meta_name_value(n, _) { /* FIXME (#2543) */ copy n } - ast::meta_list(n, _) { /* FIXME (#2543) */ copy n } + ast::meta_word(n) => /* FIXME (#2543) */ copy n, + ast::meta_name_value(n, _) => /* FIXME (#2543) */ copy n, + ast::meta_list(n, _) => /* FIXME (#2543) */ copy n } } @@ -127,25 +127,19 @@ fn get_meta_item_name(meta: @ast::meta_item) -> ast::ident { */ fn get_meta_item_value_str(meta: @ast::meta_item) -> option<@~str> { alt meta.node { - ast::meta_name_value(_, v) { - alt v.node { - ast::lit_str(s) { - option::some(s) - } - _ { - option::none - } - } + ast::meta_name_value(_, v) => alt v.node { + ast::lit_str(s) => option::some(s), + _ => option::none } - _ { option::none } + _ => option::none } } /// Gets a list of inner meta items from a list meta_item type fn get_meta_item_list(meta: @ast::meta_item) -> option<~[@ast::meta_item]> { alt meta.node { - ast::meta_list(_, l) { option::some(/* FIXME (#2543) */ copy l) } - _ { option::none } + ast::meta_list(_, l) => option::some(/* FIXME (#2543) */ copy l), + _ => option::none } } @@ -157,11 +151,11 @@ fn get_name_value_str_pair( item: @ast::meta_item ) -> option<(ast::ident, @~str)> { alt attr::get_meta_item_value_str(item) { - some(value) { + some(value) => { let name = attr::get_meta_item_name(item); some((name, value)) } - none { none } + none => none } } @@ -210,16 +204,15 @@ fn contains(haystack: ~[@ast::meta_item], needle: @ast::meta_item) -> bool { fn eq(a: @ast::meta_item, b: @ast::meta_item) -> bool { return alt a.node { - ast::meta_word(na) { - alt b.node { ast::meta_word(nb) { na == nb } _ { false } } + ast::meta_word(na) => alt b.node { + ast::meta_word(nb) => na == nb, + _ => false } - ast::meta_name_value(na, va) { - alt b.node { - ast::meta_name_value(nb, vb) { na == nb && va.node == vb.node } - _ { false } - } + ast::meta_name_value(na, va) => alt b.node { + ast::meta_name_value(nb, vb) => na == nb && va.node == vb.node, + _ => false } - ast::meta_list(na, la) { + ast::meta_list(na, la) => { // ~[Fixme-sorting] // FIXME (#607): Needs implementing @@ -261,13 +254,11 @@ fn last_meta_item_value_str_by_name( +name: ~str ) -> option<@~str> { alt last_meta_item_by_name(items, name) { - some(item) { - alt attr::get_meta_item_value_str(item) { - some(value) { some(value) } - none { none } - } + some(item) => alt attr::get_meta_item_value_str(item) { + some(value) => some(value), + none => none } - none { none } + none => none } } @@ -276,10 +267,8 @@ fn last_meta_item_list_by_name( +name: ~str ) -> option<~[@ast::meta_item]> { alt last_meta_item_by_name(items, name) { - some(item) { - attr::get_meta_item_list(item) - } - none { none } + some(item) => attr::get_meta_item_list(item), + none => none } } @@ -292,9 +281,9 @@ fn sort_meta_items(+items: ~[@ast::meta_item]) -> ~[@ast::meta_item] { pure fn lteq(ma: &@ast::meta_item, mb: &@ast::meta_item) -> bool { pure fn key(m: &ast::meta_item) -> ast::ident { alt m.node { - ast::meta_word(name) { /* FIXME (#2543) */ copy name } - ast::meta_name_value(name, _) { /* FIXME (#2543) */ copy name } - ast::meta_list(name, _) { /* FIXME (#2543) */ copy name } + ast::meta_word(name) => /* FIXME (#2543) */ copy name, + ast::meta_name_value(name, _) => /* FIXME (#2543) */ copy name, + ast::meta_list(name, _) => /* FIXME (#2543) */ copy name } } key(*ma) <= key(*mb) @@ -322,8 +311,8 @@ fn find_linkage_attrs(attrs: ~[ast::attribute]) -> ~[ast::attribute] { let mut found = ~[]; for find_attrs_by_name(attrs, ~"link").each |attr| { alt attr.node.value.node { - ast::meta_list(_, _) { vec::push(found, attr) } - _ { debug!{"ignoring link attribute that has incorrect type"}; } + ast::meta_list(_, _) => vec::push(found, attr), + _ => debug!{"ignoring link attribute that has incorrect type"} } } return found; @@ -336,26 +325,26 @@ fn find_linkage_attrs(attrs: ~[ast::attribute]) -> ~[ast::attribute] { fn find_linkage_metas(attrs: ~[ast::attribute]) -> ~[@ast::meta_item] { do find_linkage_attrs(attrs).flat_map |attr| { alt check attr.node.value.node { - ast::meta_list(_, items) { /* FIXME (#2543) */ copy items } + ast::meta_list(_, items) => /* FIXME (#2543) */ copy items } } } fn foreign_abi(attrs: ~[ast::attribute]) -> either<~str, ast::foreign_abi> { return alt attr::first_attr_value_str_by_name(attrs, ~"abi") { - option::none { + option::none => { either::right(ast::foreign_abi_cdecl) } - option::some(@~"rust-intrinsic") { + option::some(@~"rust-intrinsic") => { either::right(ast::foreign_abi_rust_intrinsic) } - option::some(@~"cdecl") { + option::some(@~"cdecl") => { either::right(ast::foreign_abi_cdecl) } - option::some(@~"stdcall") { + option::some(@~"stdcall") => { either::right(ast::foreign_abi_stdcall) } - option::some(t) { + option::some(t) => { either::left(~"unsupported abi: " + *t) } }; @@ -373,8 +362,8 @@ fn find_inline_attr(attrs: ~[ast::attribute]) -> inline_attr { // FIXME (#2809)---validate the usage of #[inline] and #[inline(always)] do vec::foldl(ia_none, attrs) |ia,attr| { alt attr.node.value.node { - ast::meta_word(@~"inline") { ia_hint } - ast::meta_list(@~"inline", items) { + ast::meta_word(@~"inline") => ia_hint, + ast::meta_list(@~"inline", items) => { if !vec::is_empty(find_meta_items_by_name(items, ~"always")) { ia_always } else if !vec::is_empty( @@ -384,7 +373,7 @@ fn find_inline_attr(attrs: ~[ast::attribute]) -> inline_attr { ia_hint } } - _ { ia } + _ => ia } } } diff --git a/src/libsyntax/codemap.rs b/src/libsyntax/codemap.rs index 95742451396..575edaa771c 100644 --- a/src/libsyntax/codemap.rs +++ b/src/libsyntax/codemap.rs @@ -125,16 +125,16 @@ fn lookup_char_pos_adj(map: codemap, pos: uint) { let loc = lookup_char_pos(map, pos); alt (loc.file.substr) { - fss_none { + fss_none => { {filename: /* FIXME (#2543) */ copy loc.file.name, line: loc.line, col: loc.col, file: some(loc.file)} } - fss_internal(sp) { + fss_internal(sp) => { lookup_char_pos_adj(map, sp.lo + (pos - loc.file.start_pos.ch)) } - fss_external(eloc) { + fss_external(eloc) => { {filename: /* FIXME (#2543) */ copy eloc.filename, line: eloc.line + loc.line - 1u, col: if loc.line == 1u {eloc.col + loc.col} else {loc.col}, @@ -147,12 +147,12 @@ fn adjust_span(map: codemap, sp: span) -> span { pure fn lookup(pos: file_pos) -> uint { return pos.ch; } let line = lookup_line(map, sp.lo, lookup); alt (line.fm.substr) { - fss_none {sp} - fss_internal(s) { + fss_none => sp, + fss_internal(s) => { adjust_span(map, {lo: s.lo + (sp.lo - line.fm.start_pos.ch), hi: s.lo + (sp.hi - line.fm.start_pos.ch), expn_info: sp.expn_info})} - fss_external(_) {sp} + fss_external(_) => sp } } @@ -197,8 +197,8 @@ fn span_to_lines(sp: span, cm: codemap::codemap) -> @file_lines { fn get_line(fm: filemap, line: int) -> ~str unsafe { let begin: uint = fm.lines[line].byte - fm.start_pos.byte; let end = alt str::find_char_from(*fm.src, '\n', begin) { - some(e) { e } - none { str::len(*fm.src) } + some(e) => e, + none => str::len(*fm.src) }; str::slice(*fm.src, begin, end) } diff --git a/src/libsyntax/diagnostic.rs b/src/libsyntax/diagnostic.rs index 98cf3953a29..6195849f340 100644 --- a/src/libsyntax/diagnostic.rs +++ b/src/libsyntax/diagnostic.rs @@ -88,10 +88,12 @@ impl codemap_handler of handler for handler_t { fn abort_if_errors() { let s; alt self.err_count { - 0u { return; } - 1u { s = ~"aborting due to previous error"; } - _ { s = fmt!{"aborting due to %u previous errors", - self.err_count}; } + 0u => return, + 1u => s = ~"aborting due to previous error", + _ => { + s = fmt!{"aborting due to %u previous errors", + self.err_count}; + } } self.fatal(s); } @@ -121,8 +123,8 @@ fn mk_span_handler(handler: handler, cm: codemap::codemap) -> span_handler { fn mk_handler(emitter: option<emitter>) -> handler { let emit = alt emitter { - some(e) { e } - none { + some(e) => e, + none => { let f = fn@(cmsp: option<(codemap::codemap, span)>, msg: ~str, t: level) { emit(cmsp, msg, t); @@ -146,19 +148,19 @@ enum level { fn diagnosticstr(lvl: level) -> ~str { alt lvl { - fatal { ~"error" } - error { ~"error" } - warning { ~"warning" } - note { ~"note" } + fatal => ~"error", + error => ~"error", + warning => ~"warning", + note => ~"note" } } fn diagnosticcolor(lvl: level) -> u8 { alt lvl { - fatal { term::color_bright_red } - error { term::color_bright_red } - warning { term::color_bright_yellow } - note { term::color_bright_green } + fatal => term::color_bright_red, + error => term::color_bright_red, + warning => term::color_bright_yellow, + note => term::color_bright_green } } @@ -181,7 +183,7 @@ fn print_diagnostic(topic: ~str, lvl: level, msg: ~str) { fn emit(cmsp: option<(codemap::codemap, span)>, msg: ~str, lvl: level) { alt cmsp { - some((cm, sp)) { + some((cm, sp)) => { let sp = codemap::adjust_span(cm,sp); let ss = codemap::span_to_str(sp, cm); let lines = codemap::span_to_lines(sp, cm); @@ -189,7 +191,7 @@ fn emit(cmsp: option<(codemap::codemap, span)>, highlight_lines(cm, sp, lines); print_macro_backtrace(cm, sp); } - none { + none => { print_diagnostic(~"", lvl, msg); } } @@ -265,7 +267,7 @@ fn print_macro_backtrace(cm: codemap::codemap, sp: span) { fn expect<T: copy>(diag: span_handler, opt: option<T>, msg: fn() -> ~str) -> T { alt opt { - some(t) { t } - none { diag.handler().bug(msg()); } + some(t) => t, + none => diag.handler().bug(msg()) } } diff --git a/src/libsyntax/ext/auto_serialize.rs b/src/libsyntax/ext/auto_serialize.rs index cc37b5cc8d0..6e9673f4bc2 100644 --- a/src/libsyntax/ext/auto_serialize.rs +++ b/src/libsyntax/ext/auto_serialize.rs @@ -102,18 +102,18 @@ fn expand(cx: ext_ctxt, do vec::flat_map(in_items) |in_item| { alt in_item.node { - ast::item_ty(ty, tps) { + ast::item_ty(ty, tps) => { vec::append(~[filter_attrs(in_item)], ty_fns(cx, in_item.ident, ty, tps)) } - ast::item_enum(variants, tps) { + ast::item_enum(variants, tps) => { vec::append(~[filter_attrs(in_item)], enum_fns(cx, in_item.ident, in_item.span, variants, tps)) } - _ { + _ => { cx.span_err(span, ~"#[auto_serialize] can only be \ applied to type and enum \ definitions"); @@ -376,12 +376,12 @@ fn ser_lambda(cx: ext_ctxt, tps: ser_tps_map, ty: @ast::ty, fn is_vec_or_str(ty: @ast::ty) -> bool { alt ty.node { - ast::ty_vec(_) { true } + ast::ty_vec(_) => true, // This may be wrong if the user has shadowed (!) str ast::ty_path(@{span: _, global: _, idents: ids, rp: none, types: _}, _) - if ids == ~[@~"str"] { true } - _ { false } + if ids == ~[@~"str"] => true, + _ => false } } @@ -392,37 +392,37 @@ fn ser_ty(cx: ext_ctxt, tps: ser_tps_map, let ext_cx = cx; // required for #ast{} alt ty.node { - ast::ty_nil { + ast::ty_nil => { ~[#ast[stmt]{$(s).emit_nil()}] } - ast::ty_bot { + ast::ty_bot => { cx.span_err( ty.span, fmt!{"Cannot serialize bottom type"}); ~[] } - ast::ty_box(mt) { + ast::ty_box(mt) => { let l = ser_lambda(cx, tps, mt.ty, cx.clone(s), #ast{ *$(v) }); ~[#ast[stmt]{$(s).emit_box($(l));}] } // For unique evecs/estrs, just pass through to underlying vec or str - ast::ty_uniq(mt) if is_vec_or_str(mt.ty) { + ast::ty_uniq(mt) if is_vec_or_str(mt.ty) => { ser_ty(cx, tps, mt.ty, s, v) } - ast::ty_uniq(mt) { + ast::ty_uniq(mt) => { let l = ser_lambda(cx, tps, mt.ty, cx.clone(s), #ast{ *$(v) }); ~[#ast[stmt]{$(s).emit_uniq($(l));}] } - ast::ty_ptr(_) | ast::ty_rptr(_, _) { + ast::ty_ptr(_) | ast::ty_rptr(_, _) => { cx.span_err(ty.span, ~"cannot serialize pointer types"); ~[] } - ast::ty_rec(flds) { + ast::ty_rec(flds) => { let fld_stmts = do vec::from_fn(vec::len(flds)) |fidx| { let fld = flds[fidx]; let vf = cx.expr(fld.span, @@ -439,12 +439,12 @@ fn ser_ty(cx: ext_ctxt, tps: ser_tps_map, ~[#ast[stmt]{$(s).emit_rec($(fld_lambda));}] } - ast::ty_fn(_, _) { + ast::ty_fn(_, _) => { cx.span_err(ty.span, ~"cannot serialize function types"); ~[] } - ast::ty_tup(tys) { + ast::ty_tup(tys) => { // Generate code like // // alt v { @@ -478,31 +478,31 @@ fn ser_ty(cx: ext_ctxt, tps: ser_tps_map, ~[cx.alt_stmt(arms, ty.span, v)] } - ast::ty_path(path, _) { + ast::ty_path(path, _) => { if vec::len(path.idents) == 1u && vec::is_empty(path.types) { let ident = path.idents[0]; alt tps.find(*ident) { - some(f) { f(v) } - none { ser_path(cx, tps, path, s, v) } + some(f) => f(v), + none => ser_path(cx, tps, path, s, v) } } else { ser_path(cx, tps, path, s, v) } } - ast::ty_mac(_) { + ast::ty_mac(_) => { cx.span_err(ty.span, ~"cannot serialize macro types"); ~[] } - ast::ty_infer { + ast::ty_infer => { cx.span_err(ty.span, ~"cannot serialize inferred types"); ~[] } - ast::ty_vec(mt) { + ast::ty_vec(mt) => { let ser_e = cx.expr( ty.span, @@ -519,7 +519,7 @@ fn ser_ty(cx: ext_ctxt, tps: ser_tps_map, }] } - ast::ty_fixed_length(_, _) { + ast::ty_fixed_length(_, _) => { cx.span_unimpl(ty.span, ~"serialization for fixed length types"); } } @@ -635,34 +635,34 @@ fn deser_ty(cx: ext_ctxt, tps: deser_tps_map, let ext_cx = cx; // required for #ast{} alt ty.node { - ast::ty_nil { + ast::ty_nil => { #ast{ $(d).read_nil() } } - ast::ty_bot { + ast::ty_bot => { #ast{ fail } } - ast::ty_box(mt) { + ast::ty_box(mt) => { let l = deser_lambda(cx, tps, mt.ty, cx.clone(d)); #ast{ @$(d).read_box($(l)) } } // For unique evecs/estrs, just pass through to underlying vec or str - ast::ty_uniq(mt) if is_vec_or_str(mt.ty) { + ast::ty_uniq(mt) if is_vec_or_str(mt.ty) => { deser_ty(cx, tps, mt.ty, d) } - ast::ty_uniq(mt) { + ast::ty_uniq(mt) => { let l = deser_lambda(cx, tps, mt.ty, cx.clone(d)); #ast{ ~$(d).read_uniq($(l)) } } - ast::ty_ptr(_) | ast::ty_rptr(_, _) { + ast::ty_ptr(_) | ast::ty_rptr(_, _) => { #ast{ fail } } - ast::ty_rec(flds) { + ast::ty_rec(flds) => { let fields = do vec::from_fn(vec::len(flds)) |fidx| { let fld = flds[fidx]; let d = cx.clone(d); @@ -679,11 +679,11 @@ fn deser_ty(cx: ext_ctxt, tps: deser_tps_map, #ast{ $(d).read_rec($(fld_lambda)) } } - ast::ty_fn(_, _) { + ast::ty_fn(_, _) => { #ast{ fail } } - ast::ty_tup(tys) { + ast::ty_tup(tys) => { // Generate code like // // d.read_tup(3u) {|| @@ -704,34 +704,34 @@ fn deser_ty(cx: ext_ctxt, tps: deser_tps_map, #ast{ $(d).read_tup($(sz), $(body)) } } - ast::ty_path(path, _) { + ast::ty_path(path, _) => { if vec::len(path.idents) == 1u && vec::is_empty(path.types) { let ident = path.idents[0]; alt tps.find(*ident) { - some(f) { f() } - none { deser_path(cx, tps, path, d) } + some(f) => f(), + none => deser_path(cx, tps, path, d) } } else { deser_path(cx, tps, path, d) } } - ast::ty_mac(_) { + ast::ty_mac(_) => { #ast{ fail } } - ast::ty_infer { + ast::ty_infer => { #ast{ fail } } - ast::ty_vec(mt) { + ast::ty_vec(mt) => { let l = deser_lambda(cx, tps, mt.ty, cx.clone(d)); #ast{ std::serialization::read_to_vec($(d), $(l)) } } - ast::ty_fixed_length(_, _) { + ast::ty_fixed_length(_, _) => { cx.span_unimpl(ty.span, ~"deserialization for fixed length types"); } } diff --git a/src/libsyntax/ext/base.rs b/src/libsyntax/ext/base.rs index 2947201003f..b8cce21190c 100644 --- a/src/libsyntax/ext/base.rs +++ b/src/libsyntax/ext/base.rs @@ -151,7 +151,7 @@ fn mk_ctxt(parse_sess: parse::parse_sess, fn mod_path() -> ~[ast::ident] { return self.mod_path; } fn bt_push(ei: codemap::expn_info_) { alt ei { - expanded_from({call_site: cs, callie: callie}) { + expanded_from({call_site: cs, callie: callie}) => { self.backtrace = some(@expanded_from({ call_site: {lo: cs.lo, hi: cs.hi, @@ -162,10 +162,10 @@ fn mk_ctxt(parse_sess: parse::parse_sess, } fn bt_pop() { alt self.backtrace { - some(@expanded_from({call_site: {expn_info: prev, _}, _})) { + some(@expanded_from({call_site: {expn_info: prev, _}, _})) => { self.backtrace = prev } - _ { self.bug(~"tried to pop without a push"); } + _ => self.bug(~"tried to pop without a push") } } fn span_fatal(sp: span, msg: ~str) -> ! { @@ -207,24 +207,22 @@ fn mk_ctxt(parse_sess: parse::parse_sess, fn expr_to_str(cx: ext_ctxt, expr: @ast::expr, error: ~str) -> ~str { alt expr.node { - ast::expr_lit(l) { - alt l.node { - ast::lit_str(s) { return *s; } - _ { cx.span_fatal(l.span, error); } - } + ast::expr_lit(l) => alt l.node { + ast::lit_str(s) => return *s, + _ => cx.span_fatal(l.span, error) } - _ { cx.span_fatal(expr.span, error); } + _ => cx.span_fatal(expr.span, error) } } fn expr_to_ident(cx: ext_ctxt, expr: @ast::expr, error: ~str) -> ast::ident { alt expr.node { - ast::expr_path(p) { + ast::expr_path(p) => { if vec::len(p.types) > 0u || vec::len(p.idents) != 1u { cx.span_fatal(expr.span, error); } else { return p.idents[0]; } } - _ { cx.span_fatal(expr.span, error); } + _ => cx.span_fatal(expr.span, error) } } @@ -236,29 +234,27 @@ fn get_mac_args_no_max(cx: ext_ctxt, sp: span, arg: ast::mac_arg, fn get_mac_args(cx: ext_ctxt, sp: span, arg: ast::mac_arg, min: uint, max: option<uint>, name: ~str) -> ~[@ast::expr] { alt arg { - some(expr) { - alt expr.node { - ast::expr_vec(elts, _) { + some(expr) => alt expr.node { + ast::expr_vec(elts, _) => { let elts_len = vec::len(elts); - alt max { - some(max) if ! (min <= elts_len && elts_len <= max) { - cx.span_fatal(sp, - fmt!{"#%s takes between %u and %u arguments.", - name, min, max}); - } - none if ! (min <= elts_len) { - cx.span_fatal(sp, fmt!{"#%s needs at least %u arguments.", - name, min}); + alt max { + some(max) if ! (min <= elts_len && elts_len <= max) => { + cx.span_fatal(sp, + fmt!{"#%s takes between %u and %u arguments.", + name, min, max}); + } + none if ! (min <= elts_len) => { + cx.span_fatal(sp, fmt!{"#%s needs at least %u arguments.", + name, min}); + } + _ => return elts /* we're good */ } - _ { return elts; /* we're good */} - } } - _ { + _ => { cx.span_fatal(sp, fmt!{"#%s: malformed invocation", name}) } - } } - none {cx.span_fatal(sp, fmt!{"#%s: missing arguments", name})} + none => cx.span_fatal(sp, fmt!{"#%s: missing arguments", name}) } } @@ -266,8 +262,8 @@ fn get_mac_body(cx: ext_ctxt, sp: span, args: ast::mac_body) -> ast::mac_body_ { alt (args) { - some(body) {body} - none {cx.span_fatal(sp, ~"missing macro body")} + some(body) => body, + none => cx.span_fatal(sp, ~"missing macro body") } } @@ -295,17 +291,15 @@ fn tt_args_to_original_flavor(cx: ext_ctxt, sp: span, arg: ~[ast::token_tree]) let args = alt parse_or_else(cx.parse_sess(), cx.cfg(), arg_reader as reader, argument_gram).get(@~"arg") { - @matched_seq(s, _) { - do s.map() |lf| { - alt lf { - @matched_nonterminal(parse::token::nt_expr(arg)) { - arg /* whew! list of exprs, here we come! */ - } - _ { fail ~"badly-structured parse result"; } - } + @matched_seq(s, _) => do s.map() |lf| { + alt lf { + @matched_nonterminal(parse::token::nt_expr(arg)) => { + arg /* whew! list of exprs, here we come! */ + } + _ => fail ~"badly-structured parse result" } } - _ { fail ~"badly-structured parse result"; } + _ => fail ~"badly-structured parse result" }; return some(@{id: parse::next_node_id(cx.parse_sess()), diff --git a/src/libsyntax/ext/env.rs b/src/libsyntax/ext/env.rs index 4aa55e88f16..143a675fa63 100644 --- a/src/libsyntax/ext/env.rs +++ b/src/libsyntax/ext/env.rs @@ -17,8 +17,8 @@ fn expand_syntax_ext(cx: ext_ctxt, sp: codemap::span, arg: ast::mac_arg, let var = expr_to_str(cx, args[0], ~"#env requires a string"); alt os::getenv(var) { - option::none { return mk_uniq_str(cx, sp, ~""); } - option::some(s) { return mk_uniq_str(cx, sp, s); } + option::none => return mk_uniq_str(cx, sp, ~""), + option::some(s) => return mk_uniq_str(cx, sp, s) } } diff --git a/src/libsyntax/ext/expand.rs b/src/libsyntax/ext/expand.rs index 24cc78e366e..ee1ec62e4e2 100644 --- a/src/libsyntax/ext/expand.rs +++ b/src/libsyntax/ext/expand.rs @@ -18,25 +18,25 @@ fn expand_expr(exts: hashmap<~str, syntax_extension>, cx: ext_ctxt, return alt e { // expr_mac should really be expr_ext or something; it's the // entry-point for all syntax extensions. - expr_mac(mac) { + expr_mac(mac) => { // Old-style macros, for compatibility, will erase this whole // block once we've transitioned. alt mac.node { - mac_invoc(pth, args, body) { + mac_invoc(pth, args, body) => { assert (vec::len(pth.idents) > 0u); let extname = pth.idents[0]; alt exts.find(*extname) { - none { + none => { cx.span_fatal(pth.span, fmt!{"macro undefined: '%s'", *extname}) } - some(item_decorator(_)) { + some(item_decorator(_)) => { cx.span_fatal( pth.span, fmt!{"%s can only be used as a decorator", *extname}); } - some(normal({expander: exp, span: exp_sp})) { + some(normal({expander: exp, span: exp_sp})) => { let expanded = exp(cx, mac.span, args, body); cx.bt_push(expanded_from({call_site: s, @@ -47,17 +47,17 @@ fn expand_expr(exts: hashmap<~str, syntax_extension>, cx: ext_ctxt, (fully_expanded, s) } - some(macro_defining(ext)) { + some(macro_defining(ext)) => { let named_extension = ext(cx, mac.span, args, body); exts.insert(*named_extension.ident, named_extension.ext); (ast::expr_rec(~[], none), s) } - some(expr_tt(_)) { + some(expr_tt(_)) => { cx.span_fatal(pth.span, fmt!{"this tt-style macro should be \ invoked '%s!{...}'", *extname}) } - some(item_tt(*)) { + some(item_tt(*)) => { cx.span_fatal(pth.span, ~"cannot use item macros in this context"); } @@ -66,20 +66,20 @@ fn expand_expr(exts: hashmap<~str, syntax_extension>, cx: ext_ctxt, // Token-tree macros, these will be the only case when we're // finished transitioning. - mac_invoc_tt(pth, tts) { + mac_invoc_tt(pth, tts) => { assert (vec::len(pth.idents) == 1u); let extname = pth.idents[0]; alt exts.find(*extname) { - none { + none => { cx.span_fatal(pth.span, fmt!{"macro undefined: '%s'", *extname}) } - some(expr_tt({expander: exp, span: exp_sp})) { + some(expr_tt({expander: exp, span: exp_sp})) => { let expanded = alt exp(cx, mac.span, tts) { - mr_expr(e) { e } - _ { cx.span_fatal( + mr_expr(e) => e, + _ => cx.span_fatal( pth.span, fmt!{"non-expr macro in expr pos: %s", - *extname}) } + *extname}) }; cx.bt_push(expanded_from({call_site: s, @@ -90,7 +90,7 @@ fn expand_expr(exts: hashmap<~str, syntax_extension>, cx: ext_ctxt, (fully_expanded, s) } - some(normal({expander: exp, span: exp_sp})) { + some(normal({expander: exp, span: exp_sp})) => { //convert the new-style invoc for the old-style macro let arg = base::tt_args_to_original_flavor(cx, pth.span, tts); @@ -104,7 +104,7 @@ fn expand_expr(exts: hashmap<~str, syntax_extension>, cx: ext_ctxt, (fully_expanded, s) } - _ { + _ => { cx.span_fatal(pth.span, fmt!{"'%s' is not a tt-style macro", *extname}) @@ -112,10 +112,10 @@ fn expand_expr(exts: hashmap<~str, syntax_extension>, cx: ext_ctxt, } } - _ { cx.span_bug(mac.span, ~"naked syntactic bit") } + _ => cx.span_bug(mac.span, ~"naked syntactic bit") } } - _ { orig(e, s, fld) } + _ => orig(e, s, fld) }; } @@ -142,17 +142,14 @@ fn expand_mod_items(exts: hashmap<~str, syntax_extension>, cx: ext_ctxt, let new_items = do vec::flat_map(module_.items) |item| { do vec::foldr(item.attrs, ~[item]) |attr, items| { let mname = alt attr.node.value.node { - ast::meta_word(n) { n } - ast::meta_name_value(n, _) { n } - ast::meta_list(n, _) { n } + ast::meta_word(n) => n, + ast::meta_name_value(n, _) => n, + ast::meta_list(n, _) => n }; alt exts.find(*mname) { none | some(normal(_)) | some(macro_defining(_)) - | some(expr_tt(_)) | some(item_tt(*)) { - items - } - - some(item_decorator(dec_fn)) { + | some(expr_tt(_)) | some(item_tt(*)) => items, + some(item_decorator(dec_fn)) => { dec_fn(cx, attr.span, attr.node.value, items) } } @@ -170,24 +167,22 @@ fn expand_item(exts: hashmap<~str, syntax_extension>, -> option<@ast::item> { let is_mod = alt it.node { - ast::item_mod(_) | ast::item_foreign_mod(_) {true} - _ {false} + ast::item_mod(_) | ast::item_foreign_mod(_) => true, + _ => false }; let maybe_it = alt it.node { - ast::item_mac(*) { - expand_item_mac(exts, cx, it, fld) - } - _ { some(it) } + ast::item_mac(*) => expand_item_mac(exts, cx, it, fld), + _ => some(it) }; alt maybe_it { - some(it) { + some(it) => { if is_mod { cx.mod_push(it.ident); } let ret_val = orig(it, fld); if is_mod { cx.mod_pop(); } return ret_val; } - none { return none; } + none => return none } } @@ -198,24 +193,24 @@ fn expand_item_mac(exts: hashmap<~str, syntax_extension>, cx: ext_ctxt, &&it: @ast::item, fld: ast_fold) -> option<@ast::item> { alt it.node { - item_mac({node: mac_invoc_tt(pth, tts), span}) { + item_mac({node: mac_invoc_tt(pth, tts), span}) => { let extname = pth.idents[0]; alt exts.find(*extname) { - none { + none => { cx.span_fatal(pth.span, fmt!{"macro undefined: '%s'", *extname}) } - some(item_tt(expand)) { + some(item_tt(expand)) => { let expanded = expand.expander(cx, it.span, it.ident, tts); cx.bt_push(expanded_from({call_site: it.span, callie: {name: *extname, span: expand.span}})); let maybe_it = alt expanded { - mr_item(it) { fld.fold_item(it) } - mr_expr(e) { cx.span_fatal(pth.span, + mr_item(it) => fld.fold_item(it), + mr_expr(e) => cx.span_fatal(pth.span, ~"expr macro in item position: " + - *extname) } - mr_def(mdef) { + *extname), + mr_def(mdef) => { exts.insert(*mdef.ident, mdef.ext); none } @@ -223,13 +218,11 @@ fn expand_item_mac(exts: hashmap<~str, syntax_extension>, cx.bt_pop(); return maybe_it } - _ { cx.span_fatal(it.span, - fmt!{"%s is not a legal here", *extname}) } + _ => cx.span_fatal(it.span, + fmt!{"%s is not a legal here", *extname}) } } - _ { - cx.span_bug(it.span, ~"invalid item macro invocation"); - } + _ => cx.span_bug(it.span, ~"invalid item macro invocation") } } diff --git a/src/libsyntax/ext/fmt.rs b/src/libsyntax/ext/fmt.rs index 10820664344..d1acf622c1f 100644 --- a/src/libsyntax/ext/fmt.rs +++ b/src/libsyntax/ext/fmt.rs @@ -53,11 +53,11 @@ fn pieces_to_expr(cx: ext_ctxt, sp: span, let mut tmp_expr = make_rt_path_expr(cx, sp, @~"flag_none"); for flags.each |f| { let fstr = alt f { - flag_left_justify { ~"flag_left_justify" } - flag_left_zero_pad { ~"flag_left_zero_pad" } - flag_space_for_sign { ~"flag_space_for_sign" } - flag_sign_always { ~"flag_sign_always" } - flag_alternate { ~"flag_alternate" } + flag_left_justify => ~"flag_left_justify", + flag_left_zero_pad => ~"flag_left_zero_pad", + flag_space_for_sign => ~"flag_space_for_sign", + flag_sign_always => ~"flag_sign_always", + flag_alternate => ~"flag_alternate" }; tmp_expr = mk_binary(cx, sp, ast::bitor, tmp_expr, make_rt_path_expr(cx, sp, @fstr)); @@ -66,30 +66,28 @@ fn pieces_to_expr(cx: ext_ctxt, sp: span, } fn make_count(cx: ext_ctxt, sp: span, cnt: count) -> @ast::expr { alt cnt { - count_implied { + count_implied => { return make_rt_path_expr(cx, sp, @~"count_implied"); } - count_is(c) { + count_is(c) => { let count_lit = mk_int(cx, sp, c); let count_is_path = make_path_vec(cx, @~"count_is"); let count_is_args = ~[count_lit]; return mk_call(cx, sp, count_is_path, count_is_args); } - _ { cx.span_unimpl(sp, ~"unimplemented #fmt conversion"); } + _ => cx.span_unimpl(sp, ~"unimplemented #fmt conversion") } } fn make_ty(cx: ext_ctxt, sp: span, t: ty) -> @ast::expr { let mut rt_type; alt t { - ty_hex(c) { - alt c { - case_upper { rt_type = ~"ty_hex_upper"; } - case_lower { rt_type = ~"ty_hex_lower"; } - } + ty_hex(c) => alt c { + case_upper => rt_type = ~"ty_hex_upper", + case_lower => rt_type = ~"ty_hex_lower" } - ty_bits { rt_type = ~"ty_bits"; } - ty_octal { rt_type = ~"ty_octal"; } - _ { rt_type = ~"ty_default"; } + ty_bits => rt_type = ~"ty_bits", + ty_octal => rt_type = ~"ty_octal", + _ => rt_type = ~"ty_default" } return make_rt_path_expr(cx, sp, @rt_type); } @@ -124,128 +122,117 @@ fn pieces_to_expr(cx: ext_ctxt, sp: span, fn is_signed_type(cnv: conv) -> bool { alt cnv.ty { - ty_int(s) { - alt s { signed { return true; } unsigned { return false; } } + ty_int(s) => alt s { + signed => return true, + unsigned => return false } - ty_float { return true; } - _ { return false; } + ty_float => return true, + _ => return false } } let unsupported = ~"conversion not supported in #fmt string"; alt cnv.param { - option::none { } - _ { cx.span_unimpl(sp, unsupported); } + option::none => (), + _ => cx.span_unimpl(sp, unsupported) } for cnv.flags.each |f| { alt f { - flag_left_justify { } - flag_sign_always { + flag_left_justify => (), + flag_sign_always => { if !is_signed_type(cnv) { cx.span_fatal(sp, ~"+ flag only valid in " + ~"signed #fmt conversion"); } } - flag_space_for_sign { + flag_space_for_sign => { if !is_signed_type(cnv) { cx.span_fatal(sp, ~"space flag only valid in " + ~"signed #fmt conversions"); } } - flag_left_zero_pad { } - _ { cx.span_unimpl(sp, unsupported); } + flag_left_zero_pad => (), + _ => cx.span_unimpl(sp, unsupported) } } alt cnv.width { - count_implied { } - count_is(_) { } - _ { cx.span_unimpl(sp, unsupported); } + count_implied => (), + count_is(_) => (), + _ => cx.span_unimpl(sp, unsupported) } alt cnv.precision { - count_implied { } - count_is(_) { } - _ { cx.span_unimpl(sp, unsupported); } + count_implied => (), + count_is(_) => (), + _ => cx.span_unimpl(sp, unsupported) } alt cnv.ty { - ty_str { return make_conv_call(cx, arg.span, ~"str", cnv, arg); } - ty_int(sign) { - alt sign { - signed { - return make_conv_call(cx, arg.span, ~"int", cnv, arg); - } - unsigned { - return make_conv_call(cx, arg.span, ~"uint", cnv, arg); - } + ty_str => return make_conv_call(cx, arg.span, ~"str", cnv, arg), + ty_int(sign) => alt sign { + signed => return make_conv_call(cx, arg.span, ~"int", cnv, arg), + unsigned => { + return make_conv_call(cx, arg.span, ~"uint", cnv, arg) } } - ty_bool { return make_conv_call(cx, arg.span, ~"bool", cnv, arg); } - ty_char { return make_conv_call(cx, arg.span, ~"char", cnv, arg); } - ty_hex(_) { + ty_bool => return make_conv_call(cx, arg.span, ~"bool", cnv, arg), + ty_char => return make_conv_call(cx, arg.span, ~"char", cnv, arg), + ty_hex(_) => { return make_conv_call(cx, arg.span, ~"uint", cnv, arg); } - ty_bits { return make_conv_call(cx, arg.span, ~"uint", cnv, arg); } - ty_octal { return make_conv_call(cx, arg.span, ~"uint", cnv, arg); } - ty_float { + ty_bits => return make_conv_call(cx, arg.span, ~"uint", cnv, arg), + ty_octal => return make_conv_call(cx, arg.span, ~"uint", cnv, arg), + ty_float => { return make_conv_call(cx, arg.span, ~"float", cnv, arg); } - ty_poly { return make_conv_call(cx, arg.span, ~"poly", cnv, arg); } + ty_poly => return make_conv_call(cx, arg.span, ~"poly", cnv, arg) } } fn log_conv(c: conv) { alt c.param { - some(p) { log(debug, ~"param: " + int::to_str(p, 10u)); } - _ { debug!{"param: none"}; } + some(p) => { log(debug, ~"param: " + int::to_str(p, 10u)); } + _ => debug!{"param: none"} } for c.flags.each |f| { alt f { - flag_left_justify { debug!{"flag: left justify"}; } - flag_left_zero_pad { debug!{"flag: left zero pad"}; } - flag_space_for_sign { debug!{"flag: left space pad"}; } - flag_sign_always { debug!{"flag: sign always"}; } - flag_alternate { debug!{"flag: alternate"}; } + flag_left_justify => debug!{"flag: left justify"}, + flag_left_zero_pad => debug!{"flag: left zero pad"}, + flag_space_for_sign => debug!{"flag: left space pad"}, + flag_sign_always => debug!{"flag: sign always"}, + flag_alternate => debug!{"flag: alternate"} } } alt c.width { - count_is(i) { log(debug, - ~"width: count is " + int::to_str(i, 10u)); } - count_is_param(i) { - log(debug, - ~"width: count is param " + int::to_str(i, 10u)); - } - count_is_next_param { debug!{"width: count is next param"}; } - count_implied { debug!{"width: count is implied"}; } + count_is(i) => log( + debug, ~"width: count is " + int::to_str(i, 10u)), + count_is_param(i) => log( + debug, ~"width: count is param " + int::to_str(i, 10u)), + count_is_next_param => debug!{"width: count is next param"}, + count_implied => debug!{"width: count is implied"} } alt c.precision { - count_is(i) { log(debug, - ~"prec: count is " + int::to_str(i, 10u)); } - count_is_param(i) { - log(debug, - ~"prec: count is param " + int::to_str(i, 10u)); - } - count_is_next_param { debug!{"prec: count is next param"}; } - count_implied { debug!{"prec: count is implied"}; } + count_is(i) => log( + debug, ~"prec: count is " + int::to_str(i, 10u)), + count_is_param(i) => log( + debug, ~"prec: count is param " + int::to_str(i, 10u)), + count_is_next_param => debug!{"prec: count is next param"}, + count_implied => debug!{"prec: count is implied"} } alt c.ty { - ty_bool { debug!{"type: bool"}; } - ty_str { debug!{"type: str"}; } - ty_char { debug!{"type: char"}; } - ty_int(s) { - alt s { - signed { debug!{"type: signed"}; } - unsigned { debug!{"type: unsigned"}; } - } + ty_bool => debug!{"type: bool"}, + ty_str => debug!{"type: str"}, + ty_char => debug!{"type: char"}, + ty_int(s) => alt s { + signed => debug!{"type: signed"}, + unsigned => debug!{"type: unsigned"} } - ty_bits { debug!{"type: bits"}; } - ty_hex(cs) { - alt cs { - case_upper { debug!{"type: uhex"}; } - case_lower { debug!{"type: lhex"}; } - } + ty_bits => debug!{"type: bits"}, + ty_hex(cs) => alt cs { + case_upper => debug!{"type: uhex"}, + case_lower => debug!{"type: lhex"}, } - ty_octal { debug!{"type: octal"}; } - ty_float { debug!{"type: float"}; } - ty_poly { debug!{"type: poly"}; } + ty_octal => debug!{"type: octal"}, + ty_float => debug!{"type: float"}, + ty_poly => debug!{"type: poly"} } } let fmt_sp = args[0].span; @@ -254,10 +241,10 @@ fn pieces_to_expr(cx: ext_ctxt, sp: span, let nargs = args.len(); for pieces.each |pc| { alt pc { - piece_string(s) { - vec::push(piece_exprs, mk_uniq_str(cx, fmt_sp, s)); + piece_string(s) => { + vec::push(piece_exprs, mk_uniq_str(cx, fmt_sp, s)) } - piece_conv(conv) { + piece_conv(conv) => { n += 1u; if n >= nargs { cx.span_fatal(sp, diff --git a/src/libsyntax/ext/pipes/check.rs b/src/libsyntax/ext/pipes/check.rs index 24ac18ada6a..59687eda96d 100644 --- a/src/libsyntax/ext/pipes/check.rs +++ b/src/libsyntax/ext/pipes/check.rs @@ -45,7 +45,7 @@ impl proto_check of proto::visitor<(), (), ()> for ext_ctxt { fn visit_message(name: ident, _span: span, _tys: &[@ast::ty], this: state, next: next_state) { alt next { - some({state: next, tys: next_tys}) { + some({state: next, tys: next_tys}) => { let proto = this.proto; if !proto.has_state(next) { // This should be a span fatal, but then we need to @@ -69,7 +69,7 @@ impl proto_check of proto::visitor<(), (), ()> for ext_ctxt { } } } - none { } + none => () } } } \ No newline at end of file diff --git a/src/libsyntax/ext/pipes/parse_proto.rs b/src/libsyntax/ext/pipes/parse_proto.rs index ea8c8c04b0e..678f5b36c45 100644 --- a/src/libsyntax/ext/pipes/parse_proto.rs +++ b/src/libsyntax/ext/pipes/parse_proto.rs @@ -26,16 +26,14 @@ impl proto_parser of proto_parser for parser { let id = self.parse_ident(); self.expect(token::COLON); let dir = alt copy self.token { - token::IDENT(n, _) { - self.get_str(n) - } - _ { fail } + token::IDENT(n, _) => self.get_str(n), + _ => fail }; self.bump(); let dir = alt dir { - @~"send" { send } - @~"recv" { recv } - _ { fail } + @~"send" => send, + @~"recv" => recv, + _ => fail }; let typarms = if self.token == token::LT { @@ -67,7 +65,7 @@ impl proto_parser of proto_parser for parser { self.expect(token::RARROW); let next = alt copy self.token { - token::IDENT(_, _) { + token::IDENT(_, _) => { let name = self.parse_ident(); let ntys = if self.token == token::LT { self.parse_unspanned_seq(token::LT, @@ -79,12 +77,12 @@ impl proto_parser of proto_parser for parser { else { ~[] }; some({state: name, tys: ntys}) } - token::NOT { + token::NOT => { // -> ! self.bump(); none } - _ { self.fatal(~"invalid next state") } + _ => self.fatal(~"invalid next state") }; state.add_message(mname, copy self.span, args, next); diff --git a/src/libsyntax/ext/pipes/pipec.rs b/src/libsyntax/ext/pipes/pipec.rs index 375ee81faa9..f61601a2aa0 100644 --- a/src/libsyntax/ext/pipes/pipec.rs +++ b/src/libsyntax/ext/pipes/pipec.rs @@ -48,7 +48,8 @@ impl compile of gen_send for message { fn gen_send(cx: ext_ctxt) -> @ast::item { debug!{"pipec: gen_send"}; alt self { - message(id, span, tys, this, some({state: next, tys: next_tys})) { + message(id, span, tys, this, + some({state: next, tys: next_tys})) => { debug!{"pipec: next state exists"}; let next = this.proto.get_state(next); assert next_tys.len() == next.ty_params.len(); @@ -71,10 +72,10 @@ impl compile of gen_send for message { if this.proto.is_bounded() { let (sp, rp) = alt (this.dir, next.dir) { - (send, send) { (~"c", ~"s") } - (send, recv) { (~"s", ~"c") } - (recv, send) { (~"s", ~"c") } - (recv, recv) { (~"c", ~"s") } + (send, send) => (~"c", ~"s"), + (send, recv) => (~"s", ~"c"), + (recv, send) => (~"s", ~"c"), + (recv, recv) => (~"c", ~"s") }; body += ~"let b = pipe.reuse_buffer();\n"; @@ -87,10 +88,10 @@ impl compile of gen_send for message { } else { let pat = alt (this.dir, next.dir) { - (send, send) { ~"(c, s)" } - (send, recv) { ~"(s, c)" } - (recv, send) { ~"(s, c)" } - (recv, recv) { ~"(c, s)" } + (send, send) => ~"(c, s)", + (send, recv) => ~"(s, c)", + (recv, send) => ~"(s, c)", + (recv, recv) => ~"(c, s)" }; body += fmt!{"let %s = pipes::entangle();\n", pat}; @@ -116,7 +117,7 @@ impl compile of gen_send for message { cx.expr_block(body)) } - message(id, span, tys, this, none) { + message(id, span, tys, this, none) => { debug!{"pipec: no next state"}; let arg_names = tys.mapi(|i, _ty| @(~"x_" + i.to_str())); @@ -181,20 +182,20 @@ impl compile of to_type_decls for state { let message(name, _span, tys, this, next) = m; let tys = alt next { - some({state: next, tys: next_tys}) { + some({state: next, tys: next_tys}) => { let next = this.proto.get_state(next); let next_name = next.data_name(); let dir = alt this.dir { - send { @~"server" } - recv { @~"client" } + send => @~"server", + recv => @~"client" }; vec::append_one(tys, cx.ty_path_ast_builder((dir + next_name) .add_tys(next_tys))) } - none { tys } + none => tys }; let v = cx.variant(name, tys); @@ -208,8 +209,8 @@ impl compile of to_type_decls for state { fn to_endpoint_decls(cx: ext_ctxt, dir: direction) -> ~[@ast::item] { debug!{"pipec: to_endpoint_decls"}; let dir = alt dir { - send { (*self).dir } - recv { (*self).dir.reverse() } + send => (*self).dir, + recv => (*self).dir.reverse() }; let mut items = ~[]; for self.messages.each |m| { @@ -255,8 +256,8 @@ impl compile of gen_init for protocol { let body = if !self.is_bounded() { alt start_state.dir { - send { #ast { pipes::entangle() } } - recv { + send => #ast { pipes::entangle() }, + recv => { #ast {{ let (s, c) = pipes::entangle(); (c, s) @@ -267,8 +268,8 @@ impl compile of gen_init for protocol { else { let body = self.gen_init_bounded(ext_cx); alt start_state.dir { - send { body } - recv { + send => body, + recv => { #ast {{ let (s, c) = $(body); (c, s) @@ -322,8 +323,8 @@ impl compile of gen_init for protocol { for (copy self.states).each |s| { for s.ty_params.each |tp| { alt params.find(|tpp| *tp.ident == *tpp.ident) { - none { vec::push(params, tp) } - _ { } + none => vec::push(params, tp), + _ => () } } } @@ -338,8 +339,8 @@ impl compile of gen_init for protocol { let fields = do (copy self.states).map_to_vec |s| { for s.ty_params.each |tp| { alt params.find(|tpp| *tp.ident == *tpp.ident) { - none { vec::push(params, tp) } - _ { } + none => vec::push(params, tp), + _ => () } } let ty = s.to_ty(cx); @@ -439,8 +440,8 @@ impl parse_utils of ext_ctxt_parse_utils for ext_ctxt { ~[], self.parse_sess()); alt res { - some(ast) { ast } - none { + some(ast) => ast, + none => { error!{"Parse error with ```\n%s\n```", s}; fail } diff --git a/src/libsyntax/ext/pipes/proto.rs b/src/libsyntax/ext/pipes/proto.rs index 1805fd9fa35..bd9ea96ee33 100644 --- a/src/libsyntax/ext/pipes/proto.rs +++ b/src/libsyntax/ext/pipes/proto.rs @@ -12,8 +12,8 @@ enum direction { impl of to_str for direction { fn to_str() -> ~str { alt self { - send { ~"send" } - recv { ~"recv" } + send => ~"send", + recv => ~"recv" } } } @@ -21,8 +21,8 @@ impl of to_str for direction { impl methods for direction { fn reverse() -> direction { alt self { - send { recv } - recv { send } + send => recv, + recv => send } } } @@ -37,26 +37,20 @@ enum message { impl methods for message { fn name() -> ident { alt self { - message(id, _, _, _, _) { - id - } + message(id, _, _, _, _) => id } } fn span() -> span { alt self { - message(_, span, _, _, _) { - span - } + message(_, span, _, _, _) => span } } /// Return the type parameters actually used by this message fn get_params() -> ~[ast::ty_param] { alt self { - message(_, _, _, this, _) { - this.ty_params - } + message(_, _, _, this, _) => this.ty_params } } } @@ -99,11 +93,11 @@ impl methods for state { fn reachable(f: fn(state) -> bool) { for self.messages.each |m| { alt m { - message(_, _, _, _, some({state: id, _})) { + message(_, _, _, _, some({state: id, _})) => { let state = self.proto.get_state(id); if !f(state) { break } } - _ { } + _ => () } } } diff --git a/src/libsyntax/ext/qquote.rs b/src/libsyntax/ext/qquote.rs index 87ecf93aa3c..21ba9599240 100644 --- a/src/libsyntax/ext/qquote.rs +++ b/src/libsyntax/ext/qquote.rs @@ -49,8 +49,8 @@ impl of qq_helper for @ast::expr { fn visit(cx: aq_ctxt, v: vt<aq_ctxt>) {visit_expr(self, cx, v);} fn extract_mac() -> option<ast::mac_> { alt (self.node) { - ast::expr_mac({node: mac, _}) {some(mac)} - _ {none} + ast::expr_mac({node: mac, _}) => some(mac), + _ => none } } fn mk_parse_fn(cx: ext_ctxt, sp: span) -> @ast::expr { @@ -64,8 +64,8 @@ impl of qq_helper for @ast::ty { fn visit(cx: aq_ctxt, v: vt<aq_ctxt>) {visit_ty(self, cx, v);} fn extract_mac() -> option<ast::mac_> { alt (self.node) { - ast::ty_mac({node: mac, _}) {some(mac)} - _ {none} + ast::ty_mac({node: mac, _}) => some(mac), + _ => none } } fn mk_parse_fn(cx: ext_ctxt, sp: span) -> @ast::expr { @@ -125,14 +125,14 @@ fn gather_anti_quotes<N: qq_helper>(lo: uint, node: N) -> aq_ctxt fn visit_aq<T:qq_helper>(node: T, constr: ~str, &&cx: aq_ctxt, v: vt<aq_ctxt>) { alt (node.extract_mac()) { - some(mac_aq(sp, e)) { + some(mac_aq(sp, e)) => { cx.gather.push(gather_item { lo: sp.lo - cx.lo, hi: sp.hi - cx.lo, e: e, constr: constr}); } - _ {node.visit(cx, v);} + _ => node.visit(cx, v) } } @@ -148,8 +148,8 @@ fn expand_ast(ecx: ext_ctxt, _sp: span, do option::iter(arg) |arg| { let args: ~[@ast::expr] = alt arg.node { - ast::expr_vec(elts, _) { elts } - _ { + ast::expr_vec(elts, _) => elts, + _ => { ecx.span_fatal (_sp, ~"#ast requires arguments of the form `~[...]`.") } @@ -159,20 +159,20 @@ fn expand_ast(ecx: ext_ctxt, _sp: span, } alt (args[0].node) { ast::expr_path(@{idents: id, _}) if vec::len(id) == 1u - {what = *id[0]} - _ {ecx.span_fatal(args[0].span, ~"expected an identifier");} + => what = *id[0], + _ => ecx.span_fatal(args[0].span, ~"expected an identifier") } } let body = get_mac_body(ecx,_sp,body); return alt what { - ~"crate" {finish(ecx, body, parse_crate)} - ~"expr" {finish(ecx, body, parse_expr)} - ~"ty" {finish(ecx, body, parse_ty)} - ~"item" {finish(ecx, body, parse_item)} - ~"stmt" {finish(ecx, body, parse_stmt)} - ~"pat" {finish(ecx, body, parse_pat)} - _ {ecx.span_fatal(_sp, ~"unsupported ast type")} + ~"crate" => finish(ecx, body, parse_crate), + ~"expr" => finish(ecx, body, parse_expr), + ~"ty" => finish(ecx, body, parse_ty), + ~"item" => finish(ecx, body, parse_item), + ~"stmt" => finish(ecx, body, parse_stmt), + ~"pat" => finish(ecx, body, parse_pat), + _ => ecx.span_fatal(_sp, ~"unsupported ast type") }; } @@ -184,8 +184,8 @@ fn parse_pat(p: parser) -> @ast::pat { p.parse_pat(true) } fn parse_item(p: parser) -> @ast::item { alt p.parse_item(~[]) { - some(item) { item } - none { fail ~"parse_item: parsing an item failed"; } + some(item) => item, + none => fail ~"parse_item: parsing an item failed" } } @@ -226,11 +226,11 @@ fn finish<T: qq_helper> str2 += repl; } alt copy state { - active {str::push_char(str2, ch);} - skip(1u) {state = blank;} - skip(sk) {state = skip (sk-1u);} - blank if is_space(ch) {str::push_char(str2, ch);} - blank {str::push_char(str2, ' ');} + active => str::push_char(str2, ch), + skip(1u) => state = blank, + skip(sk) => state = skip (sk-1u), + blank if is_space(ch) => str::push_char(str2, ch), + blank => str::push_char(str2, ' ') } i += 1u; if (j < g_len && i == cx.gather[j].hi) { @@ -309,11 +309,11 @@ fn replace_expr(repls: ~[fragment], -> (ast::expr_, span) { alt e { - ast::expr_mac({node: mac_var(i), _}) { - alt (repls[i]) { - from_expr(r) {(r.node, r.span)} - _ {fail /* fixme error message */}}} - _ {orig(e,s,fld)} + ast::expr_mac({node: mac_var(i), _}) => alt (repls[i]) { + from_expr(r) => (r.node, r.span), + _ => fail /* fixme error message */ + } + _ => orig(e,s,fld) } } @@ -323,11 +323,11 @@ fn replace_ty(repls: ~[fragment], -> (ast::ty_, span) { alt e { - ast::ty_mac({node: mac_var(i), _}) { - alt (repls[i]) { - from_ty(r) {(r.node, r.span)} - _ {fail /* fixme error message */}}} - _ {orig(e,s,fld)} + ast::ty_mac({node: mac_var(i), _}) => alt (repls[i]) { + from_ty(r) => (r.node, r.span), + _ => fail /* fixme error message */ + } + _ => orig(e,s,fld) } } diff --git a/src/libsyntax/ext/simplext.rs b/src/libsyntax/ext/simplext.rs index b835300d5c7..79b609113ab 100644 --- a/src/libsyntax/ext/simplext.rs +++ b/src/libsyntax/ext/simplext.rs @@ -37,27 +37,17 @@ enum matchable { /* for when given an incompatible bit of AST */ fn match_error(cx: ext_ctxt, m: matchable, expected: ~str) -> ! { alt m { - match_expr(x) { - cx.span_fatal(x.span, - ~"this argument is an expr, expected " + expected); - } - match_path(x) { - cx.span_fatal(x.span, - ~"this argument is a path, expected " + expected); - } - match_ident(x) { - cx.span_fatal(x.span, - ~"this argument is an ident, expected " + expected); - } - match_ty(x) { - cx.span_fatal(x.span, - ~"this argument is a type, expected " + expected); - } - match_block(x) { - cx.span_fatal(x.span, - ~"this argument is a block, expected " + expected); - } - match_exact { cx.bug(~"what is a match_exact doing in a bindings?"); } + match_expr(x) => cx.span_fatal( + x.span, ~"this argument is an expr, expected " + expected), + match_path(x) => cx.span_fatal( + x.span, ~"this argument is a path, expected " + expected), + match_ident(x) => cx.span_fatal( + x.span, ~"this argument is an ident, expected " + expected), + match_ty(x) => cx.span_fatal( + x.span, ~"this argument is a type, expected " + expected), + match_block(x) => cx.span_fatal( + x.span, ~"this argument is a block, expected " + expected), + match_exact => cx.bug(~"what is a match_exact doing in a bindings?") } } @@ -76,9 +66,8 @@ fn elts_to_ell(cx: ext_ctxt, elts: ~[@expr]) -> let mut res = none; for elts.each |elt| { alt elt.node { - expr_mac(m) { - alt m.node { - ast::mac_ellipsis { + expr_mac(m) => alt m.node { + ast::mac_ellipsis => { if res != none { cx.span_fatal(m.span, ~"only one ellipsis allowed"); } @@ -86,37 +75,37 @@ fn elts_to_ell(cx: ext_ctxt, elts: ~[@expr]) -> some({pre: vec::slice(elts, 0u, idx - 1u), rep: some(elts[idx - 1u]), post: vec::slice(elts, idx + 1u, vec::len(elts))}); - } - _ { } } + _ => () } - _ { } + _ => () } idx += 1u; } return alt res { - some(val) { val } - none { {pre: elts, rep: none, post: ~[]} } - } + some(val) => val, + none => {pre: elts, rep: none, post: ~[]} + } } fn option_flatten_map<T: copy, U: copy>(f: fn@(T) -> option<U>, v: ~[T]) -> option<~[U]> { let mut res = ~[]; for v.each |elem| { - alt f(elem) { none { return none; } some(fv) { vec::push(res, fv); } } + alt f(elem) { + none => return none, + some(fv) => vec::push(res, fv) + } } return some(res); } fn a_d_map(ad: arb_depth<matchable>, f: selector) -> match_result { alt ad { - leaf(x) { return f(x); } - seq(ads, span) { - alt option_flatten_map(|x| a_d_map(x, f), *ads) { - none { return none; } - some(ts) { return some(seq(@ts, span)); } - } + leaf(x) => return f(x), + seq(ads, span) => alt option_flatten_map(|x| a_d_map(x, f), *ads) { + none => return none, + some(ts) => return some(seq(@ts, span)) } } } @@ -124,8 +113,8 @@ fn a_d_map(ad: arb_depth<matchable>, f: selector) -> match_result { fn compose_sels(s1: selector, s2: selector) -> selector { fn scomp(s1: selector, s2: selector, m: matchable) -> match_result { return alt s1(m) { - none { none } - some(matches) { a_d_map(matches, s2) } + none => none, + some(matches) => a_d_map(matches, s2) } } return { |x| scomp(s1, s2, x) }; @@ -167,13 +156,13 @@ fn use_selectors_to_bind(b: binders, e: @expr) -> option<bindings> { let res = box_str_hash::<arb_depth<matchable>>(); //need to do this first, to check vec lengths. for b.literal_ast_matchers.each |sel| { - alt sel(match_expr(e)) { none { return none; } _ { } } + alt sel(match_expr(e)) { none => return none, _ => () } } let mut never_mind: bool = false; for b.real_binders.each |key, val| { alt val(match_expr(e)) { - none { never_mind = true; } - some(mtc) { res.insert(key, mtc); } + none => never_mind = true, + some(mtc) => { res.insert(key, mtc); } } }; //HACK: `ret` doesn't work in `for each` @@ -221,8 +210,8 @@ fn follow(m: arb_depth<matchable>, idx_path: @mut ~[uint]) -> let mut res: arb_depth<matchable> = m; for vec::each(*idx_path) |idx| { res = alt res { - leaf(_) { return res;/* end of the line */ } - seq(new_ms, _) { new_ms[idx] } + leaf(_) => return res,/* end of the line */ + seq(new_ms, _) => new_ms[idx] } } return res; @@ -231,15 +220,15 @@ fn follow(m: arb_depth<matchable>, idx_path: @mut ~[uint]) -> fn follow_for_trans(cx: ext_ctxt, mmaybe: option<arb_depth<matchable>>, idx_path: @mut ~[uint]) -> option<matchable> { alt mmaybe { - none { return none } - some(m) { + none => return none, + some(m) => { return alt follow(m, idx_path) { - seq(_, sp) { + seq(_, sp) => { cx.span_fatal(sp, ~"syntax matched under ... but not " + ~"used that way.") } - leaf(m) { return some(m) } + leaf(m) => return some(m) } } } @@ -270,24 +259,24 @@ fn transcribe_exprs(cx: ext_ctxt, b: bindings, idx_path: @mut ~[uint], recur: fn@(&&@expr) -> @expr, exprs: ~[@expr]) -> ~[@expr] { alt elts_to_ell(cx, exprs) { - {pre: pre, rep: repeat_me_maybe, post: post} { + {pre: pre, rep: repeat_me_maybe, post: post} => { let mut res = vec::map(pre, recur); alt repeat_me_maybe { - none { } - some(repeat_me) { + none => (), + some(repeat_me) => { let mut repeat: option<{rep_count: uint, name: ident}> = none; /* we need to walk over all the free vars in lockstep, except for the leaves, which are just duplicated */ do free_vars(b, repeat_me) |fv| { let cur_pos = follow(b.get(fv), idx_path); alt cur_pos { - leaf(_) { } - seq(ms, _) { + leaf(_) => (), + seq(ms, _) => { alt repeat { - none { + none => { repeat = some({rep_count: vec::len(*ms), name: fv}); } - some({rep_count: old_len, name: old_name}) { + some({rep_count: old_len, name: old_name}) => { let len = vec::len(*ms); if old_len != len { let msg = @@ -302,12 +291,12 @@ fn transcribe_exprs(cx: ext_ctxt, b: bindings, idx_path: @mut ~[uint], } }; alt repeat { - none { + none => { cx.span_fatal(repeat_me.span, ~"'...' surrounds an expression without any" + ~" repeating syntax variables"); } - some({rep_count: rc, _}) { + some({rep_count: rc, _}) => { /* Whew, we now know how how many times to repeat */ let mut idx: uint = 0u; while idx < rc { @@ -332,9 +321,9 @@ fn transcribe_exprs(cx: ext_ctxt, b: bindings, idx_path: @mut ~[uint], fn transcribe_ident(cx: ext_ctxt, b: bindings, idx_path: @mut ~[uint], &&i: ident, _fld: ast_fold) -> ident { return alt follow_for_trans(cx, b.find(i), idx_path) { - some(match_ident(a_id)) { a_id.node } - some(m) { match_error(cx, m, ~"an identifier") } - none { i } + some(match_ident(a_id)) => a_id.node, + some(m) => match_error(cx, m, ~"an identifier"), + none => i } } @@ -344,13 +333,13 @@ fn transcribe_path(cx: ext_ctxt, b: bindings, idx_path: @mut ~[uint], // Don't substitute into qualified names. if vec::len(p.types) > 0u || vec::len(p.idents) != 1u { return p; } alt follow_for_trans(cx, b.find(p.idents[0]), idx_path) { - some(match_ident(id)) { + some(match_ident(id)) => { {span: id.span, global: false, idents: ~[id.node], rp: none, types: ~[]} } - some(match_path(a_pth)) { *a_pth } - some(m) { match_error(cx, m, ~"a path") } - none { p } + some(match_path(a_pth)) => *a_pth, + some(m) => match_error(cx, m, ~"a path"), + none => p } } @@ -361,26 +350,26 @@ fn transcribe_expr(cx: ext_ctxt, b: bindings, idx_path: @mut ~[uint], -> (ast::expr_, span) { return alt e { - expr_path(p) { + expr_path(p) => { // Don't substitute into qualified names. if vec::len(p.types) > 0u || vec::len(p.idents) != 1u { (e, s); } alt follow_for_trans(cx, b.find(p.idents[0]), idx_path) { - some(match_ident(id)) { + some(match_ident(id)) => { (expr_path(@{span: id.span, global: false, idents: ~[id.node], rp: none, types: ~[]}), id.span) } - some(match_path(a_pth)) { (expr_path(a_pth), s) } - some(match_expr(a_exp)) { (a_exp.node, a_exp.span) } - some(m) { match_error(cx, m, ~"an expression") } - none { orig(e, s, fld) } + some(match_path(a_pth)) => (expr_path(a_pth), s), + some(match_expr(a_exp)) => (a_exp.node, a_exp.span), + some(m) => match_error(cx, m, ~"an expression"), + none => orig(e, s, fld) } } - _ { orig(e, s, fld) } + _ => orig(e, s, fld) } } @@ -390,19 +379,19 @@ fn transcribe_type(cx: ext_ctxt, b: bindings, idx_path: @mut ~[uint], -> (ast::ty_, span) { return alt t { - ast::ty_path(pth, _) { + ast::ty_path(pth, _) => { alt path_to_ident(pth) { - some(id) { + some(id) => { alt follow_for_trans(cx, b.find(id), idx_path) { - some(match_ty(ty)) { (ty.node, ty.span) } - some(m) { match_error(cx, m, ~"a type") } - none { orig(t, s, fld) } + some(match_ty(ty)) => (ty.node, ty.span), + some(m) => match_error(cx, m, ~"a type"), + none => orig(t, s, fld) } } - none { orig(t, s, fld) } + none => orig(t, s, fld) } } - _ { orig(t, s, fld) } + _ => orig(t, s, fld) } } @@ -416,22 +405,16 @@ fn transcribe_block(cx: ext_ctxt, b: bindings, idx_path: @mut ~[uint], -> (blk_, span) { return alt block_to_ident(blk) { - some(id) { + some(id) => { alt follow_for_trans(cx, b.find(id), idx_path) { - some(match_block(new_blk)) { (new_blk.node, new_blk.span) } - - - - + some(match_block(new_blk)) => (new_blk.node, new_blk.span), // possibly allow promotion of ident/path/expr to blocks? - some(m) { - match_error(cx, m, ~"a block") - } - none { orig(blk, s, fld) } + some(m) => match_error(cx, m, ~"a block"), + none => orig(blk, s, fld) } } - none { orig(blk, s, fld) } + none => orig(blk, s, fld) } } @@ -442,12 +425,12 @@ fn p_t_s_rec(cx: ext_ctxt, m: matchable, s: selector, b: binders) { //it might be possible to traverse only exprs, not matchables alt m { - match_expr(e) { + match_expr(e) => { alt e.node { - expr_path(p_pth) { p_t_s_r_path(cx, p_pth, s, b); } - expr_vec(p_elts, _) { + expr_path(p_pth) => p_t_s_r_path(cx, p_pth, s, b), + expr_vec(p_elts, _) => { alt elts_to_ell(cx, p_elts) { - {pre: pre, rep: some(repeat_me), post: post} { + {pre: pre, rep: some(repeat_me), post: post} => { p_t_s_r_length(cx, vec::len(pre) + vec::len(post), true, s, b); if vec::len(pre) > 0u { @@ -460,7 +443,7 @@ fn p_t_s_rec(cx: ext_ctxt, m: matchable, s: selector, b: binders) { ~"matching after `...` not yet supported"); } } - {pre: pre, rep: none, post: post} { + {pre: pre, rep: none, post: post} => { if post != ~[] { cx.bug(~"elts_to_ell provided an invalid result"); } @@ -470,26 +453,24 @@ fn p_t_s_rec(cx: ext_ctxt, m: matchable, s: selector, b: binders) { } } /* FIXME (#2251): handle embedded types and blocks, at least */ - expr_mac(mac) { + expr_mac(mac) => { p_t_s_r_mac(cx, mac, s, b); } - _ { + _ => { fn select(cx: ext_ctxt, m: matchable, pat: @expr) -> match_result { return alt m { - match_expr(e) { + match_expr(e) => { if e == pat { some(leaf(match_exact)) } else { none } } - _ { cx.bug(~"broken traversal in p_t_s_r") } + _ => cx.bug(~"broken traversal in p_t_s_r") } } b.literal_ast_matchers.push(|x| select(cx, x, e)); } } } - _ { - cx.bug(~"undocumented invariant in p_t_s_rec"); - } + _ => cx.bug(~"undocumented invariant in p_t_s_rec") } } @@ -497,29 +478,29 @@ fn p_t_s_rec(cx: ext_ctxt, m: matchable, s: selector, b: binders) { /* make a match more precise */ fn specialize_match(m: matchable) -> matchable { return alt m { - match_expr(e) { + match_expr(e) => { alt e.node { - expr_path(pth) { + expr_path(pth) => { alt path_to_ident(pth) { - some(id) { match_ident(respan(pth.span, id)) } - none { match_path(pth) } + some(id) => match_ident(respan(pth.span, id)), + none => match_path(pth) } } - _ { m } + _ => m } } - _ { m } + _ => m } } /* pattern_to_selectors helper functions */ fn p_t_s_r_path(cx: ext_ctxt, p: @path, s: selector, b: binders) { alt path_to_ident(p) { - some(p_id) { + some(p_id) => { fn select(cx: ext_ctxt, m: matchable) -> match_result { return alt m { - match_expr(e) { some(leaf(specialize_match(m))) } - _ { cx.bug(~"broken traversal in p_t_s_r") } + match_expr(e) => some(leaf(specialize_match(m))), + _ => cx.bug(~"broken traversal in p_t_s_r") } } if b.real_binders.contains_key(p_id) { @@ -527,17 +508,18 @@ fn p_t_s_r_path(cx: ext_ctxt, p: @path, s: selector, b: binders) { } b.real_binders.insert(p_id, compose_sels(s, |x| select(cx, x))); } - none { } + none => () } } fn block_to_ident(blk: blk_) -> option<ident> { if vec::len(blk.stmts) != 0u { return none; } return alt blk.expr { - some(expr) { - alt expr.node { expr_path(pth) { path_to_ident(pth) } _ { none } } + some(expr) => alt expr.node { + expr_path(pth) => path_to_ident(pth), + _ => none } - none { none } + none => none } } @@ -545,21 +527,22 @@ fn p_t_s_r_mac(cx: ext_ctxt, mac: ast::mac, _s: selector, _b: binders) { fn select_pt_1(cx: ext_ctxt, m: matchable, fn_m: fn(ast::mac) -> match_result) -> match_result { return alt m { - match_expr(e) { - alt e.node { expr_mac(mac) { fn_m(mac) } _ { none } } + match_expr(e) => alt e.node { + expr_mac(mac) => fn_m(mac), + _ => none } - _ { cx.bug(~"broken traversal in p_t_s_r") } + _ => cx.bug(~"broken traversal in p_t_s_r") } } fn no_des(cx: ext_ctxt, sp: span, syn: ~str) -> ! { cx.span_fatal(sp, ~"destructuring " + syn + ~" is not yet supported"); } alt mac.node { - ast::mac_ellipsis { cx.span_fatal(mac.span, ~"misused `...`"); } - ast::mac_invoc(_, _, _) { no_des(cx, mac.span, ~"macro calls"); } - ast::mac_invoc_tt(_, _) { no_des(cx, mac.span, ~"macro calls"); } - ast::mac_aq(_,_) { no_des(cx, mac.span, ~"antiquotes"); } - ast::mac_var(_) { no_des(cx, mac.span, ~"antiquote variables"); } + ast::mac_ellipsis => cx.span_fatal(mac.span, ~"misused `...`"), + ast::mac_invoc(_, _, _) => no_des(cx, mac.span, ~"macro calls"), + ast::mac_invoc_tt(_, _) => no_des(cx, mac.span, ~"macro calls"), + ast::mac_aq(_,_) => no_des(cx, mac.span, ~"antiquotes"), + ast::mac_var(_) => no_des(cx, mac.span, ~"antiquote variables") } } @@ -568,9 +551,9 @@ fn p_t_s_r_ellipses(cx: ext_ctxt, repeat_me: @expr, offset: uint, s: selector, fn select(cx: ext_ctxt, repeat_me: @expr, offset: uint, m: matchable) -> match_result { return alt m { - match_expr(e) { + match_expr(e) => { alt e.node { - expr_vec(arg_elts, _) { + expr_vec(arg_elts, _) => { let mut elts = ~[]; let mut idx = offset; while idx < vec::len(arg_elts) { @@ -582,10 +565,10 @@ fn p_t_s_r_ellipses(cx: ext_ctxt, repeat_me: @expr, offset: uint, s: selector, // error we want to report is one in the macro def some(seq(@elts, repeat_me.span)) } - _ { none } + _ => none } } - _ { cx.bug(~"broken traversal in p_t_s_r") } + _ => cx.bug(~"broken traversal in p_t_s_r") } } p_t_s_rec(cx, match_expr(repeat_me), @@ -598,18 +581,18 @@ fn p_t_s_r_length(cx: ext_ctxt, len: uint, at_least: bool, s: selector, fn len_select(_cx: ext_ctxt, m: matchable, at_least: bool, len: uint) -> match_result { return alt m { - match_expr(e) { + match_expr(e) => { alt e.node { - expr_vec(arg_elts, _) { + expr_vec(arg_elts, _) => { let actual_len = vec::len(arg_elts); if at_least && actual_len >= len || actual_len == len { some(leaf(match_exact)) } else { none } } - _ { none } + _ => none } } - _ { none } + _ => none } } b.literal_ast_matchers.push( @@ -622,15 +605,15 @@ fn p_t_s_r_actual_vector(cx: ext_ctxt, elts: ~[@expr], _repeat_after: bool, while idx < vec::len(elts) { fn select(cx: ext_ctxt, m: matchable, idx: uint) -> match_result { return alt m { - match_expr(e) { + match_expr(e) => { alt e.node { - expr_vec(arg_elts, _) { + expr_vec(arg_elts, _) => { some(leaf(match_expr(arg_elts[idx]))) } - _ { none } + _ => none } } - _ { cx.bug(~"broken traversal in p_t_s_r") } + _ => cx.bug(~"broken traversal in p_t_s_r") } } p_t_s_rec(cx, match_expr(elts[idx]), @@ -647,7 +630,7 @@ fn add_new_extension(cx: ext_ctxt, sp: span, arg: ast::mac_arg, let mut clauses: ~[@clause] = ~[]; for args.each |arg| { alt arg.node { - expr_vec(elts, mutbl) { + expr_vec(elts, mutbl) => { if vec::len(elts) != 2u { cx.span_fatal((*arg).span, ~"extension clause must consist of ~[" + @@ -656,31 +639,25 @@ fn add_new_extension(cx: ext_ctxt, sp: span, arg: ast::mac_arg, alt elts[0u].node { - expr_mac(mac) { + expr_mac(mac) => { alt mac.node { - mac_invoc(pth, invoc_arg, body) { + mac_invoc(pth, invoc_arg, body) => { alt path_to_ident(pth) { - some(id) { - alt macro_name { - none { macro_name = some(id); } - some(other_id) { - if id != other_id { - cx.span_fatal(pth.span, - ~"macro name must be " + - ~"consistent"); - } - } + some(id) => alt macro_name { + none => macro_name = some(id), + some(other_id) => if id != other_id { + cx.span_fatal(pth.span, + ~"macro name must be " + + ~"consistent"); } } - none { - cx.span_fatal(pth.span, - ~"macro name must not be a path"); - } + none => cx.span_fatal(pth.span, + ~"macro name must not be a path") } let arg = alt invoc_arg { - some(arg) { arg } - none { cx.span_fatal(mac.span, - ~"macro must have arguments")} + some(arg) => arg, + none => cx.span_fatal(mac.span, + ~"macro must have arguments") }; vec::push(clauses, @{params: pattern_to_selectors(cx, arg), @@ -689,20 +666,20 @@ fn add_new_extension(cx: ext_ctxt, sp: span, arg: ast::mac_arg, // FIXME (#2251): check duplicates (or just simplify // the macro arg situation) } - _ { + _ => { cx.span_bug(mac.span, ~"undocumented invariant in \ add_extension"); } } } - _ { + _ => { cx.span_fatal(elts[0u].span, ~"extension clause must" + ~" start with a macro invocation."); } } } - _ { + _ => { cx.span_fatal((*arg).span, ~"extension must be ~[clause, " + ~" ...]"); } @@ -713,11 +690,9 @@ fn add_new_extension(cx: ext_ctxt, sp: span, arg: ast::mac_arg, return {ident: alt macro_name { - some(id) { id } - none { - cx.span_fatal(sp, ~"macro definition must have " + - ~"at least one clause") - } + some(id) => id, + none => cx.span_fatal(sp, ~"macro definition must have " + + ~"at least one clause") }, ext: normal({expander: ext, span: some(option::get(arg).span)})}; @@ -725,13 +700,13 @@ fn add_new_extension(cx: ext_ctxt, sp: span, arg: ast::mac_arg, _body: ast::mac_body, clauses: ~[@clause]) -> @expr { let arg = alt arg { - some(arg) { arg } - none { cx.span_fatal(sp, ~"macro must have arguments")} + some(arg) => arg, + none => cx.span_fatal(sp, ~"macro must have arguments") }; for clauses.each |c| { alt use_selectors_to_bind(c.params, arg) { - some(bindings) { return transcribe(cx, bindings, c.body); } - none { again; } + some(bindings) => return transcribe(cx, bindings, c.body), + none => again } } cx.span_fatal(sp, ~"no clauses match macro invocation"); diff --git a/src/libsyntax/ext/source_util.rs b/src/libsyntax/ext/source_util.rs index 00c1e4ff47a..c55f1e67be2 100644 --- a/src/libsyntax/ext/source_util.rs +++ b/src/libsyntax/ext/source_util.rs @@ -71,8 +71,8 @@ fn expand_include_str(cx: ext_ctxt, sp: codemap::span, arg: ast::mac_arg, let res = io::read_whole_file_str(res_rel_file(cx, sp, file)); alt res { - result::ok(_) { /* Continue. */ } - result::err(e) { + result::ok(_) => { /* Continue. */ } + result::err(e) => { cx.parse_sess().span_diagnostic.handler().fatal(e); } } @@ -87,13 +87,13 @@ fn expand_include_bin(cx: ext_ctxt, sp: codemap::span, arg: ast::mac_arg, let file = expr_to_str(cx, args[0], ~"#include_bin requires a string"); alt io::read_whole_file(res_rel_file(cx, sp, file)) { - result::ok(src) { + result::ok(src) => { let u8_exprs = vec::map(src, |char: u8| { mk_u8(cx, sp, char) }); return mk_uniq_vec_e(cx, sp, u8_exprs); } - result::err(e) { + result::err(e) => { cx.parse_sess().span_diagnostic.handler().fatal(e) } } diff --git a/src/libsyntax/ext/tt/earley_parser.rs b/src/libsyntax/ext/tt/earley_parser.rs index dd29ce04eeb..6a801f33aa6 100644 --- a/src/libsyntax/ext/tt/earley_parser.rs +++ b/src/libsyntax/ext/tt/earley_parser.rs @@ -32,8 +32,8 @@ enum matcher_pos_up { /* to break a circularity */ fn is_some(&&mpu: matcher_pos_up) -> bool { alt mpu { - matcher_pos_up(none) { false } - _ { true } + matcher_pos_up(none) => false, + _ => true } } @@ -49,17 +49,17 @@ type matcher_pos = ~{ fn copy_up(&& mpu: matcher_pos_up) -> matcher_pos { alt mpu { - matcher_pos_up(some(mp)) { copy mp } - _ { fail } + matcher_pos_up(some(mp)) => copy mp, + _ => fail } } fn count_names(ms: &[matcher]) -> uint { vec::foldl(0u, ms, |ct, m| { ct + alt m.node { - match_tok(_) { 0u } - match_seq(more_ms, _, _, _, _) { count_names(more_ms) } - match_nonterminal(_,_,_) { 1u } + match_tok(_) => 0u, + match_seq(more_ms, _, _, _, _) => count_names(more_ms), + match_nonterminal(_,_,_) => 1u }}) } @@ -69,11 +69,11 @@ fn initial_matcher_pos(ms: ~[matcher], sep: option<token>, lo: uint) let mut match_idx_hi = 0u; for ms.each() |elt| { alt elt.node { - match_tok(_) {} - match_seq(_,_,_,_,hi) { + match_tok(_) => (), + match_seq(_,_,_,_,hi) => { match_idx_hi = hi; // it is monotonic... } - match_nonterminal(_,_,pos) { + match_nonterminal(_,_,pos) => { match_idx_hi = pos+1u; // ...so latest is highest } } @@ -114,11 +114,11 @@ fn nameize(p_s: parse_sess, ms: ~[matcher], res: ~[@named_match]) fn n_rec(p_s: parse_sess, m: matcher, res: ~[@named_match], ret_val: hashmap<ident, @named_match>) { alt m { - {node: match_tok(_), span: _} { } - {node: match_seq(more_ms, _, _, _, _), span: _} { + {node: match_tok(_), span: _} => (), + {node: match_seq(more_ms, _, _, _, _), span: _} => { for more_ms.each() |next_m| { n_rec(p_s, next_m, res, ret_val) }; } - {node: match_nonterminal(bind_name, _, idx), span: sp} { + {node: match_nonterminal(bind_name, _, idx), span: sp} => { if ret_val.contains_key(bind_name) { p_s.span_diagnostic.span_fatal(sp, ~"Duplicated bind name: " + *bind_name) @@ -140,10 +140,8 @@ enum parse_result { fn parse_or_else(sess: parse_sess, cfg: ast::crate_cfg, rdr: reader, ms: ~[matcher]) -> hashmap<ident, @named_match> { alt parse(sess, cfg, rdr, ms) { - success(m) { m } - failure(sp, str) { - sess.span_diagnostic.span_fatal(sp, str); - } + success(m) => m, + failure(sp, str) => sess.span_diagnostic.span_fatal(sp, str) } } @@ -205,14 +203,14 @@ fn parse(sess: parse_sess, cfg: ast::crate_cfg, rdr: reader, ms: ~[matcher]) // the *_t vars are workarounds for the lack of unary move alt copy ei.sep { - some(t) if idx == len { // we need a separator + some(t) if idx == len => { // we need a separator if tok == t { //pass the separator let ei_t <- ei; ei_t.idx += 1u; vec::push(next_eis, ei_t); } } - _ { // we don't need a separator + _ => { // we don't need a separator let ei_t <- ei; ei_t.idx = 0u; vec::push(cur_eis, ei_t); @@ -225,7 +223,7 @@ fn parse(sess: parse_sess, cfg: ast::crate_cfg, rdr: reader, ms: ~[matcher]) alt copy ei.elts[idx].node { /* need to descend into sequence */ match_seq(matchers, sep, zero_ok, - match_idx_lo, match_idx_hi){ + match_idx_lo, match_idx_hi) => { if zero_ok { let new_ei = copy ei; new_ei.idx += 1u; @@ -248,8 +246,8 @@ fn parse(sess: parse_sess, cfg: ast::crate_cfg, rdr: reader, ms: ~[matcher]) sp_lo: sp.lo }); } - match_nonterminal(_,_,_) { vec::push(bb_eis, ei) } - match_tok(t) { + match_nonterminal(_,_,_) => { vec::push(bb_eis, ei) } + match_tok(t) => { let ei_t <- ei; if t == tok { ei_t.idx += 1u; vec::push(next_eis, ei_t)} } @@ -273,10 +271,11 @@ fn parse(sess: parse_sess, cfg: ast::crate_cfg, rdr: reader, ms: ~[matcher]) || bb_eis.len() > 1u { let nts = str::connect(vec::map(bb_eis, |ei| { alt ei.elts[ei.idx].node { - match_nonterminal(bind,name,_) { + match_nonterminal(bind,name,_) => { fmt!{"%s ('%s')", *name, *bind} } - _ { fail; } } }), ~" or "); + _ => fail + } }), ~" or "); return failure(sp, fmt!{ "Local ambiguity: multiple parsing options: \ built-in NTs %s or %u other options.", @@ -295,12 +294,12 @@ fn parse(sess: parse_sess, cfg: ast::crate_cfg, rdr: reader, ms: ~[matcher]) let ei = vec::pop(bb_eis); alt ei.elts[ei.idx].node { - match_nonterminal(_, name, idx) { + match_nonterminal(_, name, idx) => { ei.matches[idx].push(@matched_nonterminal( parse_nt(rust_parser, *name))); ei.idx += 1u; } - _ { fail; } + _ => fail } vec::push(cur_eis,ei); @@ -320,30 +319,30 @@ fn parse(sess: parse_sess, cfg: ast::crate_cfg, rdr: reader, ms: ~[matcher]) fn parse_nt(p: parser, name: ~str) -> nonterminal { alt name { - ~"item" { alt p.parse_item(~[]) { - some(i) { token::nt_item(i) } - none { p.fatal(~"expected an item keyword") } - }} - ~"block" { token::nt_block(p.parse_block()) } - ~"stmt" { token::nt_stmt(p.parse_stmt(~[])) } - ~"pat" { token::nt_pat(p.parse_pat(true)) } - ~"expr" { token::nt_expr(p.parse_expr()) } - ~"ty" { token::nt_ty(p.parse_ty(false /* no need to disambiguate*/)) } + ~"item" => alt p.parse_item(~[]) { + some(i) => token::nt_item(i), + none => p.fatal(~"expected an item keyword") + } + ~"block" => token::nt_block(p.parse_block()), + ~"stmt" => token::nt_stmt(p.parse_stmt(~[])), + ~"pat" => token::nt_pat(p.parse_pat(true)), + ~"expr" => token::nt_expr(p.parse_expr()), + ~"ty" => token::nt_ty(p.parse_ty(false /* no need to disambiguate*/)), // this could be handled like a token, since it is one - ~"ident" { alt copy p.token { - token::IDENT(sn,b) { p.bump(); token::nt_ident(sn,b) } - _ { p.fatal(~"expected ident, found " - + token::to_str(*p.reader.interner(), copy p.token)) } - } } - ~"path" { token::nt_path(p.parse_path_with_tps(false)) } - ~"tt" { + ~"ident" => alt copy p.token { + token::IDENT(sn,b) => { p.bump(); token::nt_ident(sn,b) } + _ => p.fatal(~"expected ident, found " + + token::to_str(*p.reader.interner(), copy p.token)) + } + ~"path" => token::nt_path(p.parse_path_with_tps(false)), + ~"tt" => { p.quote_depth += 1u; //but in theory, non-quoted tts might be useful let res = token::nt_tt(@p.parse_token_tree()); p.quote_depth -= 1u; res } - ~"matchers" { token::nt_matchers(p.parse_matchers()) } - _ { p.fatal(~"Unsupported builtin nonterminal parser: " + name)} + ~"matchers" => token::nt_matchers(p.parse_matchers()), + _ => p.fatal(~"Unsupported builtin nonterminal parser: " + name) } } diff --git a/src/libsyntax/ext/tt/macro_rules.rs b/src/libsyntax/ext/tt/macro_rules.rs index 28bf79be0d5..7655d7c970c 100644 --- a/src/libsyntax/ext/tt/macro_rules.rs +++ b/src/libsyntax/ext/tt/macro_rules.rs @@ -38,12 +38,12 @@ fn add_new_extension(cx: ext_ctxt, sp: span, name: ident, // Extract the arguments: let lhses:~[@named_match] = alt argument_map.get(@~"lhs") { - @matched_seq(s, sp) { s } - _ { cx.span_bug(sp, ~"wrong-structured lhs") } + @matched_seq(s, sp) => s, + _ => cx.span_bug(sp, ~"wrong-structured lhs") }; let rhses:~[@named_match] = alt argument_map.get(@~"rhs") { - @matched_seq(s, sp) { s } - _ { cx.span_bug(sp, ~"wrong-structured rhs") } + @matched_seq(s, sp) => s, + _ => cx.span_bug(sp, ~"wrong-structured rhs") }; // Given `lhses` and `rhses`, this is the new macro we create @@ -59,14 +59,14 @@ fn add_new_extension(cx: ext_ctxt, sp: span, name: ident, for lhses.eachi() |i, lhs| { // try each arm's matchers alt lhs { - @matched_nonterminal(nt_matchers(mtcs)) { + @matched_nonterminal(nt_matchers(mtcs)) => { // `none` is because we're not interpolating let arg_rdr = new_tt_reader(s_d, itr, none, arg) as reader; alt parse(cx.parse_sess(), cx.cfg(), arg_rdr, mtcs) { - success(named_matches) { + success(named_matches) => { let rhs = alt rhses[i] { // okay, what's your transcriber? - @matched_nonterminal(nt_tt(@tt)) { tt } - _ { cx.span_bug(sp, ~"bad thing in rhs") } + @matched_nonterminal(nt_tt(@tt)) => tt, + _ => cx.span_bug(sp, ~"bad thing in rhs") }; // rhs has holes ( `$id` and `$(...)` that need filled) let trncbr = new_tt_reader(s_d, itr, some(named_matches), @@ -75,14 +75,13 @@ fn add_new_extension(cx: ext_ctxt, sp: span, name: ident, trncbr as reader, SOURCE_FILE); return mr_expr(p.parse_expr()); } - failure(sp, msg) { - if sp.lo >= best_fail_spot.lo { - best_fail_spot = sp; best_fail_msg = msg; - } + failure(sp, msg) => if sp.lo >= best_fail_spot.lo { + best_fail_spot = sp; + best_fail_msg = msg; } } } - _ { cx.bug(~"non-matcher found in parsed lhses"); } + _ => cx.bug(~"non-matcher found in parsed lhses") } } cx.span_fatal(best_fail_spot, best_fail_msg); diff --git a/src/libsyntax/ext/tt/transcribe.rs b/src/libsyntax/ext/tt/transcribe.rs index 9fda95c464e..c704fd351ec 100644 --- a/src/libsyntax/ext/tt/transcribe.rs +++ b/src/libsyntax/ext/tt/transcribe.rs @@ -47,8 +47,8 @@ fn new_tt_reader(sp_diag: span_handler, itr: @interner<@~str>, mut cur: @{readme: src, mut idx: 0u, dotdotdoted: false, sep: none, up: tt_frame_up(option::none)}, interpolations: alt interp { /* just a convienience */ - none { std::map::box_str_hash::<@named_match>() } - some(x) { x } + none => std::map::box_str_hash::<@named_match>(), + some(x) => x }, mut repeat_idx: ~[mut], mut repeat_len: ~[], /* dummy values, never read: */ @@ -62,10 +62,10 @@ fn new_tt_reader(sp_diag: span_handler, itr: @interner<@~str>, pure fn dup_tt_frame(&&f: tt_frame) -> tt_frame { @{readme: f.readme, mut idx: f.idx, dotdotdoted: f.dotdotdoted, sep: f.sep, up: alt f.up { - tt_frame_up(some(up_frame)) { + tt_frame_up(some(up_frame)) => { tt_frame_up(some(dup_tt_frame(up_frame))) } - tt_frame_up(none) { tt_frame_up(none) } + tt_frame_up(none) => tt_frame_up(none) } } } @@ -83,11 +83,11 @@ pure fn lookup_cur_matched_by_matched(r: tt_reader, start: @named_match) -> @named_match { pure fn red(&&ad: @named_match, &&idx: uint) -> @named_match { alt *ad { - matched_nonterminal(_) { + matched_nonterminal(_) => { // end of the line; duplicate henceforth ad } - matched_seq(ads, _) { ads[idx] } + matched_seq(ads, _) => ads[idx] } } vec::foldl(start, r.repeat_idx, red) @@ -103,33 +103,29 @@ enum lis { fn lockstep_iter_size(&&t: token_tree, &&r: tt_reader) -> lis { fn lis_merge(lhs: lis, rhs: lis) -> lis { alt lhs { - lis_unconstrained { rhs } - lis_contradiction(_) { lhs } - lis_constraint(l_len, l_id) { - alt rhs { - lis_unconstrained { lhs } - lis_contradiction(_) { rhs } - lis_constraint(r_len, _) if l_len == r_len { lhs } - lis_constraint(r_len, r_id) { + lis_unconstrained => rhs, + lis_contradiction(_) => lhs, + lis_constraint(l_len, l_id) => alt rhs { + lis_unconstrained => lhs, + lis_contradiction(_) => rhs, + lis_constraint(r_len, _) if l_len == r_len => lhs, + lis_constraint(r_len, r_id) => { lis_contradiction(fmt!{"Inconsistent lockstep iteration: \ - '%s' has %u items, but '%s' has %u", - *l_id, l_len, *r_id, r_len}) - } + '%s' has %u items, but '%s' has %u", + *l_id, l_len, *r_id, r_len}) } } } } alt t { - tt_delim(tts) | tt_seq(_, tts, _, _) { + tt_delim(tts) | tt_seq(_, tts, _, _) => { vec::foldl(lis_unconstrained, tts, {|lis, tt| lis_merge(lis, lockstep_iter_size(tt, r)) }) } - tt_tok(*) { lis_unconstrained } - tt_nonterminal(_, name) { - alt *lookup_cur_matched(r, name) { - matched_nonterminal(_) { lis_unconstrained } - matched_seq(ads, _) { lis_constraint(ads.len(), name) } - } + tt_tok(*) => lis_unconstrained, + tt_nonterminal(_, name) => alt *lookup_cur_matched(r, name) { + matched_nonterminal(_) => lis_unconstrained, + matched_seq(ads, _) => lis_constraint(ads.len(), name) } } } @@ -143,11 +139,11 @@ fn tt_next_token(&&r: tt_reader) -> {tok: token, sp: span} { || r.repeat_idx.last() == r.repeat_len.last() - 1 { alt r.cur.up { - tt_frame_up(none) { + tt_frame_up(none) => { r.cur_tok = EOF; return ret_val; } - tt_frame_up(some(tt_f)) { + tt_frame_up(some(tt_f)) => { if r.cur.dotdotdoted { vec::pop(r.repeat_idx); vec::pop(r.repeat_len); } @@ -161,40 +157,40 @@ fn tt_next_token(&&r: tt_reader) -> {tok: token, sp: span} { r.cur.idx = 0u; r.repeat_idx[r.repeat_idx.len() - 1u] += 1u; alt r.cur.sep { - some(tk) { + some(tk) => { r.cur_tok = tk; /* repeat same span, I guess */ return ret_val; } - none {} + none => () } } } loop { /* because it's easiest, this handles `tt_delim` not starting with a `tt_tok`, even though it won't happen */ alt r.cur.readme[r.cur.idx] { - tt_delim(tts) { + tt_delim(tts) => { r.cur = @{readme: tts, mut idx: 0u, dotdotdoted: false, sep: none, up: tt_frame_up(option::some(r.cur)) }; // if this could be 0-length, we'd need to potentially recur here } - tt_tok(sp, tok) { + tt_tok(sp, tok) => { r.cur_span = sp; r.cur_tok = tok; r.cur.idx += 1u; return ret_val; } - tt_seq(sp, tts, sep, zerok) { + tt_seq(sp, tts, sep, zerok) => { alt lockstep_iter_size(tt_seq(sp, tts, sep, zerok), r) { - lis_unconstrained { + lis_unconstrained => { r.sp_diag.span_fatal( sp, /* blame macro writer */ ~"attempted to repeat an expression containing no syntax \ variables matched as repeating at this depth"); } - lis_contradiction(msg) { /* FIXME #2887 blame macro invoker + lis_contradiction(msg) => { /* FIXME #2887 blame macro invoker instead*/ r.sp_diag.span_fatal(sp, msg); } - lis_constraint(len, _) { + lis_constraint(len, _) => { if len == 0 { if !zerok { r.sp_diag.span_fatal(sp, /* FIXME #2887 blame invoker @@ -215,22 +211,22 @@ fn tt_next_token(&&r: tt_reader) -> {tok: token, sp: span} { } } // FIXME #2887: think about span stuff here - tt_nonterminal(sp, ident) { + tt_nonterminal(sp, ident) => { alt *lookup_cur_matched(r, ident) { /* sidestep the interpolation tricks for ident because (a) idents can be in lots of places, so it'd be a pain (b) we actually can, since it's a token. */ - matched_nonterminal(nt_ident(sn,b)) { + matched_nonterminal(nt_ident(sn,b)) => { r.cur_span = sp; r.cur_tok = IDENT(sn,b); r.cur.idx += 1u; return ret_val; } - matched_nonterminal(other_whole_nt) { + matched_nonterminal(other_whole_nt) => { r.cur_span = sp; r.cur_tok = INTERPOLATED(other_whole_nt); r.cur.idx += 1u; return ret_val; } - matched_seq(*) { + matched_seq(*) => { r.sp_diag.span_fatal( copy r.cur_span, /* blame the macro writer */ fmt!{"variable '%s' is still repeating at this depth", diff --git a/src/libsyntax/fold.rs b/src/libsyntax/fold.rs index 521d9ab946a..ec6d7010aa1 100644 --- a/src/libsyntax/fold.rs +++ b/src/libsyntax/fold.rs @@ -81,13 +81,13 @@ type ast_fold_precursor = @{ fn fold_meta_item_(&&mi: @meta_item, fld: ast_fold) -> @meta_item { return @{node: alt mi.node { - meta_word(id) { meta_word(fld.fold_ident(id)) } - meta_list(id, mis) { + meta_word(id) => meta_word(fld.fold_ident(id)), + meta_list(id, mis) => { let fold_meta_item = |x|fold_meta_item_(x, fld); meta_list(/* FIXME: (#2543) */ copy id, vec::map(mis, fold_meta_item)) } - meta_name_value(id, s) { + meta_name_value(id, s) => { meta_name_value(fld.fold_ident(id), /* FIXME (#2543) */ copy s) } @@ -113,14 +113,14 @@ fn fold_arg_(a: arg, fld: ast_fold) -> arg { fn fold_mac_(m: mac, fld: ast_fold) -> mac { return {node: alt m.node { - mac_invoc(pth, arg, body) { + mac_invoc(pth, arg, body) => { mac_invoc(fld.fold_path(pth), option::map(arg, |x| fld.fold_expr(x)), body) } - mac_invoc_tt(pth, tt) { m.node } - mac_ellipsis { mac_ellipsis } - mac_aq(_,_) { /* FIXME (#2543) */ copy m.node } - mac_var(_) { /* FIXME (#2543) */ copy m.node } + mac_invoc_tt(pth, tt) => m.node, + mac_ellipsis => mac_ellipsis, + mac_aq(_,_) => /* FIXME (#2543) */ copy m.node, + mac_var(_) => /* FIXME (#2543) */ copy m.node, }, span: fld.new_span(m.span)}; } @@ -134,8 +134,8 @@ fn fold_fn_decl(decl: ast::fn_decl, fld: ast_fold) -> ast::fn_decl { fn fold_ty_param_bound(tpb: ty_param_bound, fld: ast_fold) -> ty_param_bound { alt tpb { - bound_copy | bound_send | bound_const | bound_owned { tpb } - bound_trait(ty) { bound_trait(fld.fold_ty(ty)) } + bound_copy | bound_send | bound_const | bound_owned => tpb, + bound_trait(ty) => bound_trait(fld.fold_ty(ty)) } } @@ -164,16 +164,16 @@ fn noop_fold_crate(c: crate_, fld: ast_fold) -> crate_ { fn noop_fold_crate_directive(cd: crate_directive_, fld: ast_fold) -> crate_directive_ { return alt cd { - cdir_src_mod(id, attrs) { + cdir_src_mod(id, attrs) => { cdir_src_mod(fld.fold_ident(id), /* FIXME (#2543) */ copy attrs) } - cdir_dir_mod(id, cds, attrs) { + cdir_dir_mod(id, cds, attrs) => { cdir_dir_mod(fld.fold_ident(id), vec::map(cds, |x| fld.fold_crate_directive(x)), /* FIXME (#2543) */ copy attrs) } - cdir_view_item(vi) { cdir_view_item(fld.fold_view_item(vi)) } - cdir_syntax(_) { copy cd } + cdir_view_item(vi) => cdir_view_item(fld.fold_view_item(vi)), + cdir_syntax(_) => copy cd } } @@ -191,7 +191,7 @@ fn noop_fold_foreign_item(&&ni: @foreign_item, fld: ast_fold) attrs: vec::map(ni.attrs, fold_attribute), node: alt ni.node { - foreign_item_fn(fdec, typms) { + foreign_item_fn(fdec, typms) => { foreign_item_fn({inputs: vec::map(fdec.inputs, fold_arg), output: fld.fold_ty(fdec.output), purity: fdec.purity, @@ -217,32 +217,32 @@ fn noop_fold_item(&&i: @item, fld: ast_fold) -> option<@item> { fn noop_fold_class_item(&&ci: @class_member, fld: ast_fold) -> @class_member { @{node: alt ci.node { - instance_var(ident, t, cm, id, p) { + instance_var(ident, t, cm, id, p) => { instance_var(/* FIXME (#2543) */ copy ident, fld.fold_ty(t), cm, id, p) } - class_method(m) { class_method(fld.fold_method(m)) } + class_method(m) => class_method(fld.fold_method(m)) }, span: ci.span} } fn noop_fold_item_underscore(i: item_, fld: ast_fold) -> item_ { return alt i { - item_const(t, e) { item_const(fld.fold_ty(t), fld.fold_expr(e)) } - item_fn(decl, typms, body) { + item_const(t, e) => item_const(fld.fold_ty(t), fld.fold_expr(e)), + item_fn(decl, typms, body) => { item_fn(fold_fn_decl(decl, fld), fold_ty_params(typms, fld), fld.fold_block(body)) } - item_mod(m) { item_mod(fld.fold_mod(m)) } - item_foreign_mod(nm) { item_foreign_mod(fld.fold_foreign_mod(nm)) } - item_ty(t, typms) { item_ty(fld.fold_ty(t), - fold_ty_params(typms, fld)) } - item_enum(variants, typms) { + item_mod(m) => item_mod(fld.fold_mod(m)), + item_foreign_mod(nm) => item_foreign_mod(fld.fold_foreign_mod(nm)), + item_ty(t, typms) => item_ty(fld.fold_ty(t), + fold_ty_params(typms, fld)), + item_enum(variants, typms) => { item_enum(vec::map(variants, |x| fld.fold_variant(x)), fold_ty_params(typms, fld)) } - item_class(typms, traits, items, m_ctor, m_dtor) { + item_class(typms, traits, items, m_ctor, m_dtor) => { let resulting_optional_constructor; alt m_ctor { none => { @@ -273,18 +273,18 @@ fn noop_fold_item_underscore(i: item_, fld: ast_fold) -> item_ { resulting_optional_constructor, dtor) } - item_impl(tps, ifce, ty, methods) { + item_impl(tps, ifce, ty, methods) => { item_impl(fold_ty_params(tps, fld), ifce.map(|p| fold_trait_ref(p, fld)), fld.fold_ty(ty), vec::map(methods, |x| fld.fold_method(x))) } - item_trait(tps, traits, methods) { + item_trait(tps, traits, methods) => { item_trait(fold_ty_params(tps, fld), vec::map(traits, |p| fold_trait_ref(p, fld)), /* FIXME (#2543) */ copy methods) } - item_mac(m) { + item_mac(m) => { // FIXME #2888: we might actually want to do something here. item_mac(m) } @@ -320,9 +320,9 @@ fn noop_fold_block(b: blk_, fld: ast_fold) -> blk_ { fn noop_fold_stmt(s: stmt_, fld: ast_fold) -> stmt_ { return alt s { - stmt_decl(d, nid) { stmt_decl(fld.fold_decl(d), fld.new_id(nid)) } - stmt_expr(e, nid) { stmt_expr(fld.fold_expr(e), fld.new_id(nid)) } - stmt_semi(e, nid) { stmt_semi(fld.fold_expr(e), fld.new_id(nid)) } + stmt_decl(d, nid) => stmt_decl(fld.fold_decl(d), fld.new_id(nid)), + stmt_expr(e, nid) => stmt_expr(fld.fold_expr(e), fld.new_id(nid)), + stmt_semi(e, nid) => stmt_semi(fld.fold_expr(e), fld.new_id(nid)) }; } @@ -334,18 +334,18 @@ fn noop_fold_arm(a: arm, fld: ast_fold) -> arm { fn noop_fold_pat(p: pat_, fld: ast_fold) -> pat_ { return alt p { - pat_wild { pat_wild } - pat_ident(binding_mode, pth, sub) { + pat_wild => pat_wild, + pat_ident(binding_mode, pth, sub) => { pat_ident(binding_mode, fld.fold_path(pth), option::map(sub, |x| fld.fold_pat(x))) } - pat_lit(e) { pat_lit(fld.fold_expr(e)) } - pat_enum(pth, pats) { + pat_lit(e) => pat_lit(fld.fold_expr(e)), + pat_enum(pth, pats) => { pat_enum(fld.fold_path(pth), option::map(pats, |pats| vec::map(pats, |x| fld.fold_pat(x)))) } - pat_rec(fields, etc) { + pat_rec(fields, etc) => { let mut fs = ~[]; for fields.each |f| { vec::push(fs, @@ -354,10 +354,10 @@ fn noop_fold_pat(p: pat_, fld: ast_fold) -> pat_ { } pat_rec(fs, etc) } - pat_tup(elts) { pat_tup(vec::map(elts, |x| fld.fold_pat(x))) } - pat_box(inner) { pat_box(fld.fold_pat(inner)) } - pat_uniq(inner) { pat_uniq(fld.fold_pat(inner)) } - pat_range(e1, e2) { + pat_tup(elts) => pat_tup(vec::map(elts, |x| fld.fold_pat(x))), + pat_box(inner) => pat_box(fld.fold_pat(inner)), + pat_uniq(inner) => pat_uniq(fld.fold_pat(inner)), + pat_range(e1, e2) => { pat_range(fld.fold_expr(e1), fld.fold_expr(e2)) } }; @@ -365,12 +365,10 @@ fn noop_fold_pat(p: pat_, fld: ast_fold) -> pat_ { fn noop_fold_decl(d: decl_, fld: ast_fold) -> decl_ { alt d { - decl_local(ls) { decl_local(vec::map(ls, |x| fld.fold_local(x))) } - decl_item(it) { - alt fld.fold_item(it) { - some(it_folded) { decl_item(it_folded) } - none { decl_local(~[]) } - } + decl_local(ls) => decl_local(vec::map(ls, |x| fld.fold_local(x))), + decl_item(it) => alt fld.fold_item(it) { + some(it_folded) => decl_item(it_folded), + none => decl_local(~[]) } } } @@ -396,91 +394,91 @@ fn noop_fold_expr(e: expr_, fld: ast_fold) -> expr_ { let fold_mac = |x| fold_mac_(x, fld); return alt e { - expr_vstore(e, v) { + expr_vstore(e, v) => { expr_vstore(fld.fold_expr(e), v) } - expr_vec(exprs, mutt) { + expr_vec(exprs, mutt) => { expr_vec(fld.map_exprs(|x| fld.fold_expr(x), exprs), mutt) } expr_repeat(expr, count, mutt) => expr_repeat(fld.fold_expr(expr), fld.fold_expr(count), mutt), - expr_rec(fields, maybe_expr) { + expr_rec(fields, maybe_expr) => { expr_rec(vec::map(fields, fold_field), option::map(maybe_expr, |x| fld.fold_expr(x))) } - expr_tup(elts) { expr_tup(vec::map(elts, |x| fld.fold_expr(x))) } - expr_call(f, args, blk) { + expr_tup(elts) => expr_tup(vec::map(elts, |x| fld.fold_expr(x))), + expr_call(f, args, blk) => { expr_call(fld.fold_expr(f), fld.map_exprs(|x| fld.fold_expr(x), args), blk) } - expr_binary(binop, lhs, rhs) { + expr_binary(binop, lhs, rhs) => { expr_binary(binop, fld.fold_expr(lhs), fld.fold_expr(rhs)) } - expr_unary(binop, ohs) { expr_unary(binop, fld.fold_expr(ohs)) } - expr_loop_body(f) { expr_loop_body(fld.fold_expr(f)) } - expr_do_body(f) { expr_do_body(fld.fold_expr(f)) } - expr_lit(_) { copy e } - expr_cast(expr, ty) { expr_cast(fld.fold_expr(expr), ty) } - expr_addr_of(m, ohs) { expr_addr_of(m, fld.fold_expr(ohs)) } - expr_if(cond, tr, fl) { + expr_unary(binop, ohs) => expr_unary(binop, fld.fold_expr(ohs)), + expr_loop_body(f) => expr_loop_body(fld.fold_expr(f)), + expr_do_body(f) => expr_do_body(fld.fold_expr(f)), + expr_lit(_) => copy e, + expr_cast(expr, ty) => expr_cast(fld.fold_expr(expr), ty), + expr_addr_of(m, ohs) => expr_addr_of(m, fld.fold_expr(ohs)), + expr_if(cond, tr, fl) => { expr_if(fld.fold_expr(cond), fld.fold_block(tr), option::map(fl, |x| fld.fold_expr(x))) } - expr_while(cond, body) { + expr_while(cond, body) => { expr_while(fld.fold_expr(cond), fld.fold_block(body)) } - expr_loop(body) { + expr_loop(body) => { expr_loop(fld.fold_block(body)) } - expr_alt(expr, arms, mode) { + expr_alt(expr, arms, mode) => { expr_alt(fld.fold_expr(expr), vec::map(arms, |x| fld.fold_arm(x)), mode) } - expr_fn(proto, decl, body, captures) { + expr_fn(proto, decl, body, captures) => { expr_fn(proto, fold_fn_decl(decl, fld), fld.fold_block(body), @((*captures).map(|cap_item| { @({id: fld.new_id((*cap_item).id) with *cap_item})}))) } - expr_fn_block(decl, body, captures) { + expr_fn_block(decl, body, captures) => { expr_fn_block(fold_fn_decl(decl, fld), fld.fold_block(body), @((*captures).map(|cap_item| { @({id: fld.new_id((*cap_item).id) with *cap_item})}))) } - expr_block(blk) { expr_block(fld.fold_block(blk)) } - expr_move(el, er) { + expr_block(blk) => expr_block(fld.fold_block(blk)), + expr_move(el, er) => { expr_move(fld.fold_expr(el), fld.fold_expr(er)) } - expr_copy(e) { expr_copy(fld.fold_expr(e)) } - expr_unary_move(e) { expr_unary_move(fld.fold_expr(e)) } - expr_assign(el, er) { + expr_copy(e) => expr_copy(fld.fold_expr(e)), + expr_unary_move(e) => expr_unary_move(fld.fold_expr(e)), + expr_assign(el, er) => { expr_assign(fld.fold_expr(el), fld.fold_expr(er)) } - expr_swap(el, er) { + expr_swap(el, er) => { expr_swap(fld.fold_expr(el), fld.fold_expr(er)) } - expr_assign_op(op, el, er) { + expr_assign_op(op, el, er) => { expr_assign_op(op, fld.fold_expr(el), fld.fold_expr(er)) } - expr_field(el, id, tys) { + expr_field(el, id, tys) => { expr_field(fld.fold_expr(el), fld.fold_ident(id), vec::map(tys, |x| fld.fold_ty(x))) } - expr_index(el, er) { + expr_index(el, er) => { expr_index(fld.fold_expr(el), fld.fold_expr(er)) } - expr_path(pth) { expr_path(fld.fold_path(pth)) } - expr_fail(e) { expr_fail(option::map(e, |x| fld.fold_expr(x))) } - expr_break | expr_again { copy e } - expr_ret(e) { expr_ret(option::map(e, |x| fld.fold_expr(x))) } - expr_log(i, lv, e) { expr_log(i, fld.fold_expr(lv), - fld.fold_expr(e)) } - expr_assert(e) { expr_assert(fld.fold_expr(e)) } - expr_mac(mac) { expr_mac(fold_mac(mac)) } - expr_struct(path, fields) { + expr_path(pth) => expr_path(fld.fold_path(pth)), + expr_fail(e) => expr_fail(option::map(e, |x| fld.fold_expr(x))), + expr_break | expr_again => copy e, + expr_ret(e) => expr_ret(option::map(e, |x| fld.fold_expr(x))), + expr_log(i, lv, e) => expr_log(i, fld.fold_expr(lv), + fld.fold_expr(e)), + expr_assert(e) => expr_assert(fld.fold_expr(e)), + expr_mac(mac) => expr_mac(fold_mac(mac)), + expr_struct(path, fields) => { expr_struct(fld.fold_path(path), vec::map(fields, fold_field)) } } @@ -497,18 +495,18 @@ fn noop_fold_ty(t: ty_, fld: ast_fold) -> ty_ { span: fld.new_span(f.span)} } alt t { - ty_nil | ty_bot | ty_infer {copy t} - ty_box(mt) {ty_box(fold_mt(mt, fld))} - ty_uniq(mt) {ty_uniq(fold_mt(mt, fld))} - ty_vec(mt) {ty_vec(fold_mt(mt, fld))} - ty_ptr(mt) {ty_ptr(fold_mt(mt, fld))} - ty_rptr(region, mt) {ty_rptr(region, fold_mt(mt, fld))} - ty_rec(fields) {ty_rec(vec::map(fields, |f| fold_field(f, fld)))} - ty_fn(proto, decl) {ty_fn(proto, fold_fn_decl(decl, fld))} - ty_tup(tys) {ty_tup(vec::map(tys, |ty| fld.fold_ty(ty)))} - ty_path(path, id) {ty_path(fld.fold_path(path), fld.new_id(id))} - ty_fixed_length(t, vs) {ty_fixed_length(fld.fold_ty(t), vs)} - ty_mac(mac) {ty_mac(fold_mac(mac))} + ty_nil | ty_bot | ty_infer => copy t, + ty_box(mt) => ty_box(fold_mt(mt, fld)), + ty_uniq(mt) => ty_uniq(fold_mt(mt, fld)), + ty_vec(mt) => ty_vec(fold_mt(mt, fld)), + ty_ptr(mt) => ty_ptr(fold_mt(mt, fld)), + ty_rptr(region, mt) => ty_rptr(region, fold_mt(mt, fld)), + ty_rec(fields) => ty_rec(vec::map(fields, |f| fold_field(f, fld))), + ty_fn(proto, decl) => ty_fn(proto, fold_fn_decl(decl, fld)), + ty_tup(tys) => ty_tup(vec::map(tys, |ty| fld.fold_ty(ty))), + ty_path(path, id) => ty_path(fld.fold_path(path), fld.new_id(id)), + ty_fixed_length(t, vs) => ty_fixed_length(fld.fold_ty(t), vs), + ty_mac(mac) => ty_mac(fold_mac(mac)) } } @@ -534,8 +532,8 @@ fn noop_fold_variant(v: variant_, fld: ast_fold) -> variant_ { let attrs = vec::map(v.attrs, fold_attribute); let de = alt v.disr_expr { - some(e) {some(fld.fold_expr(e))} - none {none} + some(e) => some(fld.fold_expr(e)), + none => none }; return {name: /* FIXME (#2543) */ copy v.name, attrs: attrs, @@ -561,8 +559,8 @@ fn noop_fold_local(l: local_, fld: ast_fold) -> local_ { pat: fld.fold_pat(l.pat), init: alt l.init { - option::none::<initializer> { l.init } - option::some::<initializer>(init) { + option::none::<initializer> => l.init, + option::some::<initializer>(init) => { option::some::<initializer>({op: init.op, expr: fld.fold_expr(init.expr)}) } @@ -636,11 +634,11 @@ impl of ast_fold for ast_fold_precursor { } fn fold_class_item(&&ci: @class_member) -> @class_member { @{node: alt ci.node { - instance_var(nm, t, mt, id, p) { + instance_var(nm, t, mt, id, p) => { instance_var(/* FIXME (#2543) */ copy nm, (self as ast_fold).fold_ty(t), mt, id, p) } - class_method(m) { + class_method(m) => { class_method(self.fold_method(m, self as ast_fold)) } }, span: self.new_span(ci.span)} diff --git a/src/libsyntax/parse.rs b/src/libsyntax/parse.rs index 05c1317fcde..71e7c4a04e5 100644 --- a/src/libsyntax/parse.rs +++ b/src/libsyntax/parse.rs @@ -190,8 +190,8 @@ fn new_parser_etc_from_file(sess: parse_sess, cfg: ast::crate_cfg, (parser, string_reader) { let res = io::read_whole_file_str(path); alt res { - result::ok(_) { /* Continue. */ } - result::err(e) { sess.span_diagnostic.handler().fatal(e); } + result::ok(_) => { /* Continue. */ } + result::err(e) => sess.span_diagnostic.handler().fatal(e) } let src = @result::unwrap(res); let filemap = codemap::new_filemap(path, src, sess.chpos, sess.byte_pos); diff --git a/src/libsyntax/parse/attr.rs b/src/libsyntax/parse/attr.rs index 265b707899a..006bd3909d8 100644 --- a/src/libsyntax/parse/attr.rs +++ b/src/libsyntax/parse/attr.rs @@ -30,7 +30,7 @@ impl parser_attr of parser_attr for parser { { let expect_item_next = vec::is_not_empty(first_item_attrs); alt self.token { - token::POUND { + token::POUND => { let lo = self.span.lo; if self.look_ahead(1u) == token::LBRACKET { self.bump(); @@ -46,12 +46,10 @@ impl parser_attr of parser_attr for parser { return some(right(self.parse_syntax_ext_naked(lo))); } else { return none; } } - token::DOC_COMMENT(_) { + token::DOC_COMMENT(_) => { return some(left(self.parse_outer_attributes())); } - _ { - return none; - } + _ => return none } } @@ -60,13 +58,13 @@ impl parser_attr of parser_attr for parser { let mut attrs: ~[ast::attribute] = ~[]; loop { alt copy self.token { - token::POUND { + token::POUND => { if self.look_ahead(1u) != token::LBRACKET { break; } attrs += ~[self.parse_attribute(ast::attr_outer)]; } - token::DOC_COMMENT(s) { + token::DOC_COMMENT(s) => { let attr = ::attr::mk_sugared_doc_attr( *self.get_str(s), self.span.lo, self.span.hi); if attr.node.style != ast::attr_outer { @@ -75,9 +73,7 @@ impl parser_attr of parser_attr for parser { attrs += ~[attr]; self.bump(); } - _ { - break; - } + _ => break } } return attrs; @@ -111,7 +107,7 @@ impl parser_attr of parser_attr for parser { let mut next_outer_attrs: ~[ast::attribute] = ~[]; loop { alt copy self.token { - token::POUND { + token::POUND => { if self.look_ahead(1u) != token::LBRACKET { // This is an extension break; @@ -130,7 +126,7 @@ impl parser_attr of parser_attr for parser { break; } } - token::DOC_COMMENT(s) { + token::DOC_COMMENT(s) => { let attr = ::attr::mk_sugared_doc_attr( *self.get_str(s), self.span.lo, self.span.hi); self.bump(); @@ -141,9 +137,7 @@ impl parser_attr of parser_attr for parser { break; } } - _ { - break; - } + _ => break } } return {inner: inner_attrs, next: next_outer_attrs}; @@ -153,18 +147,18 @@ impl parser_attr of parser_attr for parser { let lo = self.span.lo; let ident = self.parse_ident(); alt self.token { - token::EQ { + token::EQ => { self.bump(); let lit = self.parse_lit(); let mut hi = self.span.hi; return @spanned(lo, hi, ast::meta_name_value(ident, lit)); } - token::LPAREN { + token::LPAREN => { let inner_items = self.parse_meta_seq(); let mut hi = self.span.hi; return @spanned(lo, hi, ast::meta_list(ident, inner_items)); } - _ { + _ => { let mut hi = self.span.hi; return @spanned(lo, hi, ast::meta_word(ident)); } @@ -178,8 +172,10 @@ impl parser_attr of parser_attr for parser { } fn parse_optional_meta() -> ~[@ast::meta_item] { - alt self.token { token::LPAREN { return self.parse_meta_seq(); } - _ { return ~[]; } } + alt self.token { + token::LPAREN => return self.parse_meta_seq(), + _ => return ~[] + } } } diff --git a/src/libsyntax/parse/classify.rs b/src/libsyntax/parse/classify.rs index 8a5e02163be..8450ce0038d 100644 --- a/src/libsyntax/parse/classify.rs +++ b/src/libsyntax/parse/classify.rs @@ -8,25 +8,23 @@ fn expr_requires_semi_to_be_stmt(e: @ast::expr) -> bool { alt e.node { ast::expr_if(_, _, _) | ast::expr_alt(_, _, _) | ast::expr_block(_) | ast::expr_while(_, _) | ast::expr_loop(_) - | ast::expr_call(_, _, true) { - false - } - _ { true } + | ast::expr_call(_, _, true) => false, + _ => true } } fn stmt_ends_with_semi(stmt: ast::stmt) -> bool { alt stmt.node { - ast::stmt_decl(d, _) { + ast::stmt_decl(d, _) => { return alt d.node { - ast::decl_local(_) { true } - ast::decl_item(_) { false } + ast::decl_local(_) => true, + ast::decl_item(_) => false } } - ast::stmt_expr(e, _) { + ast::stmt_expr(e, _) => { return expr_requires_semi_to_be_stmt(e); } - ast::stmt_semi(e, _) { + ast::stmt_semi(e, _) => { return false; } } @@ -34,43 +32,38 @@ fn stmt_ends_with_semi(stmt: ast::stmt) -> bool { fn need_parens(expr: @ast::expr, outer_prec: uint) -> bool { alt expr.node { - ast::expr_binary(op, _, _) { operator_prec(op) < outer_prec } - ast::expr_cast(_, _) { parse::prec::as_prec < outer_prec } + ast::expr_binary(op, _, _) => operator_prec(op) < outer_prec, + ast::expr_cast(_, _) => parse::prec::as_prec < outer_prec, // This may be too conservative in some cases - ast::expr_assign(_, _) { true } - ast::expr_move(_, _) { true } - ast::expr_swap(_, _) { true } - ast::expr_assign_op(_, _, _) { true } - ast::expr_ret(_) { true } - ast::expr_assert(_) { true } - ast::expr_log(_, _, _) { true } - _ { !parse::classify::expr_requires_semi_to_be_stmt(expr) } + ast::expr_assign(_, _) => true, + ast::expr_move(_, _) => true, + ast::expr_swap(_, _) => true, + ast::expr_assign_op(_, _, _) => true, + ast::expr_ret(_) => true, + ast::expr_assert(_) => true, + ast::expr_log(_, _, _) => true, + _ => !parse::classify::expr_requires_semi_to_be_stmt(expr) } } fn ends_in_lit_int(ex: @ast::expr) -> bool { alt ex.node { - ast::expr_lit(node) { - alt node { - @{node: ast::lit_int(_, ast::ty_i), _} | - @{node: ast::lit_int_unsuffixed(_), _} - { true } - _ { false } - } + ast::expr_lit(node) => alt node { + @{node: ast::lit_int(_, ast::ty_i), _} + | @{node: ast::lit_int_unsuffixed(_), _} => true, + _ => false } ast::expr_binary(_, _, sub) | ast::expr_unary(_, sub) | ast::expr_move(_, sub) | ast::expr_copy(sub) | ast::expr_assign(_, sub) | ast::expr_assign_op(_, _, sub) | ast::expr_swap(_, sub) | - ast::expr_log(_, _, sub) | ast::expr_assert(sub) { + ast::expr_log(_, _, sub) | ast::expr_assert(sub) => { ends_in_lit_int(sub) } - ast::expr_fail(osub) | ast::expr_ret(osub) { - alt osub { - some(ex) { ends_in_lit_int(ex) } - _ { false } - } + ast::expr_fail(osub) | ast::expr_ret(osub) => alt osub { + some(ex) => ends_in_lit_int(ex), + _ => false } - _ { false } + _ => false } } diff --git a/src/libsyntax/parse/common.rs b/src/libsyntax/parse/common.rs index 092238e17be..6b31b53eaa5 100644 --- a/src/libsyntax/parse/common.rs +++ b/src/libsyntax/parse/common.rs @@ -85,10 +85,10 @@ impl parser_common of parser_common for parser { fn parse_ident() -> ast::ident { alt copy self.token { - token::IDENT(i, _) { self.bump(); return self.get_str(i); } - token::INTERPOLATED(token::nt_ident(*)) { self.bug( + token::IDENT(i, _) => { self.bump(); return self.get_str(i); } + token::INTERPOLATED(token::nt_ident(*)) => { self.bug( ~"ident interpolation not converted to real token"); } - _ { self.fatal(~"expected ident, found `" + _ => { self.fatal(~"expected ident, found `" + token_to_str(self.reader, self.token) + ~"`"); } } @@ -135,10 +135,10 @@ impl parser_common of parser_common for parser { fn is_any_keyword(tok: token::token) -> bool { alt tok { - token::IDENT(sid, false) { + token::IDENT(sid, false) => { self.keywords.contains_key_ref(self.get_str(sid)) } - _ { false } + _ => false } } @@ -147,13 +147,13 @@ impl parser_common of parser_common for parser { let mut bump = false; let val = alt self.token { - token::IDENT(sid, false) { + token::IDENT(sid, false) => { if word == *self.get_str(sid) { bump = true; true } else { false } } - _ { false } + _ => false }; if bump { self.bump() } val @@ -174,11 +174,11 @@ impl parser_common of parser_common for parser { fn check_restricted_keywords() { alt self.token { - token::IDENT(_, false) { + token::IDENT(_, false) => { let w = token_to_str(self.reader, self.token); self.check_restricted_keywords_(w); } - _ { } + _ => () } } @@ -210,9 +210,11 @@ impl parser_common of parser_common for parser { while self.token != token::GT && self.token != token::BINOP(token::SHR) { alt sep { - some(t) { if first { first = false; } - else { self.expect(t); } } - _ { } + some(t) => { + if first { first = false; } + else { self.expect(t); } + } + _ => () } vec::push(v, f(self)); } @@ -252,9 +254,11 @@ impl parser_common of parser_common for parser { let mut v: ~[T] = ~[]; while self.token != ket { alt sep.sep { - some(t) { if first { first = false; } - else { self.expect(t); } } - _ { } + some(t) => { + if first { first = false; } + else { self.expect(t); } + } + _ => () } if sep.trailing_sep_allowed && self.token == ket { break; } vec::push(v, f(self)); diff --git a/src/libsyntax/parse/eval.rs b/src/libsyntax/parse/eval.rs index 90519c23e5f..154e653e890 100644 --- a/src/libsyntax/parse/eval.rs +++ b/src/libsyntax/parse/eval.rs @@ -48,8 +48,8 @@ fn parse_companion_mod(cx: ctx, prefix: ~str, suffix: option<~str>) fn companion_file(+prefix: ~str, suffix: option<~str>) -> ~str { return alt suffix { - option::some(s) { path::connect(prefix, s) } - option::none { prefix } + option::some(s) => path::connect(prefix, s), + option::none => prefix } + ~".rs"; } @@ -57,8 +57,8 @@ fn parse_companion_mod(cx: ctx, prefix: ~str, suffix: option<~str>) // Crude, but there's no lib function for this and I'm not // up to writing it just now alt io::file_reader(path) { - result::ok(_) { true } - result::err(_) { false } + result::ok(_) => true, + result::err(_) => false } } @@ -80,10 +80,8 @@ fn parse_companion_mod(cx: ctx, prefix: ~str, suffix: option<~str>) fn cdir_path_opt(id: ast::ident, attrs: ~[ast::attribute]) -> @~str { alt ::attr::first_attr_value_str_by_name(attrs, ~"path") { - some(d) { - return d; - } - none { return id; } + some(d) => return d, + none => return id } } @@ -91,7 +89,7 @@ fn eval_crate_directive(cx: ctx, cdir: @ast::crate_directive, prefix: ~str, &view_items: ~[@ast::view_item], &items: ~[@ast::item]) { alt cdir.node { - ast::cdir_src_mod(id, attrs) { + ast::cdir_src_mod(id, attrs) => { let file_path = cdir_path_opt(@(*id + ~".rs"), attrs); let full_path = if path::path_is_absolute(*file_path) { @@ -112,7 +110,7 @@ fn eval_crate_directive(cx: ctx, cdir: @ast::crate_directive, prefix: ~str, cx.sess.byte_pos = cx.sess.byte_pos + r0.pos; vec::push(items, i); } - ast::cdir_dir_mod(id, cdirs, attrs) { + ast::cdir_dir_mod(id, cdirs, attrs) => { let path = cdir_path_opt(id, attrs); let full_path = if path::path_is_absolute(*path) { @@ -130,8 +128,8 @@ fn eval_crate_directive(cx: ctx, cdir: @ast::crate_directive, prefix: ~str, cx.sess.next_id += 1; vec::push(items, i); } - ast::cdir_view_item(vi) { vec::push(view_items, vi); } - ast::cdir_syntax(pth) { } + ast::cdir_view_item(vi) => vec::push(view_items, vi), + ast::cdir_syntax(pth) => () } } // diff --git a/src/libsyntax/parse/lexer.rs b/src/libsyntax/parse/lexer.rs index 74dbea41d82..bc5aba5283c 100644 --- a/src/libsyntax/parse/lexer.rs +++ b/src/libsyntax/parse/lexer.rs @@ -207,7 +207,7 @@ fn consume_any_line_comment(rdr: string_reader) -> option<{tok: token::token, sp: span}> { if rdr.curr == '/' { alt nextch(rdr) { - '/' { + '/' => { bump(rdr); bump(rdr); // line comments starting with "///" or "//!" are doc-comments @@ -228,8 +228,8 @@ fn consume_any_line_comment(rdr: string_reader) return consume_whitespace_and_comments(rdr); } } - '*' { bump(rdr); bump(rdr); return consume_block_comment(rdr); } - _ {} + '*' => { bump(rdr); bump(rdr); return consume_block_comment(rdr); } + _ => () } } else if rdr.curr == '#' { if nextch(rdr) == '!' { @@ -314,11 +314,11 @@ fn scan_digits(rdr: string_reader, radix: uint) -> ~str { let c = rdr.curr; if c == '_' { bump(rdr); again; } alt char::to_digit(c, radix) { - some(d) { + some(d) => { str::push_char(rslt, c); bump(rdr); } - _ { return rslt; } + _ => return rslt } }; } @@ -372,8 +372,8 @@ fn scan_number(c: char, rdr: string_reader) -> token::token { } let parsed = option::get(u64::from_str_radix(num_str, base as u64)); alt tp { - either::left(t) { return token::LIT_INT(parsed as i64, t); } - either::right(t) { return token::LIT_UINT(parsed, t); } + either::left(t) => return token::LIT_INT(parsed as i64, t), + either::right(t) => return token::LIT_UINT(parsed, t) } } let mut is_float = false; @@ -384,11 +384,11 @@ fn scan_number(c: char, rdr: string_reader) -> token::token { num_str += ~"." + dec_part; } alt scan_exponent(rdr) { - some(s) { + some(s) => { is_float = true; num_str += s; } - none {} + none => () } if rdr.curr == 'f' { bump(rdr); @@ -479,9 +479,9 @@ fn next_token_inner(rdr: string_reader) -> token::token { // One-byte tokens. - ';' { bump(rdr); return token::SEMI; } - ',' { bump(rdr); return token::COMMA; } - '.' { + ';' => { bump(rdr); return token::SEMI; } + ',' => { bump(rdr); return token::COMMA; } + '.' => { bump(rdr); if rdr.curr == '.' && nextch(rdr) != '.' { bump(rdr); @@ -494,16 +494,16 @@ fn next_token_inner(rdr: string_reader) -> token::token { } return token::DOT; } - '(' { bump(rdr); return token::LPAREN; } - ')' { bump(rdr); return token::RPAREN; } - '{' { bump(rdr); return token::LBRACE; } - '}' { bump(rdr); return token::RBRACE; } - '[' { bump(rdr); return token::LBRACKET; } - ']' { bump(rdr); return token::RBRACKET; } - '@' { bump(rdr); return token::AT; } - '#' { bump(rdr); return token::POUND; } - '~' { bump(rdr); return token::TILDE; } - ':' { + '(' => { bump(rdr); return token::LPAREN; } + ')' => { bump(rdr); return token::RPAREN; } + '{' => { bump(rdr); return token::LBRACE; } + '}' => { bump(rdr); return token::RBRACE; } + '[' => { bump(rdr); return token::LBRACKET; } + ']' => { bump(rdr); return token::RBRACKET; } + '@' => { bump(rdr); return token::AT; } + '#' => { bump(rdr); return token::POUND; } + '~' => { bump(rdr); return token::TILDE; } + ':' => { bump(rdr); if rdr.curr == ':' { bump(rdr); @@ -511,14 +511,14 @@ fn next_token_inner(rdr: string_reader) -> token::token { } else { return token::COLON; } } - '$' { bump(rdr); return token::DOLLAR; } + '$' => { bump(rdr); return token::DOLLAR; } // Multi-byte tokens. - '=' { + '=' => { bump(rdr); if rdr.curr == '=' { bump(rdr); @@ -530,37 +530,37 @@ fn next_token_inner(rdr: string_reader) -> token::token { return token::EQ; } } - '!' { + '!' => { bump(rdr); if rdr.curr == '=' { bump(rdr); return token::NE; } else { return token::NOT; } } - '<' { + '<' => { bump(rdr); alt rdr.curr { - '=' { bump(rdr); return token::LE; } - '<' { return binop(rdr, token::SHL); } - '-' { + '=' => { bump(rdr); return token::LE; } + '<' => { return binop(rdr, token::SHL); } + '-' => { bump(rdr); alt rdr.curr { - '>' { bump(rdr); return token::DARROW; } - _ { return token::LARROW; } + '>' => { bump(rdr); return token::DARROW; } + _ => { return token::LARROW; } } } - _ { return token::LT; } + _ => { return token::LT; } } } - '>' { + '>' => { bump(rdr); alt rdr.curr { - '=' { bump(rdr); return token::GE; } - '>' { return binop(rdr, token::SHR); } - _ { return token::GT; } + '=' => { bump(rdr); return token::GE; } + '>' => { return binop(rdr, token::SHR); } + _ => { return token::GT; } } } - '\'' { + '\'' => { bump(rdr); let mut c2 = rdr.curr; bump(rdr); @@ -568,16 +568,16 @@ fn next_token_inner(rdr: string_reader) -> token::token { let escaped = rdr.curr; bump(rdr); alt escaped { - 'n' { c2 = '\n'; } - 'r' { c2 = '\r'; } - 't' { c2 = '\t'; } - '\\' { c2 = '\\'; } - '\'' { c2 = '\''; } - '"' { c2 = '"'; } - 'x' { c2 = scan_numeric_escape(rdr, 2u); } - 'u' { c2 = scan_numeric_escape(rdr, 4u); } - 'U' { c2 = scan_numeric_escape(rdr, 8u); } - c2 { + 'n' => { c2 = '\n'; } + 'r' => { c2 = '\r'; } + 't' => { c2 = '\t'; } + '\\' => { c2 = '\\'; } + '\'' => { c2 = '\''; } + '"' => { c2 = '"'; } + 'x' => { c2 = scan_numeric_escape(rdr, 2u); } + 'u' => { c2 = scan_numeric_escape(rdr, 4u); } + 'U' => { c2 = scan_numeric_escape(rdr, 8u); } + c2 => { rdr.fatal(fmt!{"unknown character escape: %d", c2 as int}); } } @@ -588,7 +588,7 @@ fn next_token_inner(rdr: string_reader) -> token::token { bump(rdr); // advance curr past token return token::LIT_INT(c2 as i64, ast::ty_char); } - '"' { + '"' => { let n = rdr.chpos; bump(rdr); while rdr.curr != '"' { @@ -600,63 +600,63 @@ fn next_token_inner(rdr: string_reader) -> token::token { let ch = rdr.curr; bump(rdr); alt ch { - '\\' { + '\\' => { let escaped = rdr.curr; bump(rdr); alt escaped { - 'n' { str::push_char(accum_str, '\n'); } - 'r' { str::push_char(accum_str, '\r'); } - 't' { str::push_char(accum_str, '\t'); } - '\\' { str::push_char(accum_str, '\\'); } - '\'' { str::push_char(accum_str, '\''); } - '"' { str::push_char(accum_str, '"'); } - '\n' { consume_whitespace(rdr); } - 'x' { + 'n' => str::push_char(accum_str, '\n'), + 'r' => str::push_char(accum_str, '\r'), + 't' => str::push_char(accum_str, '\t'), + '\\' => str::push_char(accum_str, '\\'), + '\'' => str::push_char(accum_str, '\''), + '"' => str::push_char(accum_str, '"'), + '\n' => consume_whitespace(rdr), + 'x' => { str::push_char(accum_str, scan_numeric_escape(rdr, 2u)); } - 'u' { + 'u' => { str::push_char(accum_str, scan_numeric_escape(rdr, 4u)); } - 'U' { + 'U' => { str::push_char(accum_str, scan_numeric_escape(rdr, 8u)); } - c2 { + c2 => { rdr.fatal(fmt!{"unknown string escape: %d", c2 as int}); } } } - _ { str::push_char(accum_str, ch); } + _ => str::push_char(accum_str, ch) } } bump(rdr); return token::LIT_STR((*rdr.interner).intern(@accum_str)); } - '-' { + '-' => { if nextch(rdr) == '>' { bump(rdr); bump(rdr); return token::RARROW; } else { return binop(rdr, token::MINUS); } } - '&' { + '&' => { if nextch(rdr) == '&' { bump(rdr); bump(rdr); return token::ANDAND; } else { return binop(rdr, token::AND); } } - '|' { + '|' => { alt nextch(rdr) { - '|' { bump(rdr); bump(rdr); return token::OROR; } - _ { return binop(rdr, token::OR); } + '|' => { bump(rdr); bump(rdr); return token::OROR; } + _ => { return binop(rdr, token::OR); } } } - '+' { return binop(rdr, token::PLUS); } - '*' { return binop(rdr, token::STAR); } - '/' { return binop(rdr, token::SLASH); } - '^' { return binop(rdr, token::CARET); } - '%' { return binop(rdr, token::PERCENT); } - c { rdr.fatal(fmt!{"unknown start of token: %d", c as int}); } + '+' => { return binop(rdr, token::PLUS); } + '*' => { return binop(rdr, token::STAR); } + '/' => { return binop(rdr, token::SLASH); } + '^' => { return binop(rdr, token::CARET); } + '%' => { return binop(rdr, token::PERCENT); } + c => { rdr.fatal(fmt!{"unknown start of token: %d", c as int}); } } } diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 4769e4ab384..5eacf75e529 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -107,35 +107,35 @@ The important thing is to make sure that lookahead doesn't balk at INTERPOLATED tokens */ macro_rules! maybe_whole_expr { {$p:expr} => { alt copy $p.token { - INTERPOLATED(token::nt_expr(e)) { + INTERPOLATED(token::nt_expr(e)) => { $p.bump(); return pexpr(e); } - INTERPOLATED(token::nt_path(pt)) { + INTERPOLATED(token::nt_path(pt)) => { $p.bump(); return $p.mk_pexpr($p.span.lo, $p.span.lo, expr_path(pt)); } - _ {} + _ => () }} } macro_rules! maybe_whole { {$p:expr, $constructor:ident} => { alt copy $p.token { - INTERPOLATED(token::$constructor(x)) { $p.bump(); return x; } - _ {} + INTERPOLATED(token::$constructor(x)) => { $p.bump(); return x; } + _ => () }} ; {deref $p:expr, $constructor:ident} => { alt copy $p.token { - INTERPOLATED(token::$constructor(x)) { $p.bump(); return *x; } - _ {} + INTERPOLATED(token::$constructor(x)) => { $p.bump(); return *x; } + _ => () }} ; {some $p:expr, $constructor:ident} => { alt copy $p.token { - INTERPOLATED(token::$constructor(x)) { $p.bump(); return some(x); } - _ {} + INTERPOLATED(token::$constructor(x)) => { $p.bump(); return some(x); } + _ => () }} ; {pair_empty $p:expr, $constructor:ident} => { alt copy $p.token { - INTERPOLATED(token::$constructor(x)) { $p.bump(); return (~[], x); } - _ {} + INTERPOLATED(token::$constructor(x)) => { $p.bump(); return (~[], x); } + _ => () }} } @@ -284,7 +284,7 @@ class parser { `%s`", token_to_str(p.reader, p.token)}; alt p.token { - token::SEMI { + token::SEMI => { p.bump(); debug!{"parse_trait_methods(): parsing required method"}; // NB: at the moment, visibility annotations on required @@ -294,7 +294,7 @@ class parser { self_ty: self_ty, id: p.get_id(), span: mk_sp(lo, hi)}) } - token::LBRACE { + token::LBRACE => { debug!{"parse_trait_methods(): parsing provided method"}; let (inner_attrs, body) = p.parse_inner_attrs_and_block(true); @@ -311,7 +311,7 @@ class parser { vis: vis}) } - _ { p.fatal(~"expected `;` or `}` but found `" + + _ => { p.fatal(~"expected `;` or `}` but found `" + token_to_str(p.reader, p.token) + ~"`"); } } @@ -356,8 +356,8 @@ class parser { fn region_from_name(s: option<@~str>) -> @region { let r = alt s { - some (string) { re_named(string) } - none { re_anon } + some (string) => re_named(string), + none => re_anon }; @{id: self.get_id(), node: r} @@ -368,12 +368,12 @@ class parser { self.expect(token::BINOP(token::AND)); alt copy self.token { - token::IDENT(sid, _) { + token::IDENT(sid, _) => { self.bump(); let n = self.get_str(sid); self.region_from_name(some(n)) } - _ { + _ => { self.region_from_name(none) } } @@ -402,12 +402,12 @@ class parser { let lo = self.span.lo; alt self.maybe_parse_dollar_mac() { - some(e) { + some(e) => { return @{id: self.get_id(), node: ty_mac(spanned(lo, self.span.hi, e)), span: mk_sp(lo, self.span.hi)}; } - none {} + none => () } let t = if self.token == token::LPAREN { @@ -472,8 +472,8 @@ class parser { return @{id: self.get_id(), node: alt self.maybe_parse_fixed_vstore() { // Consider a fixed vstore suffix (/N or /_) - none { t } - some(v) { + none => t, + some(v) => { ty_fixed_length(@{id: self.get_id(), node:t, span: sp}, v) } }, span: sp} @@ -542,27 +542,27 @@ class parser { fn maybe_parse_dollar_mac() -> option<mac_> { alt copy self.token { - token::DOLLAR { + token::DOLLAR => { let lo = self.span.lo; self.bump(); alt copy self.token { - token::LIT_INT_UNSUFFIXED(num) { + token::LIT_INT_UNSUFFIXED(num) => { self.bump(); some(mac_var(num as uint)) } - token::LPAREN { + token::LPAREN => { self.bump(); let e = self.parse_expr(); self.expect(token::RPAREN); let hi = self.last_span.hi; some(mac_aq(mk_sp(lo,hi), e)) } - _ { + _ => { self.fatal(~"expected `(` or unsuffixed integer literal"); } } } - _ {none} + _ => none } } @@ -570,15 +570,13 @@ class parser { if self.token == token::BINOP(token::SLASH) { self.bump(); alt copy self.token { - token::UNDERSCORE { + token::UNDERSCORE => { self.bump(); some(none) } - token::LIT_INT_UNSUFFIXED(i) if i >= 0i64 { + token::LIT_INT_UNSUFFIXED(i) if i >= 0i64 => { self.bump(); some(some(i as uint)) } - _ { - none - } + _ => none } } else { none @@ -587,13 +585,13 @@ class parser { fn lit_from_token(tok: token::token) -> lit_ { alt tok { - token::LIT_INT(i, it) { lit_int(i, it) } - token::LIT_UINT(u, ut) { lit_uint(u, ut) } - token::LIT_INT_UNSUFFIXED(i) { lit_int_unsuffixed(i) } - token::LIT_FLOAT(s, ft) { lit_float(self.get_str(s), ft) } - token::LIT_STR(s) { lit_str(self.get_str(s)) } - token::LPAREN { self.expect(token::RPAREN); lit_nil } - _ { self.unexpected_last(tok); } + token::LIT_INT(i, it) => lit_int(i, it), + token::LIT_UINT(u, ut) => lit_uint(u, ut), + token::LIT_INT_UNSUFFIXED(i) => lit_int_unsuffixed(i), + token::LIT_FLOAT(s, ft) => lit_float(self.get_str(s), ft), + token::LIT_STR(s) => lit_str(self.get_str(s)), + token::LPAREN => { self.expect(token::RPAREN); lit_nil } + _ => self.unexpected_last(tok) } } @@ -735,8 +733,8 @@ class parser { fn to_expr(e: pexpr) -> @expr { alt e.node { - expr_tup(es) if vec::len(es) == 1u { es[0u] } - _ { *e } + expr_tup(es) if vec::len(es) == 1u => es[0u], + _ => *e } } @@ -748,8 +746,8 @@ class parser { let mut ex: expr_; alt self.maybe_parse_dollar_mac() { - some(x) {return pexpr(self.mk_mac_expr(lo, self.span.hi, x));} - _ {} + some(x) => return pexpr(self.mk_mac_expr(lo, self.span.hi, x)), + _ => () } if self.token == token::LPAREN { @@ -800,8 +798,8 @@ class parser { } else if self.eat_keyword(~"fn") { let proto = self.parse_fn_ty_proto(); alt proto { - proto_bare { self.fatal(~"fn expr are deprecated, use fn@"); } - _ { /* fallthrough */ } + proto_bare => self.fatal(~"fn expr are deprecated, use fn@"), + _ => { /* fallthrough */ } } return pexpr(self.parse_fn_expr(proto)); } else if self.eat_keyword(~"unchecked") { @@ -895,13 +893,13 @@ class parser { if self.token == token::NOT { self.bump(); let tts = alt self.token { - token::LPAREN | token::LBRACE | token::LBRACKET { + token::LPAREN | token::LBRACE | token::LBRACKET => { let ket = token::flip_delimiter(self.token); self.parse_unspanned_seq(copy self.token, ket, seq_sep_none(), |p| p.parse_token_tree()) } - _ { self.fatal(~"expected open delimiter"); } + _ => self.fatal(~"expected open delimiter") }; let hi = self.span.hi; @@ -942,16 +940,14 @@ class parser { // only. alt ex { expr_lit(@{node: lit_str(_), span: _}) | - expr_vec(_, _) { - alt self.maybe_parse_fixed_vstore() { - none { } - some(v) { + expr_vec(_, _) => alt self.maybe_parse_fixed_vstore() { + none => (), + some(v) => { hi = self.span.hi; ex = expr_vstore(self.mk_expr(lo, hi, ex), vstore_fixed(v)); - } } } - _ { } + _ => () } return self.mk_pexpr(lo, hi, ex); @@ -971,8 +967,8 @@ class parser { fn parse_syntax_ext_naked(lo: uint) -> @expr { alt self.token { - token::IDENT(_, _) {} - _ { self.fatal(~"expected a syntax expander name"); } + token::IDENT(_, _) => (), + _ => self.fatal(~"expected a syntax expander name") } let pth = self.parse_path_without_tps(); //temporary for a backwards-compatible cycle: @@ -998,10 +994,10 @@ class parser { let mut depth = 1u; while (depth > 0u) { alt (self.token) { - token::LBRACE {depth += 1u;} - token::RBRACE {depth -= 1u;} - token::EOF {self.fatal(~"unexpected EOF in macro body");} - _ {} + token::LBRACE => depth += 1u, + token::RBRACE => depth -= 1u, + token::EOF => self.fatal(~"unexpected EOF in macro body"), + _ => () } self.bump(); } @@ -1028,7 +1024,7 @@ class parser { // expr.f if self.eat(token::DOT) { alt copy self.token { - token::IDENT(i, _) { + token::IDENT(i, _) => { hi = self.span.hi; self.bump(); let tys = if self.eat(token::MOD_SEP) { @@ -1040,14 +1036,14 @@ class parser { self.get_str(i), tys)); } - _ { self.unexpected(); } + _ => self.unexpected() } again; } if self.expr_is_complete(e) { break; } alt copy self.token { // expr(...) - token::LPAREN if self.permits_call() { + token::LPAREN if self.permits_call() => { let es = self.parse_unspanned_seq( token::LPAREN, token::RPAREN, seq_sep_trailing_disallowed(token::COMMA), @@ -1059,7 +1055,7 @@ class parser { } // expr[...] - token::LBRACKET { + token::LBRACKET => { self.bump(); let ix = self.parse_expr(); hi = ix.span.hi; @@ -1067,7 +1063,7 @@ class parser { e = self.mk_pexpr(lo, hi, expr_index(self.to_expr(e), ix)); } - _ { return e; } + _ => return e } } return e; @@ -1099,15 +1095,15 @@ class parser { fn parse_tt_tok(p: parser, delim_ok: bool) -> token_tree { alt p.token { token::RPAREN | token::RBRACE | token::RBRACKET - if !delim_ok { + if !delim_ok => { p.fatal(~"incorrect close delimiter: `" + token_to_str(p.reader, p.token) + ~"`"); } - token::EOF { + token::EOF => { p.fatal(~"file ended in the middle of a macro invocation"); } /* we ought to allow different depths of unquotation */ - token::DOLLAR if p.quote_depth > 0u { + token::DOLLAR if p.quote_depth > 0u => { p.bump(); let sp = p.span; @@ -1121,7 +1117,7 @@ class parser { return tt_nonterminal(sp, p.parse_ident()); } } - _ { /* ok */ } + _ => { /* ok */ } } let res = tt_tok(p.span, p.token); p.bump(); @@ -1129,7 +1125,7 @@ class parser { } return alt self.token { - token::LPAREN | token::LBRACE | token::LBRACKET { + token::LPAREN | token::LBRACE | token::LBRACKET => { let ket = token::flip_delimiter(self.token); tt_delim(vec::append( ~[parse_tt_tok(self, true)], @@ -1139,7 +1135,7 @@ class parser { |p| p.parse_token_tree()), ~[parse_tt_tok(self, true)]))) } - _ { parse_tt_tok(self, false) } + _ => parse_tt_tok(self, false) }; } @@ -1149,11 +1145,11 @@ class parser { maybe_whole!{self, nt_matchers}; let name_idx = @mut 0u; return alt self.token { - token::LBRACE | token::LPAREN | token::LBRACKET { + token::LBRACE | token::LPAREN | token::LBRACKET => { self.parse_matcher_subseq(name_idx, copy self.token, token::flip_delimiter(self.token)) } - _ { self.fatal(~"expected open delimiter"); } + _ => self.fatal(~"expected open delimiter") } } @@ -1217,29 +1213,29 @@ class parser { let mut ex; alt copy self.token { - token::NOT { + token::NOT => { self.bump(); let e = self.to_expr(self.parse_prefix_expr()); hi = e.span.hi; self.get_id(); // see ast_util::op_expr_callee_id ex = expr_unary(not, e); } - token::BINOP(b) { + token::BINOP(b) => { alt b { - token::MINUS { + token::MINUS => { self.bump(); let e = self.to_expr(self.parse_prefix_expr()); hi = e.span.hi; self.get_id(); // see ast_util::op_expr_callee_id ex = expr_unary(neg, e); } - token::STAR { + token::STAR => { self.bump(); let e = self.to_expr(self.parse_prefix_expr()); hi = e.span.hi; ex = expr_unary(deref, e); } - token::AND { + token::AND => { self.bump(); let m = self.parse_mutability(); let e = self.to_expr(self.parse_prefix_expr()); @@ -1247,16 +1243,16 @@ class parser { // HACK: turn &[...] into a &-evec ex = alt e.node { expr_vec(*) | expr_lit(@{node: lit_str(_), span: _}) - if m == m_imm { + if m == m_imm => { expr_vstore(e, vstore_slice(self.region_from_name(none))) } - _ { expr_addr_of(m, e) } + _ => expr_addr_of(m, e) }; } - _ { return self.parse_dot_or_call_expr(); } + _ => return self.parse_dot_or_call_expr() } } - token::AT { + token::AT => { self.bump(); let m = self.parse_mutability(); let e = self.to_expr(self.parse_prefix_expr()); @@ -1264,11 +1260,11 @@ class parser { // HACK: turn @[...] into a @-evec ex = alt e.node { expr_vec(*) | expr_lit(@{node: lit_str(_), span: _}) - if m == m_imm { expr_vstore(e, vstore_box) } - _ { expr_unary(box(m), e) } + if m == m_imm => expr_vstore(e, vstore_box), + _ => expr_unary(box(m), e) }; } - token::TILDE { + token::TILDE => { self.bump(); let m = self.parse_mutability(); let e = self.to_expr(self.parse_prefix_expr()); @@ -1276,11 +1272,11 @@ class parser { // HACK: turn ~[...] into a ~-evec ex = alt e.node { expr_vec(*) | expr_lit(@{node: lit_str(_), span: _}) - if m == m_imm { expr_vstore(e, vstore_uniq) } - _ { expr_unary(uniq(m), e) } + if m == m_imm => expr_vstore(e, vstore_uniq), + _ => expr_unary(uniq(m), e) }; } - _ { return self.parse_dot_or_call_expr(); } + _ => return self.parse_dot_or_call_expr() } return self.mk_pexpr(lo, hi, ex); } @@ -1306,7 +1302,7 @@ class parser { } let cur_opt = token_to_binop(peeked); alt cur_opt { - some(cur_op) { + some(cur_op) => { let cur_prec = operator_prec(cur_op); if cur_prec > min_prec { self.bump(); @@ -1318,7 +1314,7 @@ class parser { return self.parse_more_binops(bin, min_prec); } } - _ {} + _ => () } if as_prec > min_prec && self.eat_keyword(~"as") { let rhs = self.parse_ty(true); @@ -1333,42 +1329,42 @@ class parser { let lo = self.span.lo; let lhs = self.parse_binops(); alt copy self.token { - token::EQ { + token::EQ => { self.bump(); let rhs = self.parse_expr(); return self.mk_expr(lo, rhs.span.hi, expr_assign(lhs, rhs)); } - token::BINOPEQ(op) { + token::BINOPEQ(op) => { self.bump(); let rhs = self.parse_expr(); let mut aop; alt op { - token::PLUS { aop = add; } - token::MINUS { aop = subtract; } - token::STAR { aop = mul; } - token::SLASH { aop = div; } - token::PERCENT { aop = rem; } - token::CARET { aop = bitxor; } - token::AND { aop = bitand; } - token::OR { aop = bitor; } - token::SHL { aop = shl; } - token::SHR { aop = shr; } + token::PLUS => aop = add, + token::MINUS => aop = subtract, + token::STAR => aop = mul, + token::SLASH => aop = div, + token::PERCENT => aop = rem, + token::CARET => aop = bitxor, + token::AND => aop = bitand, + token::OR => aop = bitor, + token::SHL => aop = shl, + token::SHR => aop = shr } self.get_id(); // see ast_util::op_expr_callee_id return self.mk_expr(lo, rhs.span.hi, expr_assign_op(aop, lhs, rhs)); } - token::LARROW { + token::LARROW => { self.bump(); let rhs = self.parse_expr(); return self.mk_expr(lo, rhs.span.hi, expr_move(lhs, rhs)); } - token::DARROW { + token::DARROW => { self.bump(); let rhs = self.parse_expr(); return self.mk_expr(lo, rhs.span.hi, expr_swap(lhs, rhs)); } - _ {/* fall through */ } + _ => {/* fall through */ } } return lhs; } @@ -1407,10 +1403,10 @@ class parser { self.parse_lambda_expr_( || { alt self.token { - token::BINOP(token::OR) | token::OROR { + token::BINOP(token::OR) | token::OROR => { self.parse_fn_block_decl() } - _ { + _ => { // No argument list - `do foo {` ({ { @@ -1476,7 +1472,7 @@ class parser { // them as the lambda arguments let e = self.parse_expr_res(RESTRICT_NO_BAR_OR_DOUBLEBAR_OP); alt e.node { - expr_call(f, args, false) { + expr_call(f, args, false) => { let block = self.parse_lambda_block_expr(); let last_arg = self.mk_expr(block.span.lo, block.span.hi, ctor(block)); @@ -1484,14 +1480,14 @@ class parser { @{node: expr_call(f, args, true) with *e} } - expr_path(*) | expr_field(*) | expr_call(*) { + expr_path(*) | expr_field(*) | expr_call(*) => { let block = self.parse_lambda_block_expr(); let last_arg = self.mk_expr(block.span.lo, block.span.hi, ctor(block)); self.mk_expr(lo.lo, last_arg.span.hi, expr_call(e, ~[last_arg], true)) } - _ { + _ => { // There may be other types of expressions that can // represent the callee in `for` and `do` expressions // but they aren't represented by tests @@ -1607,11 +1603,11 @@ class parser { fn parse_initializer() -> option<initializer> { alt self.token { - token::EQ { + token::EQ => { self.bump(); return some({op: init_assign, expr: self.parse_expr()}); } - token::LARROW { + token::LARROW => { self.bump(); return some({op: init_move, expr: self.parse_expr()}); } @@ -1622,7 +1618,7 @@ class parser { // return some(rec(op = init_recv, // expr = self.parse_expr())); // } - _ { + _ => { return none; } } @@ -1644,39 +1640,43 @@ class parser { let mut hi = self.span.hi; let mut pat; alt self.token { - token::UNDERSCORE { self.bump(); pat = pat_wild; } - token::AT { + token::UNDERSCORE => { self.bump(); pat = pat_wild; } + token::AT => { self.bump(); let sub = self.parse_pat(refutable); hi = sub.span.hi; // HACK: parse @"..." as a literal of a vstore @str pat = alt sub.node { - pat_lit(e@@{node: expr_lit(@{node: lit_str(_), span: _}), _}) { + pat_lit(e@@{ + node: expr_lit(@{node: lit_str(_), span: _}), _ + }) => { let vst = @{id: self.get_id(), callee_id: self.get_id(), node: expr_vstore(e, vstore_box), span: mk_sp(lo, hi)}; pat_lit(vst) } - _ { pat_box(sub) } + _ => pat_box(sub) }; } - token::TILDE { + token::TILDE => { self.bump(); let sub = self.parse_pat(refutable); hi = sub.span.hi; // HACK: parse ~"..." as a literal of a vstore ~str pat = alt sub.node { - pat_lit(e@@{node: expr_lit(@{node: lit_str(_), span: _}), _}) { + pat_lit(e@@{ + node: expr_lit(@{node: lit_str(_), span: _}), _ + }) => { let vst = @{id: self.get_id(), callee_id: self.get_id(), node: expr_vstore(e, vstore_uniq), span: mk_sp(lo, hi)}; pat_lit(vst) } - _ { pat_uniq(sub) } + _ => pat_uniq(sub) }; } - token::LBRACE { + token::LBRACE => { self.bump(); let mut fields = ~[]; let mut etc = false; @@ -1722,7 +1722,7 @@ class parser { self.bump(); pat = pat_rec(fields, etc); } - token::LPAREN { + token::LPAREN => { self.bump(); if self.token == token::RPAREN { hi = self.span.hi; @@ -1742,7 +1742,7 @@ class parser { pat = pat_tup(fields); } } - tok { + tok => { if !is_ident(tok) || self.is_keyword(~"true") || self.is_keyword(~"false") { let val = self.parse_expr_res(RESTRICT_NO_BAR_OP); @@ -1789,24 +1789,22 @@ class parser { let mut args: ~[@pat] = ~[]; let mut star_pat = false; alt self.token { - token::LPAREN { - alt self.look_ahead(1u) { - token::BINOP(token::STAR) { + token::LPAREN => alt self.look_ahead(1u) { + token::BINOP(token::STAR) => { // This is a "top constructor only" pat - self.bump(); self.bump(); - star_pat = true; - self.expect(token::RPAREN); + self.bump(); self.bump(); + star_pat = true; + self.expect(token::RPAREN); } - _ { + _ => { args = self.parse_unspanned_seq( token::LPAREN, token::RPAREN, seq_sep_trailing_disallowed(token::COMMA), |p| p.parse_pat(refutable)); - hi = self.span.hi; + hi = self.span.hi; } - } } - _ { } + _ => () } // at this point, we're not sure whether it's a enum or a // bind @@ -1887,9 +1885,9 @@ class parser { } else { let mut item_attrs; alt self.parse_outer_attrs_or_ext(first_item_attrs) { - none { item_attrs = ~[]; } - some(left(attrs)) { item_attrs = attrs; } - some(right(ext)) { + none => item_attrs = ~[], + some(left(attrs)) => item_attrs = attrs, + some(right(ext)) => { return @spanned(lo, ext.span.hi, stmt_expr(ext, self.get_id())); } @@ -1898,12 +1896,12 @@ class parser { let item_attrs = vec::append(first_item_attrs, item_attrs); alt self.parse_item(item_attrs) { - some(i) { + some(i) => { let mut hi = i.span.hi; let decl = @spanned(lo, hi, decl_item(i)); return @spanned(lo, hi, stmt_decl(decl, self.get_id())); } - none() { /* fallthrough */ } + none() => { /* fallthrough */ } } check_expected_item(self, item_attrs); @@ -1990,24 +1988,24 @@ class parser { while self.token != token::RBRACE { alt self.token { - token::SEMI { + token::SEMI => { self.bump(); // empty } - _ { + _ => { let stmt = self.parse_stmt(initial_attrs); initial_attrs = ~[]; alt stmt.node { - stmt_expr(e, stmt_id) { // Expression without semicolon: + stmt_expr(e, stmt_id) => { // Expression without semicolon: alt self.token { - token::SEMI { + token::SEMI => { self.bump(); push(stmts, @{node: stmt_semi(e, stmt_id) with *stmt}); } - token::RBRACE { + token::RBRACE => { expr = some(e); } - t { + t => { if classify::stmt_ends_with_semi(*stmt) { self.fatal(~"expected `;` or `}` after \ expression but found `" @@ -2018,7 +2016,7 @@ class parser { } } - _ { // All other kinds of statements: + _ => { // All other kinds of statements: vec::push(stmts, stmt); if classify::stmt_ends_with_semi(*stmt) { @@ -2083,12 +2081,8 @@ class parser { fn is_self_ident() -> bool { alt self.token { - token::IDENT(sid, false) if ~"self" == *self.get_str(sid) { - true - } - _ => { - false - } + token::IDENT(sid, false) if ~"self" == *self.get_str(sid) => true, + _ => false } } @@ -2266,14 +2260,14 @@ class parser { fn parse_method_name() -> ident { alt copy self.token { - token::BINOP(op) { self.bump(); @token::binop_to_str(op) } - token::NOT { self.bump(); @~"!" } - token::LBRACKET { + token::BINOP(op) => { self.bump(); @token::binop_to_str(op) } + token::NOT => { self.bump(); @~"!" } + token::LBRACKET => { self.bump(); self.expect(token::RBRACKET); @~"[]" } - _ { + _ => { let id = self.parse_value_ident(); if id == @~"unary" && self.eat(token::BINOP(token::MINUS)) { @~"unary-" @@ -2388,8 +2382,8 @@ class parser { traits = ~[]; }; ident = alt ident_old { - some(name) { name } - none { self.expect_keyword(~"of"); fail; } + some(name) => name, + none => { self.expect_keyword(~"of"); fail; } }; self.expect_keyword(~"for"); ty = self.parse_ty(false); @@ -2446,13 +2440,13 @@ class parser { let mut the_dtor : option<(blk, ~[attribute], codemap::span)> = none; while self.token != token::RBRACE { alt self.parse_class_item(class_path) { - ctor_decl(a_fn_decl, attrs, blk, s) { + ctor_decl(a_fn_decl, attrs, blk, s) => { the_ctor = some((a_fn_decl, attrs, blk, s)); } - dtor_decl(blk, attrs, s) { + dtor_decl(blk, attrs, s) => { the_dtor = some((blk, attrs, s)); } - members(mms) { ms = vec::append(ms, mms); } + members(mms) => { ms = vec::append(ms, mms); } } } let actual_dtor = do option::map(the_dtor) |dtor| { @@ -2464,7 +2458,7 @@ class parser { span: d_s}}; self.bump(); alt the_ctor { - some((ct_d, ct_attrs, ct_b, ct_s)) { + some((ct_d, ct_attrs, ct_b, ct_s)) => { (class_name, item_class(ty_params, traits, ms, some({ node: {id: ctor_id, @@ -2478,7 +2472,7 @@ class parser { /* Is it strange for the parser to check this? */ - none { + none => { (class_name, item_class(ty_params, traits, ms, none, actual_dtor), none) @@ -2488,8 +2482,8 @@ class parser { fn token_is_pound_or_doc_comment(++tok: token::token) -> bool { alt tok { - token::POUND | token::DOC_COMMENT(_) { true } - _ { false } + token::POUND | token::DOC_COMMENT(_) => true, + _ => false } } @@ -2583,8 +2577,8 @@ class parser { } debug!{"parse_mod_items: parse_item(attrs=%?)", attrs}; alt self.parse_item(attrs) { - some(i) { vec::push(items, i); } - _ { + some(i) => vec::push(items, i), + _ => { self.fatal(~"expected item but found `" + token_to_str(self.reader, self.token) + ~"`"); } @@ -2765,19 +2759,19 @@ class parser { fn parse_fn_ty_proto() -> proto { alt self.token { - token::AT { + token::AT => { self.bump(); proto_box } - token::TILDE { + token::TILDE => { self.bump(); proto_uniq } - token::BINOP(token::AND) { + token::BINOP(token::AND) => { self.bump(); proto_block } - _ { + _ => { proto_block } } @@ -2785,12 +2779,8 @@ class parser { fn fn_expr_lookahead(tok: token::token) -> bool { alt tok { - token::LPAREN | token::AT | token::TILDE | token::BINOP(_) { - true - } - _ { - false - } + token::LPAREN | token::AT | token::TILDE | token::BINOP(_) => true, + _ => false } } @@ -2851,13 +2841,13 @@ class parser { self.expect(token::NOT); let id = self.parse_ident(); let tts = alt self.token { - token::LPAREN | token::LBRACE | token::LBRACKET { + token::LPAREN | token::LBRACE | token::LBRACKET => { let ket = token::flip_delimiter(self.token); self.parse_unspanned_seq(copy self.token, ket, seq_sep_none(), |p| p.parse_token_tree()) } - _ { self.fatal(~"expected open delimiter"); } + _ => self.fatal(~"expected open delimiter") }; let m = ast::mac_invoc_tt(pth, tts); let m: ast::mac = {node: m, @@ -2868,8 +2858,8 @@ class parser { } else { return none; }; some(self.mk_item(lo, self.last_span.hi, ident, item_, visibility, alt extra_attrs { - some(as) { vec::append(attrs, as) } - none { attrs } + some(as) => vec::append(attrs, as), + none => attrs })) } @@ -2885,7 +2875,7 @@ class parser { let mut path = ~[first_ident]; debug!{"parsed view_path: %s", *first_ident}; alt self.token { - token::EQ { + token::EQ => { // x = foo::bar self.bump(); path = ~[self.parse_ident()]; @@ -2900,20 +2890,20 @@ class parser { view_path_simple(first_ident, path, self.get_id())); } - token::MOD_SEP { + token::MOD_SEP => { // foo::bar or foo::{a,b,c} or foo::* while self.token == token::MOD_SEP { self.bump(); alt copy self.token { - token::IDENT(i, _) { + token::IDENT(i, _) => { self.bump(); vec::push(path, self.get_str(i)); } // foo::bar::{a,b,c} - token::LBRACE { + token::LBRACE => { let idents = self.parse_unspanned_seq( token::LBRACE, token::RBRACE, seq_sep_trailing_allowed(token::COMMA), @@ -2926,7 +2916,7 @@ class parser { } // foo::bar::* - token::BINOP(token::STAR) { + token::BINOP(token::STAR) => { self.bump(); let path = @{span: mk_sp(lo, self.span.hi), global: false, idents: path, @@ -2935,11 +2925,11 @@ class parser { view_path_glob(path, self.get_id())); } - _ { break; } + _ => break } } } - _ { } + _ => () } let last = path[vec::len(path) - 1u]; let path = @{span: mk_sp(lo, self.span.hi), global: false, @@ -3009,10 +2999,8 @@ class parser { fn parse_str() -> @~str { alt copy self.token { - token::LIT_STR(s) { self.bump(); self.get_str(s) } - _ { - self.fatal(~"expected string literal") - } + token::LIT_STR(s) => { self.bump(); self.get_str(s) } + _ => self.fatal(~"expected string literal") } } @@ -3043,13 +3031,13 @@ class parser { let id = self.parse_ident(); alt self.token { // mod x = "foo.rs"; - token::SEMI { + token::SEMI => { let mut hi = self.span.hi; self.bump(); return spanned(lo, hi, cdir_src_mod(id, outer_attrs)); } // mod x = "foo_dir" { ...directives... } - token::LBRACE { + token::LBRACE => { self.bump(); let inner_attrs = self.parse_inner_attrs_and_next(); let mod_attrs = vec::append(outer_attrs, inner_attrs.inner); @@ -3061,7 +3049,7 @@ class parser { return spanned(lo, hi, cdir_dir_mod(id, cdirs, mod_attrs)); } - _ { self.unexpected(); } + _ => self.unexpected() } } else if self.is_view_item() { let vi = self.parse_view_item(outer_attrs); diff --git a/src/libsyntax/parse/prec.rs b/src/libsyntax/parse/prec.rs index 8ea7306e180..45bbe3b8e3b 100644 --- a/src/libsyntax/parse/prec.rs +++ b/src/libsyntax/parse/prec.rs @@ -21,25 +21,25 @@ const as_prec: uint = 11u; */ fn token_to_binop(tok: token) -> option<ast::binop> { alt tok { - BINOP(STAR) { some(mul) } - BINOP(SLASH) { some(div) } - BINOP(PERCENT) { some(rem) } + BINOP(STAR) => some(mul), + BINOP(SLASH) => some(div), + BINOP(PERCENT) => some(rem), // 'as' sits between here with 11 - BINOP(PLUS) { some(add) } - BINOP(MINUS) { some(subtract) } - BINOP(SHL) { some(shl) } - BINOP(SHR) { some(shr) } - BINOP(AND) { some(bitand) } - BINOP(CARET) { some(bitxor) } - BINOP(OR) { some(bitor) } - LT { some(lt) } - LE { some(le) } - GE { some(ge) } - GT { some(gt) } - EQEQ { some(eq) } - NE { some(ne) } - ANDAND { some(and) } - OROR { some(or) } - _ { none } + BINOP(PLUS) => some(add), + BINOP(MINUS) => some(subtract), + BINOP(SHL) => some(shl), + BINOP(SHR) => some(shr), + BINOP(AND) => some(bitand), + BINOP(CARET) => some(bitxor), + BINOP(OR) => some(bitor), + LT => some(lt), + LE => some(le), + GE => some(ge), + GT => some(gt), + EQEQ => some(eq), + NE => some(ne), + ANDAND => some(and), + OROR => some(or), + _ => none } } diff --git a/src/libsyntax/parse/token.rs b/src/libsyntax/parse/token.rs index 1228926e6e4..d69ff7f1668 100644 --- a/src/libsyntax/parse/token.rs +++ b/src/libsyntax/parse/token.rs @@ -103,95 +103,100 @@ enum nonterminal { fn binop_to_str(o: binop) -> ~str { alt o { - PLUS { ~"+" } - MINUS { ~"-" } - STAR { ~"*" } - SLASH { ~"/" } - PERCENT { ~"%" } - CARET { ~"^" } - AND { ~"&" } - OR { ~"|" } - SHL { ~"<<" } - SHR { ~">>" } + PLUS => ~"+", + MINUS => ~"-", + STAR => ~"*", + SLASH => ~"/", + PERCENT => ~"%", + CARET => ~"^", + AND => ~"&", + OR => ~"|", + SHL => ~"<<", + SHR => ~">>" } } fn to_str(in: interner<@~str>, t: token) -> ~str { alt t { - EQ { ~"=" } - LT { ~"<" } - LE { ~"<=" } - EQEQ { ~"==" } - NE { ~"!=" } - GE { ~">=" } - GT { ~">" } - NOT { ~"!" } - TILDE { ~"~" } - OROR { ~"||" } - ANDAND { ~"&&" } - BINOP(op) { binop_to_str(op) } - BINOPEQ(op) { binop_to_str(op) + ~"=" } + EQ => ~"=", + LT => ~"<", + LE => ~"<=", + EQEQ => ~"==", + NE => ~"!=", + GE => ~">=", + GT => ~">", + NOT => ~"!", + TILDE => ~"~", + OROR => ~"||", + ANDAND => ~"&&", + BINOP(op) => binop_to_str(op), + BINOPEQ(op) => binop_to_str(op) + ~"=", /* Structural symbols */ - AT { ~"@" } - DOT { ~"." } - DOTDOT { ~".." } - ELLIPSIS { ~"..." } - COMMA { ~"," } - SEMI { ~";" } - COLON { ~":" } - MOD_SEP { ~"::" } - RARROW { ~"->" } - LARROW { ~"<-" } - DARROW { ~"<->" } - FAT_ARROW { ~"=>" } - LPAREN { ~"(" } - RPAREN { ~")" } - LBRACKET { ~"[" } - RBRACKET { ~"]" } - LBRACE { ~"{" } - RBRACE { ~"}" } - POUND { ~"#" } - DOLLAR { ~"$" } + AT => ~"@", + DOT => ~".", + DOTDOT => ~"..", + ELLIPSIS => ~"...", + COMMA => ~",", + SEMI => ~";", + COLON => ~":", + MOD_SEP => ~"::", + RARROW => ~"->", + LARROW => ~"<-", + DARROW => ~"<->", + FAT_ARROW => ~"=>", + LPAREN => ~"(", + RPAREN => ~")", + LBRACKET => ~"[", + RBRACKET => ~"]", + LBRACE => ~"{", + RBRACE => ~"}", + POUND => ~"#", + DOLLAR => ~"$", /* Literals */ - LIT_INT(c, ast::ty_char) { + LIT_INT(c, ast::ty_char) => { ~"'" + char::escape_default(c as char) + ~"'" } - LIT_INT(i, t) { + LIT_INT(i, t) => { int::to_str(i as int, 10u) + ast_util::int_ty_to_str(t) } - LIT_UINT(u, t) { + LIT_UINT(u, t) => { uint::to_str(u as uint, 10u) + ast_util::uint_ty_to_str(t) } - LIT_INT_UNSUFFIXED(i) { + LIT_INT_UNSUFFIXED(i) => { int::to_str(i as int, 10u) } - LIT_FLOAT(s, t) { + LIT_FLOAT(s, t) => { let mut body = *in.get(s); if body.ends_with(~".") { body = body + ~"0"; // `10.f` is not a float literal } body + ast_util::float_ty_to_str(t) } - LIT_STR(s) { ~"\"" + str::escape_default( *in.get(s)) + ~"\"" } + LIT_STR(s) => { ~"\"" + str::escape_default( *in.get(s)) + ~"\"" } /* Name components */ - IDENT(s, _) { *in.get(s) } + IDENT(s, _) => *in.get(s), - UNDERSCORE { ~"_" } + UNDERSCORE => ~"_", /* Other */ - DOC_COMMENT(s) { *in.get(s) } - EOF { ~"<eof>" } - INTERPOLATED(nt) { + DOC_COMMENT(s) => *in.get(s), + EOF => ~"<eof>", + INTERPOLATED(nt) => { ~"an interpolated " + alt nt { - nt_item(*) { ~"item" } nt_block(*) { ~"block" } - nt_stmt(*) { ~"statement" } nt_pat(*) { ~"pattern" } - nt_expr(*) { ~"expression" } nt_ty(*) { ~"type" } - nt_ident(*) { ~"identifier" } nt_path(*) { ~"path" } - nt_tt(*) { ~"tt" } nt_matchers(*) { ~"matcher sequence" } + nt_item(*) => ~"item", + nt_block(*) => ~"block", + nt_stmt(*) => ~"statement", + nt_pat(*) => ~"pattern", + nt_expr(*) => ~"expression", + nt_ty(*) => ~"type", + nt_ident(*) => ~"identifier", + nt_path(*) => ~"path", + nt_tt(*) => ~"tt", + nt_matchers(*) => ~"matcher sequence" } } } @@ -199,44 +204,44 @@ fn to_str(in: interner<@~str>, t: token) -> ~str { pure fn can_begin_expr(t: token) -> bool { alt t { - LPAREN { true } - LBRACE { true } - LBRACKET { true } - IDENT(_, _) { true } - UNDERSCORE { true } - TILDE { true } - LIT_INT(_, _) { true } - LIT_UINT(_, _) { true } - LIT_INT_UNSUFFIXED(_) { true } - LIT_FLOAT(_, _) { true } - LIT_STR(_) { true } - POUND { true } - AT { true } - NOT { true } - BINOP(MINUS) { true } - BINOP(STAR) { true } - BINOP(AND) { true } - BINOP(OR) { true } // in lambda syntax - OROR { true } // in lambda syntax - MOD_SEP { true } + LPAREN => true, + LBRACE => true, + LBRACKET => true, + IDENT(_, _) => true, + UNDERSCORE => true, + TILDE => true, + LIT_INT(_, _) => true, + LIT_UINT(_, _) => true, + LIT_INT_UNSUFFIXED(_) => true, + LIT_FLOAT(_, _) => true, + LIT_STR(_) => true, + POUND => true, + AT => true, + NOT => true, + BINOP(MINUS) => true, + BINOP(STAR) => true, + BINOP(AND) => true, + BINOP(OR) => true, // in lambda syntax + OROR => true, // in lambda syntax + MOD_SEP => true, INTERPOLATED(nt_expr(*)) | INTERPOLATED(nt_ident(*)) | INTERPOLATED(nt_block(*)) - | INTERPOLATED(nt_path(*)) { true } - _ { false } + | INTERPOLATED(nt_path(*)) => true, + _ => false } } /// what's the opposite delimiter? fn flip_delimiter(&t: token::token) -> token::token { alt t { - token::LPAREN { token::RPAREN } - token::LBRACE { token::RBRACE } - token::LBRACKET { token::RBRACKET } - token::RPAREN { token::LPAREN } - token::RBRACE { token::LBRACE } - token::RBRACKET { token::LBRACKET } - _ { fail } + token::LPAREN => token::RPAREN, + token::LBRACE => token::RBRACE, + token::LBRACKET => token::RBRACKET, + token::RPAREN => token::LPAREN, + token::RBRACE => token::LBRACE, + token::RBRACKET => token::LBRACKET, + _ => fail } } @@ -244,25 +249,25 @@ fn flip_delimiter(&t: token::token) -> token::token { fn is_lit(t: token) -> bool { alt t { - LIT_INT(_, _) { true } - LIT_UINT(_, _) { true } - LIT_INT_UNSUFFIXED(_) { true } - LIT_FLOAT(_, _) { true } - LIT_STR(_) { true } - _ { false } + LIT_INT(_, _) => true, + LIT_UINT(_, _) => true, + LIT_INT_UNSUFFIXED(_) => true, + LIT_FLOAT(_, _) => true, + LIT_STR(_) => true, + _ => false } } pure fn is_ident(t: token) -> bool { - alt t { IDENT(_, _) { true } _ { false } } + alt t { IDENT(_, _) => true, _ => false } } pure fn is_plain_ident(t: token) -> bool { - alt t { IDENT(_, false) { true } _ { false } } + alt t { IDENT(_, false) => true, _ => false } } pure fn is_bar(t: token) -> bool { - alt t { BINOP(OR) | OROR { true } _ { false } } + alt t { BINOP(OR) | OROR => true, _ => false } } /** diff --git a/src/libsyntax/print/pp.rs b/src/libsyntax/print/pp.rs index 2d1a418f831..12ef7149f6b 100644 --- a/src/libsyntax/print/pp.rs +++ b/src/libsyntax/print/pp.rs @@ -63,11 +63,11 @@ enum token { STRING(@~str, int), BREAK(break_t), BEGIN(begin_t), END, EOF, } fn tok_str(++t: token) -> ~str { alt t { - STRING(s, len) { return fmt!{"STR(%s,%d)", *s, len}; } - BREAK(_) { return ~"BREAK"; } - BEGIN(_) { return ~"BEGIN"; } - END { return ~"END"; } - EOF { return ~"EOF"; } + STRING(s, len) => return fmt!{"STR(%s,%d)", *s, len}, + BREAK(_) => return ~"BREAK", + BEGIN(_) => return ~"BEGIN", + END => return ~"END", + EOF => return ~"EOF" } } @@ -239,7 +239,7 @@ impl printer for printer { fn pretty_print(t: token) { debug!{"pp ~[%u,%u]", self.left, self.right}; alt t { - EOF { + EOF => { if !self.scan_stack_empty { self.check_stack(0); self.advance_left(self.token[self.left], @@ -247,7 +247,7 @@ impl printer for printer { } self.indent(0); } - BEGIN(b) { + BEGIN(b) => { if self.scan_stack_empty { self.left_total = 1; self.right_total = 1; @@ -259,7 +259,7 @@ impl printer for printer { self.size[self.right] = -self.right_total; self.scan_push(self.right); } - END { + END => { if self.scan_stack_empty { debug!{"pp END/print ~[%u,%u]", self.left, self.right}; self.print(t, 0); @@ -271,7 +271,7 @@ impl printer for printer { self.scan_push(self.right); } } - BREAK(b) { + BREAK(b) => { if self.scan_stack_empty { self.left_total = 1; self.right_total = 1; @@ -285,7 +285,7 @@ impl printer for printer { self.size[self.right] = -self.right_total; self.right_total += b.blank_space; } - STRING(s, len) { + STRING(s, len) => { if self.scan_stack_empty { debug!{"pp STRING/print ~[%u,%u]", self.left, self.right}; self.print(t, len); @@ -358,9 +358,9 @@ impl printer for printer { if L >= 0 { self.print(x, L); alt x { - BREAK(b) { self.left_total += b.blank_space; } - STRING(_, len) { assert (len == L); self.left_total += len; } - _ { } + BREAK(b) => self.left_total += b.blank_space, + STRING(_, len) => { assert (len == L); self.left_total += len; } + _ => () } if self.left != self.right { self.left += 1u; @@ -374,19 +374,19 @@ impl printer for printer { if !self.scan_stack_empty { let x = self.scan_top(); alt copy self.token[x] { - BEGIN(b) { + BEGIN(b) => { if k > 0 { self.size[self.scan_pop()] = self.size[x] + self.right_total; self.check_stack(k - 1); } } - END { + END => { // paper says + not =, but that makes no sense. self.size[self.scan_pop()] = 1; self.check_stack(k + 1); } - _ { + _ => { self.size[self.scan_pop()] = self.size[x] + self.right_total; if k > 0 { self.check_stack(k); } } @@ -423,7 +423,7 @@ impl printer for printer { self.space}; log(debug, buf_str(self.token, self.size, self.left, self.right, 6u)); alt x { - BEGIN(b) { + BEGIN(b) => { if L > self.space { let col = self.margin - self.space + b.offset; debug!{"print BEGIN -> push broken block at col %d", col}; @@ -435,25 +435,25 @@ impl printer for printer { pbreak: fits}); } } - END { + END => { debug!{"print END -> pop END"}; assert (self.print_stack.len() != 0u); self.print_stack.pop(); } - BREAK(b) { + BREAK(b) => { let top = self.get_top(); alt top.pbreak { - fits { + fits => { debug!{"print BREAK in fitting block"}; self.space -= b.blank_space; self.indent(b.blank_space); } - broken(consistent) { + broken(consistent) => { debug!{"print BREAK in consistent block"}; self.print_newline(top.offset + b.offset); self.space = self.margin - (top.offset + b.offset); } - broken(inconsistent) { + broken(inconsistent) => { if L > self.space { debug!{"print BREAK w/ newline in inconsistent"}; self.print_newline(top.offset + b.offset); @@ -466,14 +466,14 @@ impl printer for printer { } } } - STRING(s, len) { + STRING(s, len) => { debug!{"print STRING"}; assert (L == len); // assert L <= space; self.space -= len; self.print_str(*s); } - EOF { + EOF => { // EOF should never get here. fail; } diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index eaacf6cd424..c81b8b5335f 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -222,11 +222,11 @@ fn bclose_(s: ps, span: codemap::span, indented: uint) { fn bclose(s: ps, span: codemap::span) { bclose_(s, span, indent_unit); } fn is_begin(s: ps) -> bool { - alt s.s.last_token() { pp::BEGIN(_) { true } _ { false } } + alt s.s.last_token() { pp::BEGIN(_) => true, _ => false } } fn is_end(s: ps) -> bool { - alt s.s.last_token() { pp::END { true } _ { false } } + alt s.s.last_token() { pp::END => true, _ => false } } fn is_bol(s: ps) -> bool { @@ -319,8 +319,8 @@ fn print_foreign_mod(s: ps, nmod: ast::foreign_mod, fn print_region(s: ps, region: @ast::region) { alt region.node { - ast::re_anon { word_space(s, ~"&"); } - ast::re_named(name) { + ast::re_anon => word_space(s, ~"&"), + ast::re_named(name) => { word(s.s, ~"&"); word(s.s, *name); } @@ -335,29 +335,29 @@ fn print_type_ex(s: ps, &&ty: @ast::ty, print_colons: bool) { maybe_print_comment(s, ty.span.lo); ibox(s, 0u); alt ty.node { - ast::ty_nil { word(s.s, ~"()"); } - ast::ty_bot { word(s.s, ~"!"); } - ast::ty_box(mt) { word(s.s, ~"@"); print_mt(s, mt); } - ast::ty_uniq(mt) { word(s.s, ~"~"); print_mt(s, mt); } - ast::ty_vec(mt) { + ast::ty_nil => word(s.s, ~"()"), + ast::ty_bot => word(s.s, ~"!"), + ast::ty_box(mt) => { word(s.s, ~"@"); print_mt(s, mt); } + ast::ty_uniq(mt) => { word(s.s, ~"~"); print_mt(s, mt); } + ast::ty_vec(mt) => { word(s.s, ~"["); alt mt.mutbl { - ast::m_mutbl { word_space(s, ~"mut"); } - ast::m_const { word_space(s, ~"const"); } - ast::m_imm { } + ast::m_mutbl => word_space(s, ~"mut"), + ast::m_const => word_space(s, ~"const"), + ast::m_imm => () } print_type(s, mt.ty); word(s.s, ~"]"); } - ast::ty_ptr(mt) { word(s.s, ~"*"); print_mt(s, mt); } - ast::ty_rptr(region, mt) { + ast::ty_ptr(mt) => { word(s.s, ~"*"); print_mt(s, mt); } + ast::ty_rptr(region, mt) => { alt region.node { - ast::re_anon { word(s.s, ~"&"); } - _ { print_region(s, region); word(s.s, ~"/"); } + ast::re_anon => word(s.s, ~"&"), + _ => { print_region(s, region); word(s.s, ~"/"); } } print_mt(s, mt); } - ast::ty_rec(fields) { + ast::ty_rec(fields) => { word(s.s, ~"{"); fn print_field(s: ps, f: ast::ty_field) { cbox(s, indent_unit); @@ -371,24 +371,24 @@ fn print_type_ex(s: ps, &&ty: @ast::ty, print_colons: bool) { commasep_cmnt(s, consistent, fields, print_field, get_span); word(s.s, ~",}"); } - ast::ty_tup(elts) { + ast::ty_tup(elts) => { popen(s); commasep(s, inconsistent, elts, print_type); pclose(s); } - ast::ty_fn(proto, d) { + ast::ty_fn(proto, d) => { print_ty_fn(s, some(proto), d, none, none); } - ast::ty_path(path, _) { print_path(s, path, print_colons); } - ast::ty_fixed_length(t, v) { + ast::ty_path(path, _) => print_path(s, path, print_colons), + ast::ty_fixed_length(t, v) => { print_type(s, t); word(s.s, ~"/"); print_vstore(s, ast::vstore_fixed(v)); } - ast::ty_mac(_) { + ast::ty_mac(_) => { fail ~"print_type doesn't know how to print a ty_mac"; } - ast::ty_infer { + ast::ty_infer => { fail ~"print_type shouldn't see a ty_infer"; } @@ -401,7 +401,7 @@ fn print_foreign_item(s: ps, item: @ast::foreign_item) { maybe_print_comment(s, item.span.lo); print_outer_attributes(s, item.attrs); alt item.node { - ast::foreign_item_fn(decl, typarams) { + ast::foreign_item_fn(decl, typarams) => { print_fn(s, decl, item.ident, typarams); end(s); // end head-ibox word(s.s, ~";"); @@ -417,7 +417,7 @@ fn print_item(s: ps, &&item: @ast::item) { let ann_node = node_item(s, item); s.ann.pre(ann_node); alt item.node { - ast::item_const(ty, expr) { + ast::item_const(ty, expr) => { head(s, ~"const"); word_space(s, *item.ident + ~":"); print_type(s, ty); @@ -430,19 +430,19 @@ fn print_item(s: ps, &&item: @ast::item) { end(s); // end the outer cbox } - ast::item_fn(decl, typarams, body) { + ast::item_fn(decl, typarams, body) => { print_fn(s, decl, item.ident, typarams); word(s.s, ~" "); print_block_with_attrs(s, body, item.attrs); } - ast::item_mod(_mod) { + ast::item_mod(_mod) => { head(s, ~"mod"); word_nbsp(s, *item.ident); bopen(s); print_mod(s, _mod, item.attrs); bclose(s, item.span); } - ast::item_foreign_mod(nmod) { + ast::item_foreign_mod(nmod) => { head(s, ~"extern"); word_nbsp(s, ~"mod"); word_nbsp(s, *item.ident); @@ -450,7 +450,7 @@ fn print_item(s: ps, &&item: @ast::item) { print_foreign_mod(s, nmod, item.attrs); bclose(s, item.span); } - ast::item_ty(ty, params) { + ast::item_ty(ty, params) => { ibox(s, indent_unit); ibox(s, 0u); word_nbsp(s, ~"type"); @@ -464,7 +464,7 @@ fn print_item(s: ps, &&item: @ast::item) { word(s.s, ~";"); end(s); // end the outer ibox } - ast::item_enum(variants, params) { + ast::item_enum(variants, params) => { let newtype = vec::len(variants) == 1u && str::eq(item.ident, variants[0].node.name) && @@ -497,7 +497,7 @@ fn print_item(s: ps, &&item: @ast::item) { bclose(s, item.span); } } - ast::item_class(tps, traits, items, m_ctor, m_dtor) { + ast::item_class(tps, traits, items, m_ctor, m_dtor) => { head(s, ~"class"); word_nbsp(s, *item.ident); print_type_params(s, tps); @@ -539,37 +539,37 @@ fn print_item(s: ps, &&item: @ast::item) { maybe_print_comment(s, ci.span.lo); let pr = ast_util::class_member_visibility(ci); alt pr { - ast::private { + ast::private => { head(s, ~"priv"); bopen(s); hardbreak_if_not_bol(s); } - _ {} + _ => () } alt ci.node { - ast::instance_var(nm, t, mt, _,_) { + ast::instance_var(nm, t, mt, _,_) => { word_nbsp(s, ~"let"); alt mt { - ast::class_mutable { word_nbsp(s, ~"mut"); } - _ {} + ast::class_mutable => word_nbsp(s, ~"mut"), + _ => () } word(s.s, *nm); word_nbsp(s, ~":"); print_type(s, t); word(s.s, ~";"); } - ast::class_method(m) { + ast::class_method(m) => { print_method(s, m); } } alt pr { - ast::private { bclose(s, ci.span); } - _ {} + ast::private => bclose(s, ci.span), + _ => () } } bclose(s, item.span); } - ast::item_impl(tps, traits, ty, methods) { + ast::item_impl(tps, traits, ty, methods) => { head(s, ~"impl"); word(s.s, *item.ident); print_type_params(s, tps); @@ -590,7 +590,7 @@ fn print_item(s: ps, &&item: @ast::item) { } bclose(s, item.span); } - ast::item_trait(tps, traits, methods) { + ast::item_trait(tps, traits, methods) => { head(s, ~"trait"); word(s.s, *item.ident); print_type_params(s, tps); @@ -604,13 +604,13 @@ fn print_item(s: ps, &&item: @ast::item) { for methods.each |meth| { print_trait_method(s, meth); } bclose(s, item.span); } - ast::item_mac({node: ast::mac_invoc_tt(pth, tts), _}) { + ast::item_mac({node: ast::mac_invoc_tt(pth, tts), _}) => { head(s, path_to_str(pth) + ~"! " + *item.ident); bopen(s); for tts.each |tt| { print_tt(s, tt); } bclose(s, item.span); } - ast::item_mac(_) { + ast::item_mac(_) => { fail ~"invalid item-position syntax bit" } } @@ -626,31 +626,29 @@ fn print_item(s: ps, &&item: @ast::item) { /// expression arguments as expressions). It can be done! I think. fn print_tt(s: ps, tt: ast::token_tree) { alt tt { - ast::tt_delim(tts) { - for tts.each() |tt_elt| { print_tt(s, tt_elt); } - } - ast::tt_tok(_, tk) { + ast::tt_delim(tts) => for tts.each() |tt_elt| { print_tt(s, tt_elt); } + ast::tt_tok(_, tk) => { alt tk { - parse::token::IDENT(*) { // don't let idents run together + parse::token::IDENT(*) => { // don't let idents run together if s.s.token_tree_last_was_ident { word(s.s, ~" ") } s.s.token_tree_last_was_ident = true; } - _ { s.s.token_tree_last_was_ident = false; } + _ => { s.s.token_tree_last_was_ident = false; } } word(s.s, parse::token::to_str(*s.intr, tk)); } - ast::tt_seq(_, tts, sep, zerok) { + ast::tt_seq(_, tts, sep, zerok) => { word(s.s, ~"$("); for tts.each() |tt_elt| { print_tt(s, tt_elt); } word(s.s, ~")"); alt sep { - some(tk) { word(s.s, parse::token::to_str(*s.intr, tk)); } - none {} + some(tk) => word(s.s, parse::token::to_str(*s.intr, tk)), + none => () } word(s.s, if zerok { ~"*" } else { ~"+" }); s.s.token_tree_last_was_ident = false; } - ast::tt_nonterminal(_, name) { + ast::tt_nonterminal(_, name) => { word(s.s, ~"$" + *name); s.s.token_tree_last_was_ident = true; } @@ -668,12 +666,12 @@ fn print_variant(s: ps, v: ast::variant) { pclose(s); } alt v.node.disr_expr { - some(d) { + some(d) => { space(s.s); word_space(s, ~"="); print_expr(s, d); } - _ {} + _ => () } } @@ -687,8 +685,8 @@ fn print_ty_method(s: ps, m: ast::ty_method) { fn print_trait_method(s: ps, m: ast::trait_method) { alt m { - required(ty_m) { print_ty_method(s, ty_m) } - provided(m) { print_method(s, m) } + required(ty_m) => print_ty_method(s, ty_m), + provided(m) => print_method(s, m) } } @@ -705,8 +703,8 @@ fn print_outer_attributes(s: ps, attrs: ~[ast::attribute]) { let mut count = 0; for attrs.each |attr| { alt attr.node.style { - ast::attr_outer { print_attribute(s, attr); count += 1; } - _ {/* fallthrough */ } + ast::attr_outer => { print_attribute(s, attr); count += 1; } + _ => {/* fallthrough */ } } } if count > 0 { hardbreak_if_not_bol(s); } @@ -716,14 +714,14 @@ fn print_inner_attributes(s: ps, attrs: ~[ast::attribute]) { let mut count = 0; for attrs.each |attr| { alt attr.node.style { - ast::attr_inner { + ast::attr_inner => { print_attribute(s, attr); if !attr.node.is_sugared_doc { word(s.s, ~";"); } count += 1; } - _ {/* fallthrough */ } + _ => {/* fallthrough */ } } } if count > 0 { hardbreak_if_not_bol(s); } @@ -747,14 +745,14 @@ fn print_attribute(s: ps, attr: ast::attribute) { fn print_stmt(s: ps, st: ast::stmt) { maybe_print_comment(s, st.span.lo); alt st.node { - ast::stmt_decl(decl, _) { + ast::stmt_decl(decl, _) => { print_decl(s, decl); } - ast::stmt_expr(expr, _) { + ast::stmt_expr(expr, _) => { space_if_not_bol(s); print_expr(s, expr); } - ast::stmt_semi(expr, _) { + ast::stmt_semi(expr, _) => { space_if_not_bol(s); print_expr(s, expr); word(s.s, ~";"); @@ -783,16 +781,16 @@ fn print_possibly_embedded_block(s: ps, blk: ast::blk, embedded: embed_type, fn print_possibly_embedded_block_(s: ps, blk: ast::blk, embedded: embed_type, indented: uint, attrs: ~[ast::attribute]) { alt blk.node.rules { - ast::unchecked_blk { word(s.s, ~"unchecked"); } - ast::unsafe_blk { word(s.s, ~"unsafe"); } - ast::default_blk { } + ast::unchecked_blk => word(s.s, ~"unchecked"), + ast::unsafe_blk => word(s.s, ~"unsafe"), + ast::default_blk => () } maybe_print_comment(s, blk.span.lo); let ann_node = node_block(s, blk); s.ann.pre(ann_node); alt embedded { - block_block_fn { end(s); } - block_normal { bopen(s); } + block_block_fn => end(s), + block_normal => bopen(s) } print_inner_attributes(s, attrs); @@ -802,12 +800,12 @@ fn print_possibly_embedded_block_(s: ps, blk: ast::blk, embedded: embed_type, print_stmt(s, *st); } alt blk.node.expr { - some(expr) { + some(expr) => { space_if_not_bol(s); print_expr(s, expr); maybe_print_trailing_comment(s, expr.span, some(blk.span.hi)); } - _ { } + _ => () } bclose_(s, blk.span, indented); s.ann.post(ann_node); @@ -817,8 +815,8 @@ fn print_possibly_embedded_block_(s: ps, blk: ast::blk, embedded: embed_type, // alt, do, & while unambiguously without being parenthesized fn print_maybe_parens_discrim(s: ps, e: @ast::expr) { let disambig = alt e.node { - ast::expr_ret(none) | ast::expr_fail(none) { true } - _ { false } + ast::expr_ret(none) | ast::expr_fail(none) => true, + _ => false }; if disambig { popen(s); } print_expr(s, e); @@ -834,10 +832,10 @@ fn print_if(s: ps, test: @ast::expr, blk: ast::blk, print_block(s, blk); fn do_else(s: ps, els: option<@ast::expr>) { alt els { - some(_else) { + some(_else) => { alt _else.node { // "another else-if" - ast::expr_if(i, t, e) { + ast::expr_if(i, t, e) => { cbox(s, indent_unit - 1u); ibox(s, 0u); word(s.s, ~" else if "); @@ -847,19 +845,19 @@ fn print_if(s: ps, test: @ast::expr, blk: ast::blk, do_else(s, e); } // "final else" - ast::expr_block(b) { + ast::expr_block(b) => { cbox(s, indent_unit - 1u); ibox(s, 0u); word(s.s, ~" else "); print_block(s, b); } // BLEAH, constraints would be great here - _ { + _ => { fail ~"print_if saw if with weird alternative"; } } } - _ {/* fall through */ } + _ => {/* fall through */ } } } do_else(s, elseopt); @@ -867,45 +865,43 @@ fn print_if(s: ps, test: @ast::expr, blk: ast::blk, fn print_mac(s: ps, m: ast::mac) { alt m.node { - ast::mac_invoc(path, arg, body) { + ast::mac_invoc(path, arg, body) => { word(s.s, ~"#"); print_path(s, path, false); alt arg { - some(@{node: ast::expr_vec(_, _), _}) { } - _ { word(s.s, ~" "); } + some(@{node: ast::expr_vec(_, _), _}) => (), + _ => word(s.s, ~" ") } option::iter(arg, |a| print_expr(s, a)); // FIXME: extension 'body' (#2339) } - ast::mac_invoc_tt(pth, tts) { + ast::mac_invoc_tt(pth, tts) => { head(s, path_to_str(pth) + ~"!"); bopen(s); for tts.each() |tt| { print_tt(s, tt); } bclose(s, m.span); } - ast::mac_ellipsis { word(s.s, ~"..."); } - ast::mac_var(v) { word(s.s, fmt!{"$%u", v}); } - _ { /* fixme */ } + ast::mac_ellipsis => word(s.s, ~"..."), + ast::mac_var(v) => word(s.s, fmt!{"$%u", v}), + _ => { /* fixme */ } } } fn print_vstore(s: ps, t: ast::vstore) { alt t { - ast::vstore_fixed(some(i)) { word(s.s, fmt!{"%u", i}); } - ast::vstore_fixed(none) { word(s.s, ~"_"); } - ast::vstore_uniq { word(s.s, ~"~"); } - ast::vstore_box { word(s.s, ~"@"); } - ast::vstore_slice(r) { - alt r.node { - ast::re_anon { word(s.s, ~"&"); } - ast::re_named(name) { - word(s.s, ~"&"); - word(s.s, *name); - word(s.s, ~"."); - } - } + ast::vstore_fixed(some(i)) => word(s.s, fmt!{"%u", i}), + ast::vstore_fixed(none) => word(s.s, ~"_"), + ast::vstore_uniq => word(s.s, ~"~"), + ast::vstore_box => word(s.s, ~"@"), + ast::vstore_slice(r) => alt r.node { + ast::re_anon => word(s.s, ~"&"), + ast::re_named(name) => { + word(s.s, ~"&"); + word(s.s, *name); + word(s.s, ~"."); + } } - } + } } fn print_expr(s: ps, &&expr: @ast::expr) { @@ -924,20 +920,18 @@ fn print_expr(s: ps, &&expr: @ast::expr) { let ann_node = node_expr(s, expr); s.ann.pre(ann_node); alt expr.node { - ast::expr_vstore(e, v) { - alt v { - ast::vstore_fixed(_) { + ast::expr_vstore(e, v) => alt v { + ast::vstore_fixed(_) => { print_expr(s, e); - word(s.s, ~"/"); - print_vstore(s, v); + word(s.s, ~"/"); + print_vstore(s, v); } - _ { + _ => { print_vstore(s, v); - print_expr(s, e); + print_expr(s, e); } - } } - ast::expr_vec(exprs, mutbl) { + ast::expr_vec(exprs, mutbl) => { ibox(s, indent_unit); word(s.s, ~"["); if mutbl == ast::m_mutbl { @@ -964,41 +958,41 @@ fn print_expr(s: ps, &&expr: @ast::expr) { end(s); } - ast::expr_rec(fields, wth) { + ast::expr_rec(fields, wth) => { word(s.s, ~"{"); commasep_cmnt(s, consistent, fields, print_field, get_span); alt wth { - some(expr) { + some(expr) => { if vec::len(fields) > 0u { space(s.s); } ibox(s, indent_unit); word_space(s, ~"with"); print_expr(s, expr); end(s); } - _ { word(s.s, ~","); } + _ => word(s.s, ~",") } word(s.s, ~"}"); } - ast::expr_struct(path, fields) { + ast::expr_struct(path, fields) => { print_path(s, path, true); word(s.s, ~"{"); commasep_cmnt(s, consistent, fields, print_field, get_span); word(s.s, ~","); word(s.s, ~"}"); } - ast::expr_tup(exprs) { + ast::expr_tup(exprs) => { popen(s); commasep_exprs(s, inconsistent, exprs); pclose(s); } - ast::expr_call(func, args, has_block) { + ast::expr_call(func, args, has_block) => { let mut base_args = args; let blk = if has_block { let blk_arg = vec::pop(base_args); alt blk_arg.node { - ast::expr_loop_body(_) { word_nbsp(s, ~"for"); } - ast::expr_do_body(_) { word_nbsp(s, ~"do"); } - _ {} + ast::expr_loop_body(_) => word_nbsp(s, ~"for"), + ast::expr_do_body(_) => word_nbsp(s, ~"do"), + _ => () } some(blk_arg) } else { none }; @@ -1013,44 +1007,44 @@ fn print_expr(s: ps, &&expr: @ast::expr) { print_expr(s, option::get(blk)); } } - ast::expr_binary(op, lhs, rhs) { + ast::expr_binary(op, lhs, rhs) => { let prec = operator_prec(op); print_op_maybe_parens(s, lhs, prec); space(s.s); word_space(s, ast_util::binop_to_str(op)); print_op_maybe_parens(s, rhs, prec + 1u); } - ast::expr_unary(op, expr) { + ast::expr_unary(op, expr) => { word(s.s, ast_util::unop_to_str(op)); print_op_maybe_parens(s, expr, parse::prec::unop_prec); } - ast::expr_addr_of(m, expr) { + ast::expr_addr_of(m, expr) => { word(s.s, ~"&"); print_mutability(s, m); print_expr(s, expr); } - ast::expr_lit(lit) { print_literal(s, lit); } - ast::expr_cast(expr, ty) { + ast::expr_lit(lit) => print_literal(s, lit), + ast::expr_cast(expr, ty) => { print_op_maybe_parens(s, expr, parse::prec::as_prec); space(s.s); word_space(s, ~"as"); print_type_ex(s, ty, true); } - ast::expr_if(test, blk, elseopt) { + ast::expr_if(test, blk, elseopt) => { print_if(s, test, blk, elseopt, false); } - ast::expr_while(test, blk) { + ast::expr_while(test, blk) => { head(s, ~"while"); print_maybe_parens_discrim(s, test); space(s.s); print_block(s, blk); } - ast::expr_loop(blk) { + ast::expr_loop(blk) => { head(s, ~"loop"); space(s.s); print_block(s, blk); } - ast::expr_alt(expr, arms, mode) { + ast::expr_alt(expr, arms, mode) => { cbox(s, alt_indent_unit); ibox(s, 4u); word_nbsp(s, ~"alt"); @@ -1072,8 +1066,12 @@ fn print_expr(s: ps, &&expr: @ast::expr) { } space(s.s); alt arm.guard { - some(e) { word_space(s, ~"if"); print_expr(s, e); space(s.s); } - none { } + some(e) => { + word_space(s, ~"if"); + print_expr(s, e); + space(s.s); + } + none => () } word_space(s, ~"=>"); // Extract the expression from the extra block the parser adds @@ -1095,7 +1093,7 @@ fn print_expr(s: ps, &&expr: @ast::expr) { } bclose_(s, expr.span, alt_indent_unit); } - ast::expr_fn(proto, decl, body, cap_clause) { + ast::expr_fn(proto, decl, body, cap_clause) => { // containing cbox, will be closed by print-block at } cbox(s, indent_unit); // head-box, will be closed by print-block at start @@ -1106,7 +1104,7 @@ fn print_expr(s: ps, &&expr: @ast::expr) { space(s.s); print_block(s, body); } - ast::expr_fn_block(decl, body, cap_clause) { + ast::expr_fn_block(decl, body, cap_clause) => { print_fn_block_args(s, decl, *cap_clause); // The parser always adds an extra implicit block around lambdas assert body.node.stmts.is_empty(); @@ -1114,47 +1112,47 @@ fn print_expr(s: ps, &&expr: @ast::expr) { space(s.s); print_expr(s, body.node.expr.get()); } - ast::expr_loop_body(body) { + ast::expr_loop_body(body) => { print_expr(s, body); } - ast::expr_do_body(body) { + ast::expr_do_body(body) => { print_expr(s, body); } - ast::expr_block(blk) { + ast::expr_block(blk) => { // containing cbox, will be closed by print-block at } cbox(s, indent_unit); // head-box, will be closed by print-block after { ibox(s, 0u); print_block(s, blk); } - ast::expr_copy(e) { word_space(s, ~"copy"); print_expr(s, e); } - ast::expr_unary_move(e) { word_space(s, ~"move"); print_expr(s, e); } - ast::expr_move(lhs, rhs) { + ast::expr_copy(e) => { word_space(s, ~"copy"); print_expr(s, e); } + ast::expr_unary_move(e) => { word_space(s, ~"move"); print_expr(s, e); } + ast::expr_move(lhs, rhs) => { print_expr(s, lhs); space(s.s); word_space(s, ~"<-"); print_expr(s, rhs); } - ast::expr_assign(lhs, rhs) { + ast::expr_assign(lhs, rhs) => { print_expr(s, lhs); space(s.s); word_space(s, ~"="); print_expr(s, rhs); } - ast::expr_swap(lhs, rhs) { + ast::expr_swap(lhs, rhs) => { print_expr(s, lhs); space(s.s); word_space(s, ~"<->"); print_expr(s, rhs); } - ast::expr_assign_op(op, lhs, rhs) { + ast::expr_assign_op(op, lhs, rhs) => { print_expr(s, lhs); space(s.s); word(s.s, ast_util::binop_to_str(op)); word_space(s, ~"="); print_expr(s, rhs); } - ast::expr_field(expr, id, tys) { + ast::expr_field(expr, id, tys) => { // Deal with '10.x' if ends_in_lit_int(expr) { popen(s); print_expr(s, expr); pclose(s); @@ -1169,34 +1167,34 @@ fn print_expr(s: ps, &&expr: @ast::expr) { word(s.s, ~">"); } } - ast::expr_index(expr, index) { + ast::expr_index(expr, index) => { print_expr_parens_if_not_bot(s, expr); word(s.s, ~"["); print_expr(s, index); word(s.s, ~"]"); } - ast::expr_path(path) { print_path(s, path, true); } - ast::expr_fail(maybe_fail_val) { + ast::expr_path(path) => print_path(s, path, true), + ast::expr_fail(maybe_fail_val) => { word(s.s, ~"fail"); alt maybe_fail_val { - some(expr) { word(s.s, ~" "); print_expr(s, expr); } - _ { } + some(expr) => { word(s.s, ~" "); print_expr(s, expr); } + _ => () } } - ast::expr_break { word(s.s, ~"break"); } - ast::expr_again { word(s.s, ~"again"); } - ast::expr_ret(result) { + ast::expr_break => word(s.s, ~"break"), + ast::expr_again => word(s.s, ~"again"), + ast::expr_ret(result) => { word(s.s, ~"return"); alt result { - some(expr) { word(s.s, ~" "); print_expr(s, expr); } - _ { } + some(expr) => { word(s.s, ~" "); print_expr(s, expr); } + _ => () } } - ast::expr_log(lvl, lexp, expr) { + ast::expr_log(lvl, lexp, expr) => { alt check lvl { - 1 { word_nbsp(s, ~"log"); print_expr(s, expr); } - 0 { word_nbsp(s, ~"log_err"); print_expr(s, expr); } - 2 { + 1 => { word_nbsp(s, ~"log"); print_expr(s, expr); } + 0 => { word_nbsp(s, ~"log_err"); print_expr(s, expr); } + 2 => { word_nbsp(s, ~"log"); popen(s); print_expr(s, lexp); @@ -1207,11 +1205,11 @@ fn print_expr(s: ps, &&expr: @ast::expr) { } } } - ast::expr_assert(expr) { + ast::expr_assert(expr) => { word_nbsp(s, ~"assert"); print_expr(s, expr); } - ast::expr_mac(m) { print_mac(s, m); } + ast::expr_mac(m) => print_mac(s, m), } s.ann.post(ann_node); end(s); @@ -1226,8 +1224,8 @@ fn print_expr_parens_if_not_bot(s: ps, ex: @ast::expr) { ast::expr_assign_op(_, _, _) | ast::expr_swap(_, _) | ast::expr_log(_, _, _) | ast::expr_assert(_) | ast::expr_call(_, _, true) | - ast::expr_vstore(_, _) { true } - _ { false } + ast::expr_vstore(_, _) => true, + _ => false }; if parens { popen(s); } print_expr(s, ex); @@ -1237,15 +1235,15 @@ fn print_expr_parens_if_not_bot(s: ps, ex: @ast::expr) { fn print_local_decl(s: ps, loc: @ast::local) { print_pat(s, loc.node.pat); alt loc.node.ty.node { - ast::ty_infer { } - _ { word_space(s, ~":"); print_type(s, loc.node.ty); } + ast::ty_infer => (), + _ => { word_space(s, ~":"); print_type(s, loc.node.ty); } } } fn print_decl(s: ps, decl: @ast::decl) { maybe_print_comment(s, decl.span.lo); alt decl.node { - ast::decl_local(locs) { + ast::decl_local(locs) => { space_if_not_bol(s); ibox(s, indent_unit); word_nbsp(s, ~"let"); @@ -1261,21 +1259,21 @@ fn print_decl(s: ps, decl: @ast::decl) { print_local_decl(s, loc); end(s); alt loc.node.init { - some(init) { + some(init) => { nbsp(s); alt init.op { - ast::init_assign { word_space(s, ~"="); } - ast::init_move { word_space(s, ~"<-"); } + ast::init_assign => word_space(s, ~"="), + ast::init_move => word_space(s, ~"<-") } print_expr(s, init.expr); } - _ { } + _ => () } } commasep(s, consistent, locs, print_local); end(s); } - ast::decl_item(item) { print_item(s, item); } + ast::decl_item(item) => print_item(s, item) } } @@ -1300,8 +1298,8 @@ fn print_path(s: ps, &&path: @ast::path, colons_before_params: bool) { if colons_before_params { word(s.s, ~"::"); } alt path.rp { - none { /* ok */ } - some(r) { + none => { /* ok */ } + some(r) => { word(s.s, ~"/"); print_region(s, r); } @@ -1322,23 +1320,23 @@ fn print_pat(s: ps, &&pat: @ast::pat) { /* Pat isn't normalized, but the beauty of it is that it doesn't matter */ alt pat.node { - ast::pat_wild { word(s.s, ~"_"); } - ast::pat_ident(binding_mode, path, sub) { + ast::pat_wild => word(s.s, ~"_"), + ast::pat_ident(binding_mode, path, sub) => { alt binding_mode { - ast::bind_by_ref => { word_space(s, ~"ref"); } - ast::bind_by_value => {} + ast::bind_by_ref => word_space(s, ~"ref"), + ast::bind_by_value => () } print_path(s, path, true); alt sub { some(p) => { word(s.s, ~"@"); print_pat(s, p); } - none => {} + none => () } } - ast::pat_enum(path, args_) { + ast::pat_enum(path, args_) => { print_path(s, path, true); alt args_ { - none { word(s.s, ~"(*)"); } - some(args) { + none => word(s.s, ~"(*)"), + some(args) => { if vec::len(args) > 0u { popen(s); commasep(s, inconsistent, args, print_pat); @@ -1347,7 +1345,7 @@ fn print_pat(s: ps, &&pat: @ast::pat) { } } } - ast::pat_rec(fields, etc) { + ast::pat_rec(fields, etc) => { word(s.s, ~"{"); fn print_field(s: ps, f: ast::field_pat) { cbox(s, indent_unit); @@ -1364,15 +1362,15 @@ fn print_pat(s: ps, &&pat: @ast::pat) { } word(s.s, ~"}"); } - ast::pat_tup(elts) { + ast::pat_tup(elts) => { popen(s); commasep(s, inconsistent, elts, print_pat); pclose(s); } - ast::pat_box(inner) { word(s.s, ~"@"); print_pat(s, inner); } - ast::pat_uniq(inner) { word(s.s, ~"~"); print_pat(s, inner); } - ast::pat_lit(e) { print_expr(s, e); } - ast::pat_range(begin, end) { + ast::pat_box(inner) => { word(s.s, ~"@"); print_pat(s, inner); } + ast::pat_uniq(inner) => { word(s.s, ~"~"); print_pat(s, inner); } + ast::pat_lit(e) => print_expr(s, e), + ast::pat_range(begin, end) => { print_expr(s, begin); space(s.s); word_space(s, ~"to"); @@ -1385,8 +1383,8 @@ fn print_pat(s: ps, &&pat: @ast::pat) { fn print_fn(s: ps, decl: ast::fn_decl, name: ast::ident, typarams: ~[ast::ty_param]) { alt decl.purity { - ast::impure_fn { head(s, ~"fn") } - _ { head(s, purity_to_str(decl.purity) + ~" fn") } + ast::impure_fn => head(s, ~"fn"), + _ => head(s, purity_to_str(decl.purity) + ~" fn") } word(s.s, *name); print_type_params(s, typarams); @@ -1436,12 +1434,12 @@ fn print_fn_block_args(s: ps, decl: ast::fn_decl, fn mode_to_str(m: ast::mode) -> ~str { alt m { - ast::expl(ast::by_mutbl_ref) { ~"&" } - ast::expl(ast::by_move) { ~"-" } - ast::expl(ast::by_ref) { ~"&&" } - ast::expl(ast::by_val) { ~"++" } - ast::expl(ast::by_copy) { ~"+" } - ast::infer(_) { ~"" } + ast::expl(ast::by_mutbl_ref) => ~"&", + ast::expl(ast::by_move) => ~"-", + ast::expl(ast::by_ref) => ~"&&", + ast::expl(ast::by_val) => ~"++", + ast::expl(ast::by_copy) => ~"+", + ast::infer(_) => ~"" } } @@ -1456,11 +1454,11 @@ fn print_bounds(s: ps, bounds: @~[ast::ty_param_bound]) { for vec::each(*bounds) |bound| { nbsp(s); alt bound { - ast::bound_copy { word(s.s, ~"copy"); } - ast::bound_send { word(s.s, ~"send"); } - ast::bound_const { word(s.s, ~"const"); } - ast::bound_owned { word(s.s, ~"owned"); } - ast::bound_trait(t) { print_type(s, t); } + ast::bound_copy => word(s.s, ~"copy"), + ast::bound_send => word(s.s, ~"send"), + ast::bound_const => word(s.s, ~"const"), + ast::bound_owned => word(s.s, ~"owned"), + ast::bound_trait(t) => print_type(s, t) } } } @@ -1481,13 +1479,13 @@ fn print_type_params(s: ps, &¶ms: ~[ast::ty_param]) { fn print_meta_item(s: ps, &&item: @ast::meta_item) { ibox(s, indent_unit); alt item.node { - ast::meta_word(name) { word(s.s, *name); } - ast::meta_name_value(name, value) { + ast::meta_word(name) => word(s.s, *name), + ast::meta_name_value(name, value) => { word_space(s, *name); word_space(s, ~"="); print_literal(s, @value); } - ast::meta_list(name, items) { + ast::meta_list(name, items) => { word(s.s, *name); popen(s); commasep(s, consistent, items, print_meta_item); @@ -1499,7 +1497,7 @@ fn print_meta_item(s: ps, &&item: @ast::meta_item) { fn print_view_path(s: ps, &&vp: @ast::view_path) { alt vp.node { - ast::view_path_simple(ident, path, _) { + ast::view_path_simple(ident, path, _) => { if path.idents[vec::len(path.idents)-1u] != ident { word_space(s, *ident); word_space(s, ~"="); @@ -1507,12 +1505,12 @@ fn print_view_path(s: ps, &&vp: @ast::view_path) { print_path(s, path, false); } - ast::view_path_glob(path, _) { + ast::view_path_glob(path, _) => { print_path(s, path, false); word(s.s, ~"::*"); } - ast::view_path_list(path, idents, _) { + ast::view_path_list(path, idents, _) => { print_path(s, path, false); word(s.s, ~"::{"); do commasep(s, inconsistent, idents) |s, w| { @@ -1532,7 +1530,7 @@ fn print_view_item(s: ps, item: @ast::view_item) { maybe_print_comment(s, item.span.lo); print_outer_attributes(s, item.attrs); alt item.node { - ast::view_item_use(id, mta, _) { + ast::view_item_use(id, mta, _) => { head(s, ~"use"); word(s.s, *id); if vec::len(mta) > 0u { @@ -1542,12 +1540,12 @@ fn print_view_item(s: ps, item: @ast::view_item) { } } - ast::view_item_import(vps) { + ast::view_item_import(vps) => { head(s, ~"import"); print_view_paths(s, vps); } - ast::view_item_export(vps) { + ast::view_item_export(vps) => { head(s, ~"export"); print_view_paths(s, vps); } @@ -1566,9 +1564,9 @@ fn print_op_maybe_parens(s: ps, expr: @ast::expr, outer_prec: uint) { fn print_mutability(s: ps, mutbl: ast::mutability) { alt mutbl { - ast::m_mutbl { word_nbsp(s, ~"mut"); } - ast::m_const { word_nbsp(s, ~"const"); } - ast::m_imm {/* nothing */ } + ast::m_mutbl => word_nbsp(s, ~"mut"), + ast::m_const => word_nbsp(s, ~"const"), + ast::m_imm => {/* nothing */ } } } @@ -1581,10 +1579,8 @@ fn print_arg(s: ps, input: ast::arg) { ibox(s, indent_unit); print_arg_mode(s, input.mode); alt input.ty.node { - ast::ty_infer { - word(s.s, *input.ident); - } - _ { + ast::ty_infer => word(s.s, *input.ident), + _ => { if str::len(*input.ident) > 0u { word_space(s, *input.ident + ~":"); } @@ -1599,8 +1595,8 @@ fn print_ty_fn(s: ps, opt_proto: option<ast::proto>, tps: option<~[ast::ty_param]>) { ibox(s, indent_unit); word(s.s, opt_proto_to_str(opt_proto)); - alt id { some(id) { word(s.s, ~" "); word(s.s, *id); } _ { } } - alt tps { some(tps) { print_type_params(s, tps); } _ { } } + alt id { some(id) => { word(s.s, ~" "); word(s.s, *id); } _ => () } + alt tps { some(tps) => print_type_params(s, tps), _ => () } zerobreak(s.s); popen(s); commasep(s, inconsistent, decl.inputs, print_arg); @@ -1620,21 +1616,21 @@ fn print_ty_fn(s: ps, opt_proto: option<ast::proto>, fn maybe_print_trailing_comment(s: ps, span: codemap::span, next_pos: option<uint>) { let mut cm; - alt s.cm { some(ccm) { cm = ccm; } _ { return; } } + alt s.cm { some(ccm) => cm = ccm, _ => return } alt next_comment(s) { - some(cmnt) { + some(cmnt) => { if cmnt.style != comments::trailing { return; } let span_line = codemap::lookup_char_pos(cm, span.hi); let comment_line = codemap::lookup_char_pos(cm, cmnt.pos); let mut next = cmnt.pos + 1u; - alt next_pos { none { } some(p) { next = p; } } + alt next_pos { none => (), some(p) => next = p } if span.hi < cmnt.pos && cmnt.pos < next && span_line.line == comment_line.line { print_comment(s, cmnt); s.cur_cmnt += 1u; } } - _ { } + _ => () } } @@ -1644,8 +1640,8 @@ fn print_remaining_comments(s: ps) { if option::is_none(next_comment(s)) { hardbreak(s.s); } loop { alt next_comment(s) { - some(cmnt) { print_comment(s, cmnt); s.cur_cmnt += 1u; } - _ { break; } + some(cmnt) => { print_comment(s, cmnt); s.cur_cmnt += 1u; } + _ => break } } } @@ -1653,18 +1649,18 @@ fn print_remaining_comments(s: ps) { fn print_literal(s: ps, &&lit: @ast::lit) { maybe_print_comment(s, lit.span.lo); alt next_lit(s, lit.span.lo) { - some(ltrl) { + some(ltrl) => { word(s.s, ltrl.lit); return; } - _ {} + _ => () } alt lit.node { - ast::lit_str(st) { print_string(s, *st); } - ast::lit_int(ch, ast::ty_char) { + ast::lit_str(st) => print_string(s, *st), + ast::lit_int(ch, ast::ty_char) => { word(s.s, ~"'" + char::escape_default(ch as char) + ~"'"); } - ast::lit_int(i, t) { + ast::lit_int(i, t) => { if i < 0_i64 { word(s.s, ~"-" + u64::to_str(-i as u64, 10u) @@ -1675,23 +1671,23 @@ fn print_literal(s: ps, &&lit: @ast::lit) { + ast_util::int_ty_to_str(t)); } } - ast::lit_uint(u, t) { + ast::lit_uint(u, t) => { word(s.s, u64::to_str(u, 10u) + ast_util::uint_ty_to_str(t)); } - ast::lit_int_unsuffixed(i) { + ast::lit_int_unsuffixed(i) => { if i < 0_i64 { word(s.s, ~"-" + u64::to_str(-i as u64, 10u)); } else { word(s.s, u64::to_str(i as u64, 10u)); } } - ast::lit_float(f, t) { + ast::lit_float(f, t) => { word(s.s, *f + ast_util::float_ty_to_str(t)); } - ast::lit_nil { word(s.s, ~"()"); } - ast::lit_bool(val) { + ast::lit_nil => word(s.s, ~"()"), + ast::lit_bool(val) => { if val { word(s.s, ~"true"); } else { word(s.s, ~"false"); } } } @@ -1701,7 +1697,7 @@ fn lit_to_str(l: @ast::lit) -> ~str { return to_str(l, print_literal); } fn next_lit(s: ps, pos: uint) -> option<comments::lit> { alt s.literals { - some(lits) { + some(lits) => { while s.cur_lit < vec::len(lits) { let ltrl = lits[s.cur_lit]; if ltrl.pos > pos { return none; } @@ -1710,33 +1706,33 @@ fn next_lit(s: ps, pos: uint) -> option<comments::lit> { } return none; } - _ { return none; } + _ => return none } } fn maybe_print_comment(s: ps, pos: uint) { loop { alt next_comment(s) { - some(cmnt) { + some(cmnt) => { if cmnt.pos < pos { print_comment(s, cmnt); s.cur_cmnt += 1u; } else { break; } } - _ { break; } + _ => break } } } fn print_comment(s: ps, cmnt: comments::cmnt) { alt cmnt.style { - comments::mixed { + comments::mixed => { assert (vec::len(cmnt.lines) == 1u); zerobreak(s.s); word(s.s, cmnt.lines[0]); zerobreak(s.s); } - comments::isolated { + comments::isolated => { pprust::hardbreak_if_not_bol(s); for cmnt.lines.each |line| { // Don't print empty lines because they will end up as trailing @@ -1745,7 +1741,7 @@ fn print_comment(s: ps, cmnt: comments::cmnt) { hardbreak(s.s); } } - comments::trailing { + comments::trailing => { word(s.s, ~" "); if vec::len(cmnt.lines) == 1u { word(s.s, cmnt.lines[0]); @@ -1759,12 +1755,12 @@ fn print_comment(s: ps, cmnt: comments::cmnt) { end(s); } } - comments::blank_line { + comments::blank_line => { // We need to do at least one, possibly two hardbreaks. let is_semi = alt s.s.last_token() { - pp::STRING(s, _) { *s == ~";" } - _ { false } + pp::STRING(s, _) => *s == ~";", + _ => false }; if is_semi || is_begin(s) || is_end(s) { hardbreak(s.s); } hardbreak(s.s); @@ -1788,19 +1784,19 @@ fn to_str<T>(t: T, f: fn@(ps, T)) -> ~str { fn next_comment(s: ps) -> option<comments::cmnt> { alt s.comments { - some(cmnts) { + some(cmnts) => { if s.cur_cmnt < vec::len(cmnts) { return some(cmnts[s.cur_cmnt]); } else { return none::<comments::cmnt>; } } - _ { return none::<comments::cmnt>; } + _ => return none::<comments::cmnt> } } fn opt_proto_to_str(opt_p: option<ast::proto>) -> ~str { alt opt_p { - none { ~"fn" } - some(p) { proto_to_str(p) } + none => ~"fn", + some(p) => proto_to_str(p) } } @@ -1815,17 +1811,17 @@ pure fn purity_to_str(p: ast::purity) -> ~str { fn print_purity(s: ps, p: ast::purity) { alt p { - ast::impure_fn {} - _ { word_nbsp(s, purity_to_str(p)) } + ast::impure_fn => (), + _ => word_nbsp(s, purity_to_str(p)) } } fn proto_to_str(p: ast::proto) -> ~str { return alt p { - ast::proto_bare { ~"extern fn" } - ast::proto_block { ~"fn&" } - ast::proto_uniq { ~"fn~" } - ast::proto_box { ~"fn@" } + ast::proto_bare => ~"extern fn", + ast::proto_block => ~"fn&", + ast::proto_uniq => ~"fn~", + ast::proto_box => ~"fn@" }; } diff --git a/src/libsyntax/util/interner.rs b/src/libsyntax/util/interner.rs index 5b959cb648a..80bd9e3a6d1 100644 --- a/src/libsyntax/util/interner.rs +++ b/src/libsyntax/util/interner.rs @@ -28,8 +28,8 @@ trait interner<T: const copy> { impl <T: const copy> of interner<T> for hash_interner<T> { fn intern(val: T) -> uint { alt self.map.find(val) { - some(idx) { return idx; } - none { + some(idx) => return idx, + none => { let new_idx = self.vect.len(); self.map.insert(val, new_idx); self.vect.push(val); diff --git a/src/libsyntax/visit.rs b/src/libsyntax/visit.rs index 6eb468efd82..8d80f9663a3 100644 --- a/src/libsyntax/visit.rs +++ b/src/libsyntax/visit.rs @@ -27,19 +27,19 @@ enum fn_kind { fn name_of_fn(fk: fn_kind) -> ident { alt fk { fk_item_fn(name, _) | fk_method(name, _, _) - | fk_ctor(name, _, _, _, _) { /* FIXME (#2543) */ copy name } - fk_anon(*) | fk_fn_block(*) { @~"anon" } - fk_dtor(*) { @~"drop" } + | fk_ctor(name, _, _, _, _) => /* FIXME (#2543) */ copy name, + fk_anon(*) | fk_fn_block(*) => @~"anon", + fk_dtor(*) => @~"drop" } } fn tps_of_fn(fk: fn_kind) -> ~[ty_param] { alt fk { fk_item_fn(_, tps) | fk_method(_, tps, _) - | fk_ctor(_, _, tps, _, _) | fk_dtor(tps, _, _, _) { + | fk_ctor(_, _, tps, _, _) | fk_dtor(tps, _, _, _) => { /* FIXME (#2543) */ copy tps } - fk_anon(*) | fk_fn_block(*) { ~[] } + fk_anon(*) | fk_fn_block(*) => ~[] } } @@ -90,14 +90,12 @@ fn visit_crate<E>(c: crate, e: E, v: vt<E>) { fn visit_crate_directive<E>(cd: @crate_directive, e: E, v: vt<E>) { alt cd.node { - cdir_src_mod(_, _) { } - cdir_dir_mod(_, cdirs, _) { - for cdirs.each |cdir| { - visit_crate_directive(cdir, e, v); - } + cdir_src_mod(_, _) => (), + cdir_dir_mod(_, cdirs, _) => for cdirs.each |cdir| { + visit_crate_directive(cdir, e, v); } - cdir_view_item(vi) { v.visit_view_item(vi, e, v); } - cdir_syntax(_) { } + cdir_view_item(vi) => v.visit_view_item(vi, e, v), + cdir_syntax(_) => () } } @@ -111,33 +109,36 @@ fn visit_view_item<E>(_vi: @view_item, _e: E, _v: vt<E>) { } fn visit_local<E>(loc: @local, e: E, v: vt<E>) { v.visit_pat(loc.node.pat, e, v); v.visit_ty(loc.node.ty, e, v); - alt loc.node.init { none { } some(i) { v.visit_expr(i.expr, e, v); } } + alt loc.node.init { + none => (), + some(i) => v.visit_expr(i.expr, e, v) + } } fn visit_item<E>(i: @item, e: E, v: vt<E>) { alt i.node { - item_const(t, ex) { v.visit_ty(t, e, v); v.visit_expr(ex, e, v); } - item_fn(decl, tp, body) { + item_const(t, ex) => { v.visit_ty(t, e, v); v.visit_expr(ex, e, v); } + item_fn(decl, tp, body) => { v.visit_fn(fk_item_fn(/* FIXME (#2543) */ copy i.ident, /* FIXME (#2543) */ copy tp), decl, body, i.span, i.id, e, v); } - item_mod(m) { v.visit_mod(m, i.span, i.id, e, v); } - item_foreign_mod(nm) { + item_mod(m) => v.visit_mod(m, i.span, i.id, e, v), + item_foreign_mod(nm) => { for nm.view_items.each |vi| { v.visit_view_item(vi, e, v); } for nm.items.each |ni| { v.visit_foreign_item(ni, e, v); } } - item_ty(t, tps) { + item_ty(t, tps) => { v.visit_ty(t, e, v); v.visit_ty_params(tps, e, v); } - item_enum(variants, tps) { + item_enum(variants, tps) => { v.visit_ty_params(tps, e, v); for variants.each |vr| { for vr.node.args.each |va| { v.visit_ty(va.ty, e, v); } } } - item_impl(tps, traits, ty, methods) { + item_impl(tps, traits, ty, methods) => { v.visit_ty_params(tps, e, v); for traits.each |p| { visit_path(p.path, e, v); @@ -147,7 +148,7 @@ fn visit_item<E>(i: @item, e: E, v: vt<E>) { visit_method_helper(m, e, v) } } - item_class(tps, traits, members, m_ctor, m_dtor) { + item_class(tps, traits, members, m_ctor, m_dtor) => { v.visit_ty_params(tps, e, v); for members.each |m| { v.visit_class_item(m, e, v); @@ -162,25 +163,21 @@ fn visit_item<E>(i: @item, e: E, v: vt<E>) { ast_util::local_def(i.id), e, v) }; } - item_trait(tps, traits, methods) { + item_trait(tps, traits, methods) => { v.visit_ty_params(tps, e, v); for traits.each |p| { visit_path(p.path, e, v); } for methods.each |m| { v.visit_trait_method(m, e, v); } } - item_mac(m) { visit_mac(m, e, v) } + item_mac(m) => visit_mac(m, e, v) } } fn visit_class_item<E>(cm: @class_member, e:E, v:vt<E>) { alt cm.node { - instance_var(_, t, _, _, _) { - v.visit_ty(t, e, v); - } - class_method(m) { - visit_method_helper(m, e, v); - } + instance_var(_, t, _, _, _) => v.visit_ty(t, e, v), + class_method(m) => visit_method_helper(m, e, v) } } @@ -189,26 +186,25 @@ fn skip_ty<E>(_t: @ty, _e: E, _v: vt<E>) {} fn visit_ty<E>(t: @ty, e: E, v: vt<E>) { alt t.node { ty_box(mt) | ty_uniq(mt) | - ty_vec(mt) | ty_ptr(mt) | ty_rptr(_, mt) { + ty_vec(mt) | ty_ptr(mt) | ty_rptr(_, mt) => { v.visit_ty(mt.ty, e, v); } - ty_rec(flds) { - for flds.each |f| { v.visit_ty(f.node.mt.ty, e, v); } + ty_rec(flds) => for flds.each |f| { + v.visit_ty(f.node.mt.ty, e, v); + } + ty_tup(ts) => for ts.each |tt| { + v.visit_ty(tt, e, v); } - ty_tup(ts) { for ts.each |tt| { v.visit_ty(tt, e, v); } } - ty_fn(_, decl) { + ty_fn(_, decl) => { for decl.inputs.each |a| { v.visit_ty(a.ty, e, v); } v.visit_ty(decl.output, e, v); } - ty_path(p, _) { visit_path(p, e, v); } - ty_fixed_length(t, _) { - v.visit_ty(t, e, v); - } + ty_path(p, _) => visit_path(p, e, v), + ty_fixed_length(t, _) => v.visit_ty(t, e, v), ty_nil | ty_bot | ty_mac(_) | - ty_infer { - } + ty_infer => () } } @@ -218,31 +214,31 @@ fn visit_path<E>(p: @path, e: E, v: vt<E>) { fn visit_pat<E>(p: @pat, e: E, v: vt<E>) { alt p.node { - pat_enum(path, children) { + pat_enum(path, children) => { visit_path(path, e, v); do option::iter(children) |children| { for children.each |child| { v.visit_pat(child, e, v); }} } - pat_rec(fields, _) { - for fields.each |f| { v.visit_pat(f.pat, e, v); } + pat_rec(fields, _) => for fields.each |f| { + v.visit_pat(f.pat, e, v) } - pat_tup(elts) { for elts.each |elt| { v.visit_pat(elt, e, v); } } - pat_box(inner) | pat_uniq(inner) { - v.visit_pat(inner, e, v); + pat_tup(elts) => for elts.each |elt| { + v.visit_pat(elt, e, v) } - pat_ident(_, path, inner) { + pat_box(inner) | pat_uniq(inner) => v.visit_pat(inner, e, v), + pat_ident(_, path, inner) => { visit_path(path, e, v); do option::iter(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); } - pat_wild {} + 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); } + pat_wild => () } } fn visit_foreign_item<E>(ni: @foreign_item, e: E, v: vt<E>) { alt ni.node { - foreign_item_fn(fd, tps) { + foreign_item_fn(fd, tps) => { v.visit_ty_params(tps, e, v); visit_fn_decl(fd, e, v); } @@ -253,8 +249,8 @@ fn visit_ty_params<E>(tps: ~[ty_param], e: E, v: vt<E>) { for tps.each |tp| { for vec::each(*tp.bounds) |bound| { alt bound { - bound_trait(t) { v.visit_ty(t, e, v); } - bound_copy | bound_send | bound_const | bound_owned { } + bound_trait(t) => v.visit_ty(t, e, v), + bound_copy | bound_send | bound_const | bound_owned => () } } } @@ -309,12 +305,8 @@ fn visit_ty_method<E>(m: ty_method, e: E, v: vt<E>) { fn visit_trait_method<E>(m: trait_method, e: E, v: vt<E>) { alt m { - required(ty_m) { - v.visit_ty_method(ty_m, e, v) - } - provided(m) { - visit_method_helper(m, e, v) - } + required(ty_m) => v.visit_ty_method(ty_m, e, v), + provided(m) => visit_method_helper(m, e, v) } } @@ -326,23 +318,23 @@ fn visit_block<E>(b: ast::blk, e: E, v: vt<E>) { fn visit_stmt<E>(s: @stmt, e: E, v: vt<E>) { alt s.node { - stmt_decl(d, _) { v.visit_decl(d, e, v); } - stmt_expr(ex, _) { v.visit_expr(ex, e, v); } - stmt_semi(ex, _) { v.visit_expr(ex, e, v); } + stmt_decl(d, _) => v.visit_decl(d, e, v), + stmt_expr(ex, _) => v.visit_expr(ex, e, v), + stmt_semi(ex, _) => v.visit_expr(ex, e, v) } } fn visit_decl<E>(d: @decl, e: E, v: vt<E>) { alt d.node { - decl_local(locs) { - for locs.each |loc| { v.visit_local(loc, e, v); } + decl_local(locs) => for locs.each |loc| { + v.visit_local(loc, e, v) } - decl_item(it) { v.visit_item(it, e, v); } + decl_item(it) => v.visit_item(it, e, v) } } fn visit_expr_opt<E>(eo: option<@expr>, e: E, v: vt<E>) { - alt eo { none { } some(ex) { v.visit_expr(ex, e, v); } } + alt eo { none => (), some(ex) => v.visit_expr(ex, e, v) } } fn visit_exprs<E>(exprs: ~[@expr], e: E, v: vt<E>) { @@ -351,86 +343,88 @@ fn visit_exprs<E>(exprs: ~[@expr], e: E, v: vt<E>) { fn visit_mac<E>(m: mac, e: E, v: vt<E>) { alt m.node { - ast::mac_invoc(pth, arg, body) { + ast::mac_invoc(pth, arg, body) => { option::map(arg, |arg| v.visit_expr(arg, e, v)); } - ast::mac_invoc_tt(pth, tt) { /* no user-serviceable parts inside */ } - ast::mac_ellipsis { } - ast::mac_aq(_, e) { /* FIXME: maybe visit (Issue #2340) */ } - ast::mac_var(_) { } + ast::mac_invoc_tt(pth, tt) => { /* no user-serviceable parts inside */ } + ast::mac_ellipsis => (), + ast::mac_aq(_, e) => { /* FIXME: maybe visit (Issue #2340) */ } + ast::mac_var(_) => () } } fn visit_expr<E>(ex: @expr, e: E, v: vt<E>) { alt ex.node { - expr_vstore(x, _) { v.visit_expr(x, e, v); } - expr_vec(es, _) { visit_exprs(es, e, v); } + expr_vstore(x, _) => v.visit_expr(x, e, v), + expr_vec(es, _) => visit_exprs(es, e, v), expr_repeat(element, count, _) => { v.visit_expr(element, e, v); v.visit_expr(count, e, v); } - expr_rec(flds, base) { + expr_rec(flds, base) => { for flds.each |f| { v.visit_expr(f.node.expr, e, v); } visit_expr_opt(base, e, v); } - expr_struct(p, flds) { + expr_struct(p, flds) => { visit_path(p, e, v); for flds.each |f| { v.visit_expr(f.node.expr, e, v); } } - expr_tup(elts) { for elts.each |el| { v.visit_expr(el, e, v); } } - expr_call(callee, args, _) { + expr_tup(elts) => for elts.each |el| { v.visit_expr(el, e, v); } + expr_call(callee, args, _) => { visit_exprs(args, e, v); v.visit_expr(callee, e, v); } - expr_binary(_, a, b) { v.visit_expr(a, e, v); v.visit_expr(b, e, v); } + expr_binary(_, a, b) => { + v.visit_expr(a, e, v); v.visit_expr(b, e, v); + } expr_addr_of(_, x) | expr_unary(_, x) | expr_loop_body(x) | expr_do_body(x) | - expr_assert(x) { v.visit_expr(x, e, v); } - expr_lit(_) { } - expr_cast(x, t) { v.visit_expr(x, e, v); v.visit_ty(t, e, v); } - expr_if(x, b, eo) { + expr_assert(x) => v.visit_expr(x, e, v), + expr_lit(_) => (), + expr_cast(x, t) => { v.visit_expr(x, e, v); v.visit_ty(t, e, v); } + expr_if(x, b, eo) => { v.visit_expr(x, e, v); v.visit_block(b, e, v); visit_expr_opt(eo, e, v); } - expr_while(x, b) { v.visit_expr(x, e, v); v.visit_block(b, e, v); } - expr_loop(b) { v.visit_block(b, e, v); } - expr_alt(x, arms, _) { + expr_while(x, b) => { v.visit_expr(x, e, v); v.visit_block(b, e, v); } + expr_loop(b) => v.visit_block(b, e, v), + expr_alt(x, arms, _) => { v.visit_expr(x, e, v); for arms.each |a| { v.visit_arm(a, e, v); } } - expr_fn(proto, decl, body, cap_clause) { + expr_fn(proto, decl, body, cap_clause) => { v.visit_fn(fk_anon(proto, cap_clause), decl, body, ex.span, ex.id, e, v); } - expr_fn_block(decl, body, cap_clause) { + expr_fn_block(decl, body, cap_clause) => { v.visit_fn(fk_fn_block(cap_clause), decl, body, ex.span, ex.id, e, v); } - expr_block(b) { v.visit_block(b, e, v); } - expr_assign(a, b) { v.visit_expr(b, e, v); v.visit_expr(a, e, v); } - expr_copy(a) { v.visit_expr(a, e, v); } - expr_unary_move(a) { v.visit_expr(a, e, v); } - expr_move(a, b) { v.visit_expr(b, e, v); v.visit_expr(a, e, v); } - expr_swap(a, b) { v.visit_expr(a, e, v); v.visit_expr(b, e, v); } - expr_assign_op(_, a, b) { + expr_block(b) => v.visit_block(b, e, v), + expr_assign(a, b) => { v.visit_expr(b, e, v); v.visit_expr(a, e, v); } + expr_copy(a) => v.visit_expr(a, e, v), + expr_unary_move(a) => v.visit_expr(a, e, v), + expr_move(a, b) => { v.visit_expr(b, e, v); v.visit_expr(a, e, v); } + expr_swap(a, b) => { v.visit_expr(a, e, v); v.visit_expr(b, e, v); } + expr_assign_op(_, a, b) => { v.visit_expr(b, e, v); v.visit_expr(a, e, v); } - expr_field(x, _, tys) { + expr_field(x, _, tys) => { v.visit_expr(x, e, v); for tys.each |tp| { v.visit_ty(tp, e, v); } } - expr_index(a, b) { v.visit_expr(a, e, v); v.visit_expr(b, e, v); } - expr_path(p) { visit_path(p, e, v); } - expr_fail(eo) { visit_expr_opt(eo, e, v); } - expr_break { } - expr_again { } - expr_ret(eo) { visit_expr_opt(eo, e, v); } - expr_log(_, lv, x) { + expr_index(a, b) => { v.visit_expr(a, e, v); v.visit_expr(b, e, v); } + expr_path(p) => visit_path(p, e, v), + expr_fail(eo) => visit_expr_opt(eo, e, v), + expr_break => (), + expr_again => (), + expr_ret(eo) => visit_expr_opt(eo, e, v), + expr_log(_, lv, x) => { v.visit_expr(lv, e, v); v.visit_expr(x, e, v); } - expr_mac(mac) { visit_mac(mac, e, v); } + expr_mac(mac) => visit_mac(mac, e, v), } v.visit_expr_post(ex, e, v); } diff --git a/src/rustc/back/link.rs b/src/rustc/back/link.rs index c92653c8ba6..c4dc6efe7b2 100644 --- a/src/rustc/back/link.rs +++ b/src/rustc/back/link.rs @@ -62,8 +62,8 @@ mod write { fn mk_intermediate_name(output_path: ~str, extension: ~str) -> ~str unsafe { let stem = alt str::find_char(output_path, '.') { - some(dot_pos) { str::slice(output_path, 0u, dot_pos) } - none { output_path } + some(dot_pos) => str::slice(output_path, 0u, dot_pos), + none => output_path }; return stem + ~"." + extension; } @@ -83,7 +83,7 @@ mod write { if opts.save_temps { alt opts.output_type { - output_type_bitcode { + output_type_bitcode => { if opts.optimize != 0u { let filename = mk_intermediate_name(output, ~"no-opt.bc"); str::as_c_str(filename, |buf| { @@ -91,7 +91,7 @@ mod write { }); } } - _ { + _ => { let filename = mk_intermediate_name(output, ~"bc"); str::as_c_str(filename, |buf| { llvm::LLVMWriteBitcodeToFile(llmod, buf) @@ -146,13 +146,12 @@ mod write { let LLVMOptDefault = 2 as c_int; // -O2, -Os let LLVMOptAggressive = 3 as c_int; // -O3 - let mut CodeGenOptLevel; - alt check opts.optimize { - 0u { CodeGenOptLevel = LLVMOptNone; } - 1u { CodeGenOptLevel = LLVMOptLess; } - 2u { CodeGenOptLevel = LLVMOptDefault; } - 3u { CodeGenOptLevel = LLVMOptAggressive; } - } + let mut CodeGenOptLevel = alt check opts.optimize { + 0u => LLVMOptNone, + 1u => LLVMOptLess, + 2u => LLVMOptDefault, + 3u => LLVMOptAggressive + }; let mut FileType; if opts.output_type == output_type_object || @@ -325,13 +324,13 @@ fn build_link_meta(sess: session, c: ast::crate, output: ~str, for linkage_metas.each |meta| { if *attr::get_meta_item_name(meta) == ~"name" { alt attr::get_meta_item_value_str(meta) { - some(v) { name = some(v); } - none { vec::push(cmh_items, meta); } + some(v) => { name = some(v); } + none => vec::push(cmh_items, meta) } } else if *attr::get_meta_item_name(meta) == ~"vers" { alt attr::get_meta_item_value_str(meta) { - some(v) { vers = some(v); } - none { vec::push(cmh_items, meta); } + some(v) => { vers = some(v); } + none => vec::push(cmh_items, meta) } } else { vec::push(cmh_items, meta); } } @@ -357,14 +356,14 @@ fn build_link_meta(sess: session, c: ast::crate, output: ~str, for cmh_items.each |m_| { let m = m_; alt m.node { - ast::meta_name_value(key, value) { + ast::meta_name_value(key, value) => { symbol_hasher.write_str(len_and_str(*key)); symbol_hasher.write_str(len_and_str_lit(value)); } - ast::meta_word(name) { + ast::meta_word(name) => { symbol_hasher.write_str(len_and_str(*name)); } - ast::meta_list(_, _) { + ast::meta_list(_, _) => { // FIXME (#607): Implement this fail ~"unimplemented meta_item variant"; } @@ -387,8 +386,8 @@ fn build_link_meta(sess: session, c: ast::crate, output: ~str, fn crate_meta_name(sess: session, _crate: ast::crate, output: ~str, metas: provided_metas) -> @~str { return alt metas.name { - some(v) { v } - none { + some(v) => v, + none => { let name = { let mut os = @@ -409,8 +408,8 @@ fn build_link_meta(sess: session, c: ast::crate, output: ~str, fn crate_meta_vers(sess: session, _crate: ast::crate, metas: provided_metas) -> @~str { return alt metas.vers { - some(v) { v } - none { + some(v) => v, + none => { let vers = ~"0.0"; warn_missing(sess, ~"vers", vers); @vers @@ -453,8 +452,8 @@ fn symbol_hash(tcx: ty::ctxt, symbol_hasher: &hash::State, t: ty::t, fn get_symbol_hash(ccx: @crate_ctxt, t: ty::t) -> ~str { alt ccx.type_hashcodes.find(t) { - some(h) { return h; } - none { + some(h) => return h, + none => { let hash = symbol_hash(ccx.tcx, ccx.symbol_hasher, t, ccx.link_meta); ccx.type_hashcodes.insert(t, hash); return hash; @@ -469,18 +468,18 @@ fn sanitize(s: ~str) -> ~str { let mut result = ~""; do str::chars_iter(s) |c| { alt c { - '@' { result += ~"_sbox_"; } - '~' { result += ~"_ubox_"; } - '*' { result += ~"_ptr_"; } - '&' { result += ~"_ref_"; } - ',' { result += ~"_"; } + '@' => result += ~"_sbox_", + '~' => result += ~"_ubox_", + '*' => result += ~"_ptr_", + '&' => result += ~"_ref_", + ',' => result += ~"_", - '{' | '(' { result += ~"_of_"; } + '{' | '(' => result += ~"_of_", 'a' to 'z' | 'A' to 'Z' | '0' to '9' - | '_' { str::push_char(result,c); } - _ { + | '_' => str::push_char(result,c), + _ => { if c > 'z' && char::is_XID_continue(c) { str::push_char(result,c); } @@ -504,7 +503,7 @@ fn mangle(ss: path) -> ~str { let mut n = ~"_ZN"; // Begin name-sequence. for ss.each |s| { - alt s { path_name(s) | path_mod(s) { + alt s { path_name(s) | path_mod(s) => { let sani = sanitize(*s); n += fmt!{"%u%s", str::len(sani), sani}; } } @@ -568,10 +567,10 @@ fn link_binary(sess: session, return str::connect(parts, ~"."); } return alt config.os { - session::os_macos { rmext(rmlib(filename)) } - session::os_linux { rmext(rmlib(filename)) } - session::os_freebsd { rmext(rmlib(filename)) } - _ { rmext(filename) } + session::os_macos => rmext(rmlib(filename)), + session::os_linux => rmext(rmlib(filename)), + session::os_freebsd => rmext(rmlib(filename)), + _ => rmext(filename) }; } diff --git a/src/rustc/back/rpath.rs b/src/rustc/back/rpath.rs index d92c5f8379e..f74ffe8f067 100644 --- a/src/rustc/back/rpath.rs +++ b/src/rustc/back/rpath.rs @@ -8,8 +8,8 @@ export get_rpath_flags; pure fn not_win32(os: session::os) -> bool { alt os { - session::os_win32 { false } - _ { true } + session::os_win32 => false, + _ => true } } @@ -109,10 +109,10 @@ fn get_rpath_relative_to_output(os: session::os, // Mac doesn't appear to support $ORIGIN let prefix = alt os { - session::os_linux { ~"$ORIGIN" + path::path_sep() } - session::os_freebsd { ~"$ORIGIN" + path::path_sep() } - session::os_macos { ~"@executable_path" + path::path_sep() } - session::os_win32 { core::unreachable(); } + session::os_linux => ~"$ORIGIN" + path::path_sep(), + session::os_freebsd => ~"$ORIGIN" + path::path_sep(), + session::os_macos => ~"@executable_path" + path::path_sep(), + session::os_win32 => core::unreachable() }; prefix + get_relative_to( diff --git a/src/rustc/back/x86.rs b/src/rustc/back/x86.rs index 93001f5e06a..045a90de495 100644 --- a/src/rustc/back/x86.rs +++ b/src/rustc/back/x86.rs @@ -9,31 +9,31 @@ fn get_target_strs(target_os: session::os) -> target_strs::t { meta_sect_name: meta_section_name(sess_os_to_meta_os(target_os)), data_layout: alt target_os { - session::os_macos { + session::os_macos => { ~"e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16" + ~"-i32:32:32-i64:32:64" + ~"-f32:32:32-f64:32:64-v64:64:64" + ~"-v128:128:128-a0:0:64-f80:128:128" + ~"-n8:16:32" } - session::os_win32 { + session::os_win32 => { ~"e-p:32:32-f64:64:64-i64:64:64-f80:32:32-n8:16:32" } - session::os_linux { + session::os_linux => { ~"e-p:32:32-f64:32:64-i64:32:64-f80:32:32-n8:16:32" } - session::os_freebsd { + session::os_freebsd => { ~"e-p:32:32-f64:32:64-i64:32:64-f80:32:32-n8:16:32" } }, target_triple: alt target_os { - session::os_macos { ~"i686-apple-darwin" } - session::os_win32 { ~"i686-pc-mingw32" } - session::os_linux { ~"i686-unknown-linux-gnu" } - session::os_freebsd { ~"i686-unknown-freebsd" } + session::os_macos => ~"i686-apple-darwin", + session::os_win32 => ~"i686-pc-mingw32", + session::os_linux => ~"i686-unknown-linux-gnu", + session::os_freebsd => ~"i686-unknown-freebsd" }, cc_args: ~[~"-m32"] diff --git a/src/rustc/back/x86_64.rs b/src/rustc/back/x86_64.rs index 76a63fbf3d9..70a35eb3289 100644 --- a/src/rustc/back/x86_64.rs +++ b/src/rustc/back/x86_64.rs @@ -9,26 +9,26 @@ fn get_target_strs(target_os: session::os) -> target_strs::t { meta_sect_name: meta_section_name(sess_os_to_meta_os(target_os)), data_layout: alt target_os { - session::os_macos { + session::os_macos => { ~"e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-"+ ~"f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-"+ ~"s0:64:64-f80:128:128-n8:16:32:64" } - session::os_win32 { + session::os_win32 => { // FIXME: Test this. Copied from linux (#2398) ~"e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-"+ ~"f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-"+ ~"s0:64:64-f80:128:128-n8:16:32:64-S128" } - session::os_linux { + session::os_linux => { ~"e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-"+ ~"f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-"+ ~"s0:64:64-f80:128:128-n8:16:32:64-S128" } - session::os_freebsd { + session::os_freebsd => { ~"e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-"+ ~"f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-"+ ~"s0:64:64-f80:128:128-n8:16:32:64-S128" @@ -36,10 +36,10 @@ fn get_target_strs(target_os: session::os) -> target_strs::t { }, target_triple: alt target_os { - session::os_macos { ~"x86_64-apple-darwin" } - session::os_win32 { ~"x86_64-pc-mingw32" } - session::os_linux { ~"x86_64-unknown-linux-gnu" } - session::os_freebsd { ~"x86_64-unknown-freebsd" } + session::os_macos => ~"x86_64-apple-darwin", + session::os_win32 => ~"x86_64-pc-mingw32", + session::os_linux => ~"x86_64-unknown-linux-gnu", + session::os_freebsd => ~"x86_64-unknown-freebsd", }, cc_args: ~[~"-m64"] diff --git a/src/rustc/driver/driver.rs b/src/rustc/driver/driver.rs index 901435d97c5..5a07c8f411c 100644 --- a/src/rustc/driver/driver.rs +++ b/src/rustc/driver/driver.rs @@ -27,27 +27,27 @@ fn anon_src() -> ~str { ~"<anon>" } fn source_name(input: input) -> ~str { alt input { - file_input(ifile) { ifile } - str_input(_) { anon_src() } + file_input(ifile) => ifile, + str_input(_) => anon_src() } } fn default_configuration(sess: session, argv0: ~str, input: input) -> ast::crate_cfg { let libc = alt sess.targ_cfg.os { - session::os_win32 { ~"msvcrt.dll" } - session::os_macos { ~"libc.dylib" } - session::os_linux { ~"libc.so.6" } - session::os_freebsd { ~"libc.so.7" } + session::os_win32 => ~"msvcrt.dll", + session::os_macos => ~"libc.dylib", + session::os_linux => ~"libc.so.6", + session::os_freebsd => ~"libc.so.7" // _ { "libc.so" } }; let mk = attr::mk_name_value_item_str; let (arch,wordsz) = alt sess.targ_cfg.arch { - session::arch_x86 { (~"x86",~"32") } - session::arch_x86_64 { (~"x86_64",~"64") } - session::arch_arm { (~"arm",~"32") } + session::arch_x86 => (~"x86",~"32"), + session::arch_x86_64 => (~"x86_64",~"64"), + session::arch_arm => (~"arm",~"32") }; return ~[ // Target bindings. @@ -100,10 +100,10 @@ enum input { fn parse_input(sess: session, cfg: ast::crate_cfg, input: input) -> @ast::crate { alt input { - file_input(file) { + file_input(file) => { parse::parse_crate_from_file(file, cfg, sess.parse_sess) } - str_input(src) { + str_input(src) => { // FIXME (#2319): Don't really want to box the source string parse::parse_crate_from_source_str( anon_src(), @src, cfg, sess.parse_sess) @@ -270,37 +270,40 @@ fn compile_input(sess: session, cfg: ast::crate_cfg, input: input, fn pretty_print_input(sess: session, cfg: ast::crate_cfg, input: input, ppm: pp_mode) { fn ann_paren_for_expr(node: pprust::ann_node) { - alt node { pprust::node_expr(s, expr) { pprust::popen(s); } _ { } } + alt node { + pprust::node_expr(s, expr) => pprust::popen(s), + _ => () + } } fn ann_typed_post(tcx: ty::ctxt, node: pprust::ann_node) { alt node { - pprust::node_expr(s, expr) { + pprust::node_expr(s, expr) => { pp::space(s.s); pp::word(s.s, ~"as"); pp::space(s.s); pp::word(s.s, ppaux::ty_to_str(tcx, ty::expr_ty(tcx, expr))); pprust::pclose(s); } - _ { } + _ => () } } fn ann_identified_post(node: pprust::ann_node) { alt node { - pprust::node_item(s, item) { + pprust::node_item(s, item) => { pp::space(s.s); pprust::synth_comment(s, int::to_str(item.id, 10u)); } - pprust::node_block(s, blk) { + pprust::node_block(s, blk) => { pp::space(s.s); pprust::synth_comment(s, ~"block " + int::to_str(blk.node.id, 10u)); } - pprust::node_expr(s, expr) { + pprust::node_expr(s, expr) => { pp::space(s.s); pprust::synth_comment(s, int::to_str(expr.id, 10u)); pprust::pclose(s); } - pprust::node_pat(s, pat) { + pprust::node_pat(s, pat) => { pp::space(s.s); pprust::synth_comment(s, ~"pat " + int::to_str(pat.id, 10u)); } @@ -312,21 +315,21 @@ fn pretty_print_input(sess: session, cfg: ast::crate_cfg, input: input, // from stdin, we're going to just suck the source into a string // so both the parser and pretty-printer can use it. let upto = alt ppm { - ppm_expanded | ppm_expanded_identified { cu_expand } - ppm_typed { cu_typeck } - _ { cu_parse } + ppm_expanded | ppm_expanded_identified => cu_expand, + ppm_typed => cu_typeck, + _ => cu_parse }; let {crate, tcx} = compile_upto(sess, cfg, input, upto, none); let ann = alt ppm { - ppm_typed { + ppm_typed => { {pre: ann_paren_for_expr, post: |a| ann_typed_post(option::get(tcx), a) } } - ppm_identified | ppm_expanded_identified { + ppm_identified | ppm_expanded_identified => { {pre: ann_paren_for_expr, post: ann_identified_post} } - ppm_expanded | ppm_normal { pprust::no_ann() } + ppm_expanded | ppm_normal => pprust::no_ann() }; let is_expanded = upto != cu_parse; let src = codemap::get_filemap(sess.codemap, source_name(input)).src; @@ -369,23 +372,23 @@ fn get_arch(triple: ~str) -> option<session::arch> { fn build_target_config(sopts: @session::options, demitter: diagnostic::emitter) -> @session::config { let os = alt get_os(sopts.target_triple) { - some(os) { os } - none { early_error(demitter, ~"unknown operating system") } + some(os) => os, + none => early_error(demitter, ~"unknown operating system") }; let arch = alt get_arch(sopts.target_triple) { - some(arch) { arch } - none { early_error(demitter, - ~"unknown architecture: " + sopts.target_triple) } + some(arch) => arch, + none => early_error(demitter, + ~"unknown architecture: " + sopts.target_triple) }; let (int_type, uint_type, float_type) = alt arch { - session::arch_x86 {(ast::ty_i32, ast::ty_u32, ast::ty_f64)} - session::arch_x86_64 {(ast::ty_i64, ast::ty_u64, ast::ty_f64)} - session::arch_arm {(ast::ty_i32, ast::ty_u32, ast::ty_f64)} + session::arch_x86 => (ast::ty_i32, ast::ty_u32, ast::ty_f64), + session::arch_x86_64 => (ast::ty_i64, ast::ty_u64, ast::ty_f64), + session::arch_arm => (ast::ty_i32, ast::ty_u32, ast::ty_f64) }; let target_strs = alt arch { - session::arch_x86 {x86::get_target_strs(os)} - session::arch_x86_64 {x86_64::get_target_strs(os)} - session::arch_arm {x86::get_target_strs(os)} + session::arch_x86 => x86::get_target_strs(os), + session::arch_x86_64 => x86_64::get_target_strs(os), + session::arch_arm => x86::get_target_strs(os) }; let target_cfg: @session::config = @{os: os, arch: arch, target_strs: target_strs, int_type: int_type, @@ -436,11 +439,11 @@ fn build_session_options(matches: getopts::matches, for flags.each |lint_name| { let lint_name = str::replace(lint_name, ~"-", ~"_"); alt lint_dict.find(lint_name) { - none { + none => { early_error(demitter, fmt!{"unknown %s flag: %s", level_name, lint_name}); } - some(lint) { + some(lint) => { vec::push(lint_opts, (lint.lint, level)); } } @@ -485,8 +488,8 @@ fn build_session_options(matches: getopts::matches, let save_temps = getopts::opt_present(matches, ~"save-temps"); alt output_type { // unless we're emitting huamn-readable assembly, omit comments. - link::output_type_llvm_assembly | link::output_type_assembly {} - _ { debugging_opts |= session::no_asm_comments; } + link::output_type_llvm_assembly | link::output_type_assembly => (), + _ => debugging_opts |= session::no_asm_comments } let opt_level: uint = if opt_present(matches, ~"O") { @@ -496,11 +499,11 @@ fn build_session_options(matches: getopts::matches, 2u } else if opt_present(matches, ~"opt-level") { alt getopts::opt_str(matches, ~"opt-level") { - ~"0" { 0u } - ~"1" { 1u } - ~"2" { 2u } - ~"3" { 3u } - _ { + ~"0" => 0u, + ~"1" => 1u, + ~"2" => 2u, + ~"3" => 3u, + _ => { early_error(demitter, ~"optimization level needs " + ~"to be between 0-3") } @@ -508,8 +511,8 @@ fn build_session_options(matches: getopts::matches, } else { 0u }; let target = alt target_opt { - none { host_triple() } - some(s) { s } + none => host_triple(), + some(s) => s }; let addl_lib_search_paths = getopts::opt_strs(matches, ~"L"); @@ -626,43 +629,33 @@ fn build_output_filenames(input: input, let obj_suffix = alt sopts.output_type { - link::output_type_none { ~"none" } - link::output_type_bitcode { ~"bc" } - link::output_type_assembly { ~"s" } - link::output_type_llvm_assembly { ~"ll" } + link::output_type_none => ~"none", + link::output_type_bitcode => ~"bc", + link::output_type_assembly => ~"s", + link::output_type_llvm_assembly => ~"ll", // Object and exe output both use the '.o' extension here - link::output_type_object | link::output_type_exe { - ~"o" - } + link::output_type_object | link::output_type_exe => ~"o" }; alt ofile { - none { + none => { // "-" as input file will cause the parser to read from stdin so we // have to make up a name // We want to toss everything after the final '.' let dirname = alt odir { - some(d) { d } - none { - alt input { - str_input(_) { - os::getcwd() - } - file_input(ifile) { - path::dirname(ifile) - } - } + some(d) => d, + none => alt input { + str_input(_) => os::getcwd(), + file_input(ifile) => path::dirname(ifile) } }; let base_filename = alt input { - file_input(ifile) { + file_input(ifile) => { let (path, _) = path::splitext(ifile); path::basename(path) } - str_input(_) { - ~"rust_out" - } + str_input(_) => ~"rust_out" }; let base_path = path::connect(dirname, base_filename); @@ -678,7 +671,7 @@ fn build_output_filenames(input: input, } } - some(out_file) { + some(out_file) => { out_path = out_file; obj_path = if stop_after_codegen { out_file @@ -722,9 +715,9 @@ mod test { fn test_switch_implies_cfg_test() { let matches = alt getopts::getopts(~[~"--test"], opts()) { - ok(m) { m } - err(f) { fail ~"test_switch_implies_cfg_test: " + - getopts::fail_str(f); } + ok(m) => m, + err(f) => fail ~"test_switch_implies_cfg_test: " + + getopts::fail_str(f) }; let sessopts = build_session_options(matches, diagnostic::emit); let sess = build_session(sessopts, diagnostic::emit); @@ -738,8 +731,8 @@ mod test { fn test_switch_implies_cfg_test_unless_cfg_test() { let matches = alt getopts::getopts(~[~"--test", ~"--cfg=test"], opts()) { - ok(m) { m } - err(f) { + ok(m) => m, + err(f) => { fail ~"test_switch_implies_cfg_test_unless_cfg_test: " + getopts::fail_str(f); } diff --git a/src/rustc/driver/rustc.rs b/src/rustc/driver/rustc.rs index 14d00c2d547..483e1ca5808 100644 --- a/src/rustc/driver/rustc.rs +++ b/src/rustc/driver/rustc.rs @@ -96,10 +96,10 @@ fn describe_warnings() { io::println(fmt!{" %s %7.7s %s", padded(max_key, k), alt v.default { - lint::allow { ~"allow" } - lint::warn { ~"warn" } - lint::deny { ~"deny" } - lint::forbid { ~"forbid" } + lint::allow => ~"allow", + lint::warn => ~"warn", + lint::deny => ~"deny", + lint::forbid => ~"forbid" }, v.desc}); } @@ -125,8 +125,8 @@ fn run_compiler(args: ~[~str], demitter: diagnostic::emitter) { let matches = alt getopts::getopts(args, opts()) { - ok(m) { m } - err(f) { + ok(m) => m, + err(f) => { early_error(demitter, getopts::fail_str(f)) } }; @@ -153,8 +153,8 @@ fn run_compiler(args: ~[~str], demitter: diagnostic::emitter) { return; } let input = alt vec::len(matches.free) { - 0u { early_error(demitter, ~"no input filename given") } - 1u { + 0u => early_error(demitter, ~"no input filename given"), + 1u => { let ifile = matches.free[0]; if ifile == ~"-" { let src = str::from_bytes(io::stdin().read_whole_stream()); @@ -163,7 +163,7 @@ fn run_compiler(args: ~[~str], demitter: diagnostic::emitter) { file_input(ifile) } } - _ { early_error(demitter, ~"multiple input filenames provided") } + _ => early_error(demitter, ~"multiple input filenames provided") }; let sopts = build_session_options(matches, demitter); @@ -176,19 +176,19 @@ fn run_compiler(args: ~[~str], demitter: diagnostic::emitter) { ~"normal"), |a| parse_pretty(sess, a) ); alt pretty { - some::<pp_mode>(ppm) { + some::<pp_mode>(ppm) => { pretty_print_input(sess, cfg, input, ppm); return; } - none::<pp_mode> {/* continue */ } + none::<pp_mode> => {/* continue */ } } let ls = opt_present(matches, ~"ls"); if ls { alt input { - file_input(ifile) { + file_input(ifile) => { list_metadata(sess, ifile, io::stdout()); } - str_input(_) { + str_input(_) => { early_error(demitter, ~"can not list metadata for stdin"); } } @@ -241,8 +241,8 @@ fn monitor(+f: fn~(diagnostic::emitter)) { f(demitter) } { - result::ok(_) { /* fallthrough */ } - result::err(_) { + result::ok(_) => { /* fallthrough */ } + result::err(_) => { // Task failed without emitting a fatal diagnostic if comm::recv(p) == done { diagnostic::emit( diff --git a/src/rustc/driver/session.rs b/src/rustc/driver/session.rs index e70c97754b9..200dd1b00d7 100644 --- a/src/rustc/driver/session.rs +++ b/src/rustc/driver/session.rs @@ -153,9 +153,9 @@ impl session for session { fn span_lint_level(level: lint::level, sp: span, msg: ~str) { alt level { - lint::allow { } - lint::warn { self.span_warn(sp, msg); } - lint::deny | lint::forbid { + lint::allow => { }, + lint::warn => self.span_warn(sp, msg), + lint::deny | lint::forbid => { self.span_err(sp, msg); } } @@ -220,17 +220,17 @@ fn expect<T: copy>(sess: session, opt: option<T>, msg: fn() -> ~str) -> T { fn building_library(req_crate_type: crate_type, crate: @ast::crate, testing: bool) -> bool { alt req_crate_type { - bin_crate { false } - lib_crate { true } - unknown_crate { + bin_crate => false, + lib_crate => true, + unknown_crate => { if testing { false } else { alt syntax::attr::first_attr_value_str_by_name( crate.node.attrs, ~"crate_type") { - option::some(@~"lib") { true } - _ { false } + option::some(@~"lib") => true, + _ => false } } } @@ -241,10 +241,10 @@ fn sess_os_to_meta_os(os: os) -> metadata::loader::os { import metadata::loader; alt os { - os_win32 { loader::os_win32 } - os_linux { loader::os_linux } - os_macos { loader::os_macos } - os_freebsd { loader::os_freebsd } + os_win32 => loader::os_win32, + os_linux => loader::os_linux, + os_macos => loader::os_macos, + os_freebsd => loader::os_freebsd } } diff --git a/src/rustc/front/config.rs b/src/rustc/front/config.rs index 9deaae5ecf1..92035856ddf 100644 --- a/src/rustc/front/config.rs +++ b/src/rustc/front/config.rs @@ -83,17 +83,17 @@ fn fold_foreign_mod(cx: ctxt, nm: ast::foreign_mod, fn filter_stmt(cx: ctxt, &&stmt: @ast::stmt) -> option<@ast::stmt> { alt stmt.node { - ast::stmt_decl(decl, _) { + ast::stmt_decl(decl, _) => { alt decl.node { - ast::decl_item(item) { + ast::decl_item(item) => { if item_in_cfg(cx, item) { option::some(stmt) } else { option::none } } - _ { option::some(stmt) } + _ => option::some(stmt) } } - _ { option::some(stmt) } + _ => option::some(stmt) } } diff --git a/src/rustc/front/intrinsic_inject.rs b/src/rustc/front/intrinsic_inject.rs index 20656c23852..cc80a524f31 100644 --- a/src/rustc/front/intrinsic_inject.rs +++ b/src/rustc/front/intrinsic_inject.rs @@ -16,8 +16,8 @@ fn inject_intrinsic(sess: session, sess.parse_sess); let item = alt item { - some(i) { i } - none { + some(i) => i, + none => { sess.fatal(~"no item found in intrinsic module"); } }; diff --git a/src/rustc/front/test.rs b/src/rustc/front/test.rs index 87011c2ad33..66e430f27cd 100644 --- a/src/rustc/front/test.rs +++ b/src/rustc/front/test.rs @@ -71,12 +71,12 @@ fn fold_mod(_cx: test_ctxt, m: ast::_mod, fld: fold::ast_fold) -> ast::_mod { // indicate to the translation pass which function we want to be main. fn nomain(&&item: @ast::item) -> option<@ast::item> { alt item.node { - ast::item_fn(_, _, _) { + ast::item_fn(_, _, _) => { if *item.ident == ~"main" { option::none } else { option::some(item) } } - _ { option::some(item) } + _ => option::some(item) } } @@ -103,12 +103,12 @@ fn fold_item(cx: test_ctxt, &&i: @ast::item, fld: fold::ast_fold) -> if is_test_fn(i) { alt i.node { - ast::item_fn(decl, _, _) if decl.purity == ast::unsafe_fn { + ast::item_fn(decl, _, _) if decl.purity == ast::unsafe_fn => { cx.sess.span_fatal( i.span, ~"unsafe functions cannot be used for tests"); } - _ { + _ => { debug!{"this is a test function"}; let test = {span: i.span, path: cx.path, ignore: is_ignored(cx, i), @@ -130,13 +130,13 @@ fn is_test_fn(i: @ast::item) -> bool { fn has_test_signature(i: @ast::item) -> bool { alt i.node { - ast::item_fn(decl, tps, _) { + ast::item_fn(decl, tps, _) => { let input_cnt = vec::len(decl.inputs); let no_output = decl.output.node == ast::ty_nil; let tparm_cnt = vec::len(tps); input_cnt == 0u && no_output && tparm_cnt == 0u } - _ { false } + _ => false } } @@ -247,8 +247,8 @@ fn mk_path(cx: test_ctxt, path: ~[ast::ident]) -> ~[ast::ident] { let is_std = { let items = attr::find_linkage_metas(cx.crate.node.attrs); alt attr::last_meta_item_value_str_by_name(items, ~"name") { - some(@~"std") { true } - _ { false } + some(@~"std") => true, + _ => false } }; if is_std { path } diff --git a/src/rustc/lib/llvm.rs b/src/rustc/lib/llvm.rs index be758ee699b..1effed07f13 100644 --- a/src/rustc/lib/llvm.rs +++ b/src/rustc/lib/llvm.rs @@ -1016,8 +1016,8 @@ fn type_to_str(names: type_names, ty: TypeRef) -> ~str { fn type_to_str_inner(names: type_names, outer0: ~[TypeRef], ty: TypeRef) -> ~str { alt type_has_name(names, ty) { - option::some(n) { return n; } - _ {} + option::some(n) => return n, + _ => {} } let outer = vec::append_one(outer0, ty); @@ -1036,18 +1036,18 @@ fn type_to_str_inner(names: type_names, outer0: ~[TypeRef], ty: TypeRef) -> } alt kind { - Void { return ~"Void"; } - Half { return ~"Half"; } - Float { return ~"Float"; } - Double { return ~"Double"; } - X86_FP80 { return ~"X86_FP80"; } - FP128 { return ~"FP128"; } - PPC_FP128 { return ~"PPC_FP128"; } - Label { return ~"Label"; } - Integer { + Void => return ~"Void", + Half => return ~"Half", + Float => return ~"Float", + Double => return ~"Double", + X86_FP80 => return ~"X86_FP80", + FP128 => return ~"FP128", + PPC_FP128 => return ~"PPC_FP128", + Label => return ~"Label", + Integer => { return ~"i" + int::str(llvm::LLVMGetIntTypeWidth(ty) as int); } - Function { + Function => { let mut s = ~"fn("; let out_ty: TypeRef = llvm::LLVMGetReturnType(ty); let n_args = llvm::LLVMCountParamTypes(ty) as uint; @@ -1060,7 +1060,7 @@ fn type_to_str_inner(names: type_names, outer0: ~[TypeRef], ty: TypeRef) -> s += type_to_str_inner(names, outer, out_ty); return s; } - Struct { + Struct => { let mut s: ~str = ~"{"; let n_elts = llvm::LLVMCountStructElementTypes(ty) as uint; let elts = vec::from_elem(n_elts, 0 as TypeRef); @@ -1071,12 +1071,12 @@ fn type_to_str_inner(names: type_names, outer0: ~[TypeRef], ty: TypeRef) -> s += ~"}"; return s; } - Array { + Array => { let el_ty = llvm::LLVMGetElementType(ty); return ~"[" + type_to_str_inner(names, outer, el_ty) + ~" x " + uint::str(llvm::LLVMGetArrayLength(ty) as uint) + ~"]"; } - Pointer { + Pointer => { let mut i: uint = 0u; for outer0.each |tout| { i += 1u; @@ -1096,19 +1096,19 @@ fn type_to_str_inner(names: type_names, outer0: ~[TypeRef], ty: TypeRef) -> return addrstr + ~"*" + type_to_str_inner(names, outer, llvm::LLVMGetElementType(ty)); } - Vector { return ~"Vector"; } - Metadata { return ~"Metadata"; } - X86_MMX { return ~"X86_MMAX"; } + Vector => return ~"Vector", + Metadata => return ~"Metadata", + X86_MMX => return ~"X86_MMAX" } } fn float_width(llt: TypeRef) -> uint { return alt llvm::LLVMGetTypeKind(llt) as int { - 1 { 32u } - 2 { 64u } - 3 { 80u } - 4 | 5 { 128u } - _ { fail ~"llvm_float_width called on a non-float type" } + 1 => 32u, + 2 => 64u, + 3 => 80u, + 4 | 5 => 128u, + _ => fail ~"llvm_float_width called on a non-float type" }; } diff --git a/src/rustc/metadata/creader.rs b/src/rustc/metadata/creader.rs index 06eb2bea3d2..03dd9c389dd 100644 --- a/src/rustc/metadata/creader.rs +++ b/src/rustc/metadata/creader.rs @@ -101,30 +101,30 @@ type env = @{diag: span_handler, fn visit_view_item(e: env, i: @ast::view_item) { alt i.node { - ast::view_item_use(ident, meta_items, id) { + ast::view_item_use(ident, meta_items, id) => { debug!{"resolving use stmt. ident: %?, meta: %?", ident, meta_items}; let cnum = resolve_crate(e, ident, meta_items, ~"", i.span); cstore::add_use_stmt_cnum(e.cstore, id, cnum); } - _ { } + _ => () } } fn visit_item(e: env, i: @ast::item) { alt i.node { - ast::item_foreign_mod(m) { + ast::item_foreign_mod(m) => { alt attr::foreign_abi(i.attrs) { - either::right(abi) { + either::right(abi) => { if abi != ast::foreign_abi_cdecl && abi != ast::foreign_abi_stdcall { return; } } - either::left(msg) { e.diag.span_fatal(i.span, msg); } + either::left(msg) => e.diag.span_fatal(i.span, msg) } let cstore = e.cstore; let foreign_name = alt attr::first_attr_value_str_by_name(i.attrs, ~"link_name") { - some(nn) { + some(nn) => { if *nn == ~"" { e.diag.span_fatal( i.span, @@ -132,7 +132,7 @@ fn visit_item(e: env, i: @ast::item) { } nn } - none { i.ident } + none => i.ident }; let mut already_added = false; if vec::len(attr::find_attrs_by_name(i.attrs, ~"nolink")) == 0u { @@ -145,14 +145,14 @@ fn visit_item(e: env, i: @ast::item) { } for link_args.each |a| { alt attr::get_meta_item_value_str(attr::attr_meta(a)) { - some(linkarg) { + some(linkarg) => { cstore::add_used_link_args(cstore, *linkarg); } - none {/* fallthrough */ } + none => {/* fallthrough */ } } } } - _ { } + _ => { } } } @@ -188,7 +188,7 @@ fn resolve_crate(e: env, ident: ast::ident, metas: ~[@ast::meta_item], let metas = metas_with_ident(ident, metas); alt existing_match(e, metas, hash) { - none { + none => { let load_ctxt: loader::ctxt = { diag: e.diag, filesearch: e.filesearch, @@ -219,8 +219,8 @@ fn resolve_crate(e: env, ident: ast::ident, metas: ~[@ast::meta_item], let cname = alt attr::last_meta_item_value_str_by_name(metas, ~"name") { - option::some(v) { v } - option::none { ident } + option::some(v) => v, + option::none => ident }; let cmeta = @{name: *cname, data: cdata, cnum_map: cnum_map, cnum: cnum}; @@ -230,7 +230,7 @@ fn resolve_crate(e: env, ident: ast::ident, metas: ~[@ast::meta_item], cstore::add_used_crate_file(cstore, cfilename); return cnum; } - some(cnum) { + some(cnum) => { return cnum; } } @@ -249,12 +249,12 @@ fn resolve_crate_deps(e: env, cdata: @~[u8]) -> cstore::cnum_map { debug!{"resolving dep crate %s ver: %s hash: %s", *dep.name, *dep.vers, *dep.hash}; alt existing_match(e, metas_with_ident(cname, cmetas), *dep.hash) { - some(local_cnum) { + some(local_cnum) => { debug!{"already have it"}; // We've already seen this crate cnum_map.insert(extrn_cnum, local_cnum); } - none { + none => { debug!{"need to load it"}; // This is a new one so we've got to load it // FIXME (#2404): Need better error reporting than just a bogus diff --git a/src/rustc/metadata/csearch.rs b/src/rustc/metadata/csearch.rs index 9e2b7c174ef..1a536ca1bdd 100644 --- a/src/rustc/metadata/csearch.rs +++ b/src/rustc/metadata/csearch.rs @@ -58,7 +58,7 @@ fn lookup_method_purity(cstore: cstore::cstore, did: ast::def_id) -> ast::purity { let cdata = cstore::get_crate_data(cstore, did.crate).data; alt check decoder::lookup_def(did.crate, cdata, did) { - ast::def_fn(_, p) { p } + ast::def_fn(_, p) => p } } diff --git a/src/rustc/metadata/cstore.rs b/src/rustc/metadata/cstore.rs index 6c329b81539..a177b264e5b 100644 --- a/src/rustc/metadata/cstore.rs +++ b/src/rustc/metadata/cstore.rs @@ -64,7 +64,7 @@ type use_crate_map = map::hashmap<ast::node_id, ast::crate_num>; // Internal method to retrieve the data from the cstore pure fn p(cstore: cstore) -> cstore_private { - alt cstore { private(p) { p } } + alt cstore { private(p) => p } } fn mk_cstore() -> cstore { diff --git a/src/rustc/metadata/decoder.rs b/src/rustc/metadata/decoder.rs index 17a00827f6a..2e4a670c841 100644 --- a/src/rustc/metadata/decoder.rs +++ b/src/rustc/metadata/decoder.rs @@ -100,8 +100,8 @@ fn find_item(item_id: int, items: ebml::doc) -> ebml::doc { fn lookup_item(item_id: int, data: @~[u8]) -> ebml::doc { let items = ebml::get_doc(ebml::doc(data), tag_items); alt maybe_find_item(item_id, items) { - none { fail(fmt!{"lookup_item: id not found: %d", item_id}); } - some(d) { d } + none => fail(fmt!{"lookup_item: id not found: %d", item_id}), + some(d) => d } } @@ -136,8 +136,8 @@ fn field_mutability(d: ebml::doc) -> ast::class_mutability { ast::class_immutable, |d| { alt ebml::doc_as_u8(d) as char { - 'm' { ast::class_mutable } - _ { ast::class_immutable } + 'm' => ast::class_mutable, + _ => ast::class_immutable } }) } @@ -185,8 +185,8 @@ fn item_ty_param_bounds(item: ebml::doc, tcx: ty::ctxt, cdata: cmd) fn item_ty_region_param(item: ebml::doc) -> bool { alt ebml::maybe_get_doc(item, tag_region_param) { - some(_) { true } - none { false } + some(_) => true, + none => false } } @@ -276,26 +276,26 @@ fn item_to_def_like(item: ebml::doc, did: ast::def_id, cnum: ast::crate_num) -> def_like { let fam_ch = item_family(item); alt fam_ch { - 'c' { dl_def(ast::def_const(did)) } - 'C' { dl_def(ast::def_class(did, true)) } - 'S' { dl_def(ast::def_class(did, false)) } - 'u' { dl_def(ast::def_fn(did, ast::unsafe_fn)) } - 'f' { dl_def(ast::def_fn(did, ast::impure_fn)) } - 'p' { dl_def(ast::def_fn(did, ast::pure_fn)) } - 'F' { dl_def(ast::def_fn(did, ast::extern_fn)) } - 'y' { dl_def(ast::def_ty(did)) } - 't' { dl_def(ast::def_ty(did)) } - 'm' { dl_def(ast::def_mod(did)) } - 'n' { dl_def(ast::def_foreign_mod(did)) } - 'v' { + 'c' => dl_def(ast::def_const(did)), + 'C' => dl_def(ast::def_class(did, true)), + 'S' => dl_def(ast::def_class(did, false)), + 'u' => dl_def(ast::def_fn(did, ast::unsafe_fn)), + 'f' => dl_def(ast::def_fn(did, ast::impure_fn)), + 'p' => dl_def(ast::def_fn(did, ast::pure_fn)), + 'F' => dl_def(ast::def_fn(did, ast::extern_fn)), + 'y' => dl_def(ast::def_ty(did)), + 't' => dl_def(ast::def_ty(did)), + 'm' => dl_def(ast::def_mod(did)), + 'n' => dl_def(ast::def_foreign_mod(did)), + 'v' => { let mut tid = option::get(item_parent_item(item)); tid = {crate: cnum, node: tid.node}; dl_def(ast::def_variant(tid, did)) } - 'I' { dl_def(ast::def_ty(did)) } - 'i' { dl_impl(did) } - 'g' | 'j' | 'N' => { dl_field } - ch { fail fmt!{"unexpected family code: '%c'", ch} } + 'I' => dl_def(ast::def_ty(did)), + 'i' => dl_impl(did), + 'g' | 'j' | 'N' => dl_field, + ch => fail fmt!{"unexpected family code: '%c'", ch} } } @@ -350,9 +350,10 @@ fn get_class_method(cdata: cmd, id: ast::node_id, let items = ebml::get_doc(ebml::doc(cdata.data), tag_items); let mut found = none; let cls_items = alt maybe_find_item(id, items) { - some(it) { it } - none { fail (fmt!{"get_class_method: class id not found \ - when looking up method %s", *name}) }}; + some(it) => it, + none => fail (fmt!{"get_class_method: class id not found \ + when looking up method %s", *name}) + }; for ebml::tagged_docs(cls_items, tag_item_trait_method) |mid| { let m_did = class_member_id(mid, cdata); if item_name(mid) == name { @@ -360,8 +361,8 @@ fn get_class_method(cdata: cmd, id: ast::node_id, } } alt found { - some(found) { found } - none { fail (fmt!{"get_class_method: no method named %s", *name}) } + some(found) => found, + none => fail (fmt!{"get_class_method: no method named %s", *name}) } } @@ -369,9 +370,9 @@ fn class_dtor(cdata: cmd, id: ast::node_id) -> option<ast::def_id> { let items = ebml::get_doc(ebml::doc(cdata.data), tag_items); let mut found = none; let cls_items = alt maybe_find_item(id, items) { - some(it) { it } - none { fail (fmt!{"class_dtor: class id not found \ - when looking up dtor for %d", id}); } + some(it) => it, + none => fail (fmt!{"class_dtor: class id not found \ + when looking up dtor for %d", id}) }; for ebml::tagged_docs(cls_items, tag_item_dtor) |doc| { let doc1 = ebml::get_doc(doc, tag_def_id); @@ -394,9 +395,9 @@ enum def_like { fn def_like_to_def(def_like: def_like) -> ast::def { alt def_like { - dl_def(def) { return def; } - dl_impl(*) { fail ~"found impl in def_like_to_def"; } - dl_field { fail ~"found field in def_like_to_def"; } + dl_def(def) => return def, + dl_impl(*) => fail ~"found impl in def_like_to_def", + dl_field => fail ~"found field in def_like_to_def" } } @@ -467,11 +468,11 @@ fn each_path(cdata: cmd, f: fn(path_entry) -> bool) { // Get the item. alt maybe_find_item(def_id.node, items) { - none { + none => { debug!{"(each_path) ignoring implicit item: %s", *path}; } - some(item_doc) { + some(item_doc) => { // Construct the def for this item. let def_like = item_to_def_like(item_doc, def_id, cdata.cnum); @@ -515,19 +516,19 @@ fn maybe_get_item_ast(cdata: cmd, tcx: ty::ctxt, let item_doc = lookup_item(id, cdata.data); let path = vec::init(item_path(item_doc)); alt decode_inlined_item(cdata, tcx, path, item_doc) { - some(ii) { csearch::found(ii) } - none { + some(ii) => csearch::found(ii), + none => { alt item_parent_item(item_doc) { - some(did) { + some(did) => { let did = translate_def_id(cdata, did); let parent_item = lookup_item(did.node, cdata.data); alt decode_inlined_item(cdata, tcx, path, parent_item) { - some(ii) { csearch::found_parent(did, ii) } - none { csearch::not_found } + some(ii) => csearch::found_parent(did, ii), + none => csearch::not_found } } - none { csearch::not_found } + none => csearch::not_found } } } @@ -548,14 +549,14 @@ fn get_enum_variants(cdata: cmd, id: ast::node_id, tcx: ty::ctxt) let name = item_name(item); let mut arg_tys: ~[ty::t] = ~[]; alt ty::get(ctor_ty).struct { - ty::ty_fn(f) { + ty::ty_fn(f) => { for f.inputs.each |a| { vec::push(arg_tys, a.ty); } } - _ { /* Nullary enum variant. */ } + _ => { /* Nullary enum variant. */ } } alt variant_disr_val(item) { - some(val) { disr_val = val; } - _ { /* empty */ } + some(val) => { disr_val = val; } + _ => { /* empty */ } } vec::push(infos, @{args: arg_tys, ctor_ty: ctor_ty, name: name, id: did, disr_val: disr_val}); @@ -653,7 +654,7 @@ fn get_impls_for_mod(cdata: cmd, let impl_data = impl_cdata.data; let item = lookup_item(local_did.node, impl_data); let nm = item_name(item); - if alt name { some(n) { n == nm } none { true } } { + if alt name { some(n) => { n == nm } none => { true } } { let base_tps = item_ty_param_count(item); vec::push(result, @{ did: local_did, ident: nm, @@ -674,8 +675,9 @@ fn get_trait_methods(cdata: cmd, id: ast::node_id, tcx: ty::ctxt) let bounds = item_ty_param_bounds(mth, tcx, cdata); let name = item_name(mth); let ty = doc_type(mth, tcx, cdata); - let fty = alt ty::get(ty).struct { ty::ty_fn(f) { f } - _ { + let fty = alt ty::get(ty).struct { + ty::ty_fn(f) => f, + _ => { tcx.diag.handler().bug( ~"get_trait_methods: id has non-function type"); } }; @@ -683,9 +685,9 @@ fn get_trait_methods(cdata: cmd, id: ast::node_id, tcx: ty::ctxt) vec::push(result, {ident: name, tps: bounds, fty: fty, self_ty: self_ty, purity: alt check item_family(mth) { - 'u' { ast::unsafe_fn } - 'f' { ast::impure_fn } - 'p' { ast::pure_fn } + 'u' => ast::unsafe_fn, + 'f' => ast::impure_fn, + 'p' => ast::pure_fn }, vis: ast::public}); } @result @@ -755,15 +757,15 @@ fn get_class_fields(cdata: cmd, id: ast::node_id) -> ~[ty::field_ty] { fn family_has_type_params(fam_ch: char) -> bool { alt check fam_ch { - 'c' | 'T' | 'm' | 'n' | 'g' | 'h' | 'j' { false } + 'c' | 'T' | 'm' | 'n' | 'g' | 'h' | 'j' => false, 'f' | 'u' | 'p' | 'F' | 'U' | 'P' | 'y' | 't' | 'v' | 'i' | 'I' | 'C' | 'a' | 'S' - { true } + => true } } fn family_names_type(fam_ch: char) -> bool { - alt fam_ch { 'y' | 't' | 'I' { true } _ { false } } + alt fam_ch { 'y' | 't' | 'I' => true, _ => false } } fn read_path(d: ebml::doc) -> {path: ~str, pos: uint} { @@ -777,34 +779,34 @@ fn read_path(d: ebml::doc) -> {path: ~str, pos: uint} { fn describe_def(items: ebml::doc, id: ast::def_id) -> ~str { if id.crate != ast::local_crate { return ~"external"; } let it = alt maybe_find_item(id.node, items) { - some(it) { it } - none { fail (fmt!{"describe_def: item not found %?", id}); } + some(it) => it, + none => fail (fmt!{"describe_def: item not found %?", id}) }; return item_family_to_str(item_family(it)); } fn item_family_to_str(fam: char) -> ~str { alt check fam { - 'c' { return ~"const"; } - 'f' { return ~"fn"; } - 'u' { return ~"unsafe fn"; } - 'p' { return ~"pure fn"; } - 'F' { return ~"foreign fn"; } - 'U' { return ~"unsafe foreign fn"; } - 'P' { return ~"pure foreign fn"; } - 'y' { return ~"type"; } - 'T' { return ~"foreign type"; } - 't' { return ~"type"; } - 'm' { return ~"mod"; } - 'n' { return ~"foreign mod"; } - 'v' { return ~"enum"; } - 'i' { return ~"impl"; } - 'I' { return ~"trait"; } - 'C' { return ~"class"; } - 'S' { return ~"struct"; } - 'g' { return ~"public field"; } - 'j' { return ~"private field"; } - 'N' { return ~"inherited field"; } + 'c' => return ~"const", + 'f' => return ~"fn", + 'u' => return ~"unsafe fn", + 'p' => return ~"pure fn", + 'F' => return ~"foreign fn", + 'U' => return ~"unsafe foreign fn", + 'P' => return ~"pure foreign fn", + 'y' => return ~"type", + 'T' => return ~"foreign type", + 't' => return ~"type", + 'm' => return ~"mod", + 'n' => return ~"foreign mod", + 'v' => return ~"enum", + 'i' => return ~"impl", + 'I' => return ~"trait", + 'C' => return ~"class", + 'S' => return ~"struct", + 'g' => return ~"public field", + 'j' => return ~"private field", + 'N' => return ~"inherited field" } } @@ -836,7 +838,7 @@ fn get_meta_items(md: ebml::doc) -> ~[@ast::meta_item] { fn get_attributes(md: ebml::doc) -> ~[ast::attribute] { let mut attrs: ~[ast::attribute] = ~[]; alt ebml::maybe_get_doc(md, tag_attributes) { - option::some(attrs_d) { + option::some(attrs_d) => { for ebml::tagged_docs(attrs_d, tag_attribute) |attr_doc| { let meta_items = get_meta_items(attr_doc); // Currently it's only possible to have a single meta item on @@ -849,7 +851,7 @@ fn get_attributes(md: ebml::doc) -> ~[ast::attribute] { span: ast_util::dummy_sp()}); }; } - option::none { } + option::none => () } return attrs; } @@ -916,8 +918,8 @@ fn get_crate_vers(data: @~[u8]) -> @~str { let attrs = decoder::get_crate_attributes(data); return alt attr::last_meta_item_value_str_by_name( attr::find_linkage_metas(attrs), ~"vers") { - some(ver) { ver } - none { @~"0.0" } + some(ver) => ver, + none => @~"0.0" }; } @@ -996,8 +998,8 @@ fn translate_def_id(cdata: cmd, did: ast::def_id) -> ast::def_id { } alt cdata.cnum_map.find(did.crate) { - option::some(n) { return {crate: n, node: did.node}; } - option::none { fail ~"didn't find a crate in the cnum_map"; } + option::some(n) => return {crate: n, node: did.node}, + option::none => fail ~"didn't find a crate in the cnum_map" } } diff --git a/src/rustc/metadata/encoder.rs b/src/rustc/metadata/encoder.rs index a5d398c7ad0..fc23c8b351c 100644 --- a/src/rustc/metadata/encoder.rs +++ b/src/rustc/metadata/encoder.rs @@ -101,9 +101,12 @@ fn encode_named_def_id(ebml_w: ebml::writer, name: ident, id: def_id) { fn encode_mutability(ebml_w: ebml::writer, mt: class_mutability) { do ebml_w.wr_tag(tag_class_mut) { - ebml_w.writer.write(&[alt mt { class_immutable { 'i' } - class_mutable { 'm' } } as u8]); - } + let val = alt mt { + class_immutable => 'i', + class_mutable => 'm' + }; + ebml_w.writer.write(&[val as u8]); + } } type entry<T> = {val: T, pos: uint}; @@ -143,11 +146,11 @@ fn encode_class_item_paths(ebml_w: ebml::writer, items: ~[@class_member], path: ~[ident], &index: ~[entry<~str>]) { for items.each |it| { alt ast_util::class_member_visibility(it) { - private { again; } - public | inherited { + private => again, + public | inherited => { let (id, ident) = alt it.node { - instance_var(v, _, _, vid, _) { (vid, v) } - class_method(it) { (it.id, it.ident) } + instance_var(v, _, _, vid, _) => (vid, v), + class_method(it) => (it.id, it.ident) }; add_to_index(ebml_w, path, index, ident); encode_named_def_id(ebml_w, ident, local_def(id)); @@ -166,13 +169,13 @@ fn encode_module_item_paths(ebml_w: ebml::writer, ecx: @encode_ctxt, add_to_index(ebml_w, path, index, it.ident); } alt it.node { - item_const(_, _) { + item_const(_, _) => { encode_named_def_id(ebml_w, it.ident, local_def(it.id)); } - item_fn(_, tps, _) { + item_fn(_, tps, _) => { encode_named_def_id(ebml_w, it.ident, local_def(it.id)); } - item_mod(_mod) { + item_mod(_mod) => { do ebml_w.wr_tag(tag_paths_data_mod) { encode_name_and_def_id(ebml_w, it.ident, it.id); encode_module_item_paths(ebml_w, ecx, _mod, @@ -180,7 +183,7 @@ fn encode_module_item_paths(ebml_w: ebml::writer, ecx: @encode_ctxt, index); } } - item_foreign_mod(nmod) { + item_foreign_mod(nmod) => { do ebml_w.wr_tag(tag_paths_data_mod) { encode_name_and_def_id(ebml_w, it.ident, it.id); encode_foreign_module_item_paths( @@ -188,12 +191,12 @@ fn encode_module_item_paths(ebml_w: ebml::writer, ecx: @encode_ctxt, vec::append_one(path, it.ident), index); } } - item_ty(_, tps) { + item_ty(_, tps) => { do ebml_w.wr_tag(tag_paths_data_item) { encode_name_and_def_id(ebml_w, it.ident, it.id); } } - item_class(_, _, items, m_ctor, m_dtor) { + item_class(_, _, items, m_ctor, m_dtor) => { do ebml_w.wr_tag(tag_paths_data_item) { encode_name_and_def_id(ebml_w, it.ident, it.id); } @@ -206,7 +209,7 @@ fn encode_module_item_paths(ebml_w: ebml::writer, ecx: @encode_ctxt, none => { // Nothing to do. } - some(ctor) { + some(ctor) => { encode_named_def_id(ebml_w, it.ident, local_def(ctor.node.id)); } @@ -217,19 +220,19 @@ fn encode_module_item_paths(ebml_w: ebml::writer, ecx: @encode_ctxt, index); } } - item_enum(variants, _) { + item_enum(variants, _) => { do ebml_w.wr_tag(tag_paths_data_item) { encode_name_and_def_id(ebml_w, it.ident, it.id); } encode_enum_variant_paths(ebml_w, variants, path, index); } - item_trait(*) { + item_trait(*) => { do ebml_w.wr_tag(tag_paths_data_item) { encode_name_and_def_id(ebml_w, it.ident, it.id); } } - item_impl(*) {} - item_mac(*) { fail ~"item macros unimplemented" } + item_impl(*) => {} + item_mac(*) => fail ~"item macros unimplemented" } } } @@ -315,8 +318,8 @@ fn encode_type(ecx: @encode_ctxt, ebml_w: ebml::writer, typ: ty::t) { fn encode_symbol(ecx: @encode_ctxt, ebml_w: ebml::writer, id: node_id) { ebml_w.start_tag(tag_items_data_item_symbol); let sym = alt ecx.item_symbols.find(id) { - some(x) { x } - none { + some(x) => x, + none => { ecx.diag.handler().bug( fmt!{"encode_symbol: id not found %d", id}); } @@ -380,8 +383,8 @@ fn encode_path(ebml_w: ebml::writer, name: ast_map::path_elt) { fn encode_path_elt(ebml_w: ebml::writer, elt: ast_map::path_elt) { let (tag, name) = alt elt { - ast_map::path_mod(name) { (tag_path_elt_mod, name) } - ast_map::path_name(name) { (tag_path_elt_name, name) } + ast_map::path_mod(name) => (tag_path_elt_mod, name), + ast_map::path_name(name) => (tag_path_elt_name, name) }; ebml_w.wr_tagged_str(tag, *name); @@ -414,12 +417,12 @@ fn encode_info_for_mod(ecx: @encode_ctxt, ebml_w: ebml::writer, md: _mod, ebml_w.start_tag(tag_mod_impl); alt ecx.tcx.items.find(did.node) { - some(ast_map::node_item(it@@{node: cl@item_class(*),_},_)) { + some(ast_map::node_item(it@@{node: cl@item_class(*),_},_)) => { /* If did stands for a trait ref, we need to map it to its parent class */ ebml_w.wr_str(def_to_str(local_def(it.id))); } - _ { + _ => { // Must be a re-export, then! // ...or a trait ref ebml_w.wr_str(def_to_str(did)); @@ -434,7 +437,9 @@ fn encode_info_for_mod(ecx: @encode_ctxt, ebml_w: ebml::writer, md: _mod, fn encode_visibility(ebml_w: ebml::writer, visibility: visibility) { encode_family(ebml_w, alt visibility { - public { 'g' } private { 'j' } inherited { 'N' } + public => 'g', + private => 'j', + inherited => 'N' }); } @@ -504,7 +509,7 @@ fn encode_info_for_class(ecx: @encode_ctxt, ebml_w: ebml::writer, /* We encode both private and public fields -- need to include private fields to get the offsets right */ alt ci.node { - instance_var(nm, _, mt, id, vis) { + instance_var(nm, _, mt, id, vis) => { vec::push(*index, {val: id, pos: ebml_w.writer.tell()}); vec::push(*global_index, {val: id, pos: ebml_w.writer.tell()}); ebml_w.start_tag(tag_items_data_item); @@ -517,9 +522,9 @@ fn encode_info_for_class(ecx: @encode_ctxt, ebml_w: ebml::writer, encode_def_id(ebml_w, local_def(id)); ebml_w.end_tag(); } - class_method(m) { + class_method(m) => { alt m.vis { - public | inherited { + public | inherited => { vec::push(*index, {val: m.id, pos: ebml_w.writer.tell()}); vec::push(*global_index, {val: m.id, pos: ebml_w.writer.tell()}); @@ -530,7 +535,7 @@ fn encode_info_for_class(ecx: @encode_ctxt, ebml_w: ebml::writer, should_inline(m.attrs), id, m, vec::append(class_tps, m.tps)); } - _ { /* don't encode private methods */ } + _ => { /* don't encode private methods */ } } } } @@ -553,10 +558,10 @@ fn encode_info_for_fn(ecx: @encode_ctxt, ebml_w: ebml::writer, encode_type(ecx, ebml_w, its_ty); encode_path(ebml_w, path, ast_map::path_name(ident)); alt item { - some(it) { + some(it) => { ecx.encode_inlined_item(ecx, ebml_w, path, it); } - none { + none => { encode_symbol(ecx, ebml_w, id); } } @@ -588,18 +593,18 @@ fn encode_info_for_method(ecx: @encode_ctxt, ebml_w: ebml::writer, fn purity_fn_family(p: purity) -> char { alt p { - unsafe_fn { 'u' } - pure_fn { 'p' } - impure_fn { 'f' } - extern_fn { 'F' } + unsafe_fn => 'u', + pure_fn => 'p', + impure_fn => 'f', + extern_fn => 'F' } } fn should_inline(attrs: ~[attribute]) -> bool { alt attr::find_inline_attr(attrs) { - attr::ia_none | attr::ia_never { false } - attr::ia_hint | attr::ia_always { true } + attr::ia_none | attr::ia_never => false, + attr::ia_hint | attr::ia_always => true } } @@ -610,12 +615,9 @@ fn encode_info_for_item(ecx: @encode_ctxt, ebml_w: ebml::writer, item: @item, let tcx = ecx.tcx; let must_write = alt item.node { - item_enum(_, _) | item_impl(*) | item_trait(*) | item_class(*) { - true - } - _ { - false - } + item_enum(_, _) | item_impl(*) + | item_trait(*) | item_class(*) => true, + _ => false }; if !must_write && !reachable(ecx, item.id) { return; } @@ -626,7 +628,7 @@ fn encode_info_for_item(ecx: @encode_ctxt, ebml_w: ebml::writer, item: @item, let add_to_index = |copy ebml_w| add_to_index_(item, ebml_w, index); alt item.node { - item_const(_, _) { + item_const(_, _) => { add_to_index(); ebml_w.start_tag(tag_items_data_item); encode_def_id(ebml_w, local_def(item.id)); @@ -636,7 +638,7 @@ fn encode_info_for_item(ecx: @encode_ctxt, ebml_w: ebml::writer, item: @item, encode_path(ebml_w, path, ast_map::path_name(item.ident)); ebml_w.end_tag(); } - item_fn(decl, tps, _) { + item_fn(decl, tps, _) => { add_to_index(); ebml_w.start_tag(tag_items_data_item); encode_def_id(ebml_w, local_def(item.id)); @@ -651,11 +653,11 @@ fn encode_info_for_item(ecx: @encode_ctxt, ebml_w: ebml::writer, item: @item, } ebml_w.end_tag(); } - item_mod(m) { + item_mod(m) => { add_to_index(); encode_info_for_mod(ecx, ebml_w, m, item.id, path, item.ident); } - item_foreign_mod(_) { + item_foreign_mod(_) => { add_to_index(); ebml_w.start_tag(tag_items_data_item); encode_def_id(ebml_w, local_def(item.id)); @@ -664,7 +666,7 @@ fn encode_info_for_item(ecx: @encode_ctxt, ebml_w: ebml::writer, item: @item, encode_path(ebml_w, path, ast_map::path_name(item.ident)); ebml_w.end_tag(); } - item_ty(_, tps) { + item_ty(_, tps) => { add_to_index(); ebml_w.start_tag(tag_items_data_item); encode_def_id(ebml_w, local_def(item.id)); @@ -676,7 +678,7 @@ fn encode_info_for_item(ecx: @encode_ctxt, ebml_w: ebml::writer, item: @item, encode_region_param(ecx, ebml_w, item); ebml_w.end_tag(); } - item_enum(variants, tps) { + item_enum(variants, tps) => { add_to_index(); do ebml_w.wr_tag(tag_items_data_item) { encode_def_id(ebml_w, local_def(item.id)); @@ -694,7 +696,7 @@ fn encode_info_for_item(ecx: @encode_ctxt, ebml_w: ebml::writer, item: @item, encode_enum_variant_info(ecx, ebml_w, item.id, variants, path, index, tps); } - item_class(tps, traits, items, ctor, m_dtor) { + item_class(tps, traits, items, ctor, m_dtor) => { /* First, encode the fields and methods These come first because we need to write them to make the index, and the index needs to be in the item for the @@ -718,12 +720,8 @@ fn encode_info_for_item(ecx: @encode_ctxt, ebml_w: ebml::writer, item: @item, encode_def_id(ebml_w, local_def(item.id)); alt ctor { - none { - encode_family(ebml_w, 'S'); - } - some(_) { - encode_family(ebml_w, 'C'); - } + none => encode_family(ebml_w, 'S'), + some(_) => encode_family(ebml_w, 'C') } encode_type_param_bounds(ebml_w, ecx, tps); @@ -755,8 +753,8 @@ fn encode_info_for_item(ecx: @encode_ctxt, ebml_w: ebml::writer, item: @item, } for ms.each |m| { alt m.vis { - private { /* do nothing */ } - public | inherited { + private => { /* do nothing */ } + public | inherited => { /* Write the info that's needed when viewing this class as a trait */ ebml_w.start_tag(tag_item_trait_method); @@ -780,7 +778,7 @@ fn encode_info_for_item(ecx: @encode_ctxt, ebml_w: ebml::writer, item: @item, encode_index(ebml_w, bkts, write_int); ebml_w.end_tag(); } - item_impl(tps, traits, _, methods) { + item_impl(tps, traits, _, methods) => { add_to_index(); ebml_w.start_tag(tag_items_data_item); encode_def_id(ebml_w, local_def(item.id)); @@ -813,7 +811,7 @@ fn encode_info_for_item(ecx: @encode_ctxt, ebml_w: ebml::writer, item: @item, vec::append(tps, m.tps)); } } - item_trait(tps, traits, ms) { + item_trait(tps, traits, ms) => { add_to_index(); ebml_w.start_tag(tag_items_data_item); encode_def_id(ebml_w, local_def(item.id)); @@ -826,7 +824,7 @@ fn encode_info_for_item(ecx: @encode_ctxt, ebml_w: ebml::writer, item: @item, let mut i = 0u; for vec::each(*ty::trait_methods(tcx, local_def(item.id))) |mty| { alt ms[i] { - required(ty_m) { + required(ty_m) => { ebml_w.start_tag(tag_item_trait_method); encode_name(ebml_w, mty.ident); encode_type_param_bounds(ebml_w, ecx, ty_m.tps); @@ -835,7 +833,7 @@ fn encode_info_for_item(ecx: @encode_ctxt, ebml_w: ebml::writer, item: @item, encode_self_type(ebml_w, mty.self_ty); ebml_w.end_tag(); } - provided(m) { + provided(m) => { encode_info_for_method(ecx, ebml_w, path, should_inline(m.attrs), item.id, m, m.tps); @@ -849,7 +847,7 @@ fn encode_info_for_item(ecx: @encode_ctxt, ebml_w: ebml::writer, item: @item, } ebml_w.end_tag(); } - item_mac(*) { fail ~"item macros unimplemented" } + item_mac(*) => fail ~"item macros unimplemented" } } @@ -862,7 +860,7 @@ fn encode_info_for_foreign_item(ecx: @encode_ctxt, ebml_w: ebml::writer, ebml_w.start_tag(tag_items_data_item); alt nitem.node { - foreign_item_fn(fn_decl, tps) { + foreign_item_fn(fn_decl, tps) => { encode_def_id(ebml_w, local_def(nitem.id)); encode_family(ebml_w, purity_fn_family(fn_decl.purity)); encode_type_param_bounds(ebml_w, ecx, tps); @@ -891,11 +889,11 @@ fn encode_info_for_items(ecx: @encode_ctxt, ebml_w: ebml::writer, visit_item: |i, cx, v, copy ebml_w| { visit::visit_item(i, cx, v); alt check ecx.tcx.items.get(i.id) { - ast_map::node_item(_, pt) { + ast_map::node_item(_, pt) => { encode_info_for_item(ecx, ebml_w, i, index, *pt); /* encode ctor, then encode items */ alt i.node { - item_class(tps, _, _, some(ctor), m_dtor) { + item_class(tps, _, _, some(ctor), m_dtor) => { debug!{"encoding info for ctor %s %d", *i.ident, ctor.node.id}; vec::push(*index, { @@ -908,7 +906,7 @@ fn encode_info_for_items(ecx: @encode_ctxt, ebml_w: ebml::writer, local_def(i.id))) } else { none }, tps, ctor.node.dec); } - _ {} + _ => {} } } } @@ -916,7 +914,7 @@ fn encode_info_for_items(ecx: @encode_ctxt, ebml_w: ebml::writer, visit_foreign_item: |ni, cx, v, copy ebml_w| { visit::visit_foreign_item(ni, cx, v); alt check ecx.tcx.items.get(ni.id) { - ast_map::node_foreign_item(_, abi, pt) { + ast_map::node_foreign_item(_, abi, pt) => { encode_info_for_foreign_item(ecx, ebml_w, ni, index, *pt, abi); } @@ -984,16 +982,16 @@ fn write_int(writer: io::writer, &&n: int) { fn encode_meta_item(ebml_w: ebml::writer, mi: meta_item) { alt mi.node { - meta_word(name) { + meta_word(name) => { ebml_w.start_tag(tag_meta_item_word); ebml_w.start_tag(tag_meta_item_name); ebml_w.writer.write(str::bytes(*name)); ebml_w.end_tag(); ebml_w.end_tag(); } - meta_name_value(name, value) { + meta_name_value(name, value) => { alt value.node { - lit_str(value) { + lit_str(value) => { ebml_w.start_tag(tag_meta_item_name_value); ebml_w.start_tag(tag_meta_item_name); ebml_w.writer.write(str::bytes(*name)); @@ -1003,10 +1001,10 @@ fn encode_meta_item(ebml_w: ebml::writer, mi: meta_item) { ebml_w.end_tag(); ebml_w.end_tag(); } - _ {/* FIXME (#623): encode other variants */ } + _ => {/* FIXME (#623): encode other variants */ } } } - meta_list(name, items) { + meta_list(name, items) => { ebml_w.start_tag(tag_meta_item_list); ebml_w.start_tag(tag_meta_item_name); ebml_w.writer.write(str::bytes(*name)); @@ -1067,11 +1065,11 @@ fn synthesize_crate_attrs(ecx: @encode_ctxt, crate: @crate) -> ~[attribute] { attr } else { alt attr.node.value.node { - meta_list(n, l) { + meta_list(n, l) => { found_link_attr = true;; synthesize_link_attr(ecx, l) } - _ { attr } + _ => attr } }); } diff --git a/src/rustc/metadata/filesearch.rs b/src/rustc/metadata/filesearch.rs index 65dd8a5a3e8..656aa4a0ae2 100644 --- a/src/rustc/metadata/filesearch.rs +++ b/src/rustc/metadata/filesearch.rs @@ -44,12 +44,12 @@ fn mk_filesearch(maybe_sysroot: option<path>, vec::push(paths, make_target_lib_path(self.sysroot, self.target_triple)); alt get_cargo_lib_path_nearest() { - result::ok(p) { vec::push(paths, p) } - result::err(p) { } + result::ok(p) => vec::push(paths, p), + result::err(p) => () } alt get_cargo_lib_path() { - result::ok(p) { vec::push(paths, p) } - result::err(p) { } + result::ok(p) => vec::push(paths, p), + result::err(p) => () } paths } @@ -102,17 +102,15 @@ fn make_target_lib_path(sysroot: path, fn get_default_sysroot() -> path { alt os::self_exe_path() { - option::some(p) { path::normalize(path::connect(p, ~"..")) } - option::none { - fail ~"can't determine value for sysroot"; - } + option::some(p) => path::normalize(path::connect(p, ~"..")), + option::none => fail ~"can't determine value for sysroot" } } fn get_sysroot(maybe_sysroot: option<path>) -> path { alt maybe_sysroot { - option::some(sr) { sr } - option::none { get_default_sysroot() } + option::some(sr) => sr, + option::none => get_default_sysroot() } } @@ -123,12 +121,10 @@ fn get_cargo_sysroot() -> result<path, ~str> { fn get_cargo_root() -> result<path, ~str> { alt os::getenv(~"CARGO_ROOT") { - some(_p) { result::ok(_p) } - none { - alt os::homedir() { - some(_q) { result::ok(path::connect(_q, ~".cargo")) } - none { result::err(~"no CARGO_ROOT or home directory") } - } + some(_p) => result::ok(_p), + none => alt os::homedir() { + some(_q) => result::ok(path::connect(_q, ~".cargo")), + none => result::err(~"no CARGO_ROOT or home directory") } } } diff --git a/src/rustc/metadata/loader.rs b/src/rustc/metadata/loader.rs index 125c2ff3aba..e45fdeb06b8 100644 --- a/src/rustc/metadata/loader.rs +++ b/src/rustc/metadata/loader.rs @@ -38,8 +38,8 @@ type ctxt = { fn load_library_crate(cx: ctxt) -> {ident: ~str, data: @~[u8]} { alt find_library_crate(cx) { - some(t) { return t; } - none { + some(t) => return t, + none => { cx.diag.span_fatal( cx.span, fmt!{"can't find crate for `%s`", *cx.ident}); } @@ -54,10 +54,10 @@ fn find_library_crate(cx: ctxt) -> option<{ident: ~str, data: @~[u8]}> { fn libname(cx: ctxt) -> {prefix: ~str, suffix: ~str} { if cx.static { return {prefix: ~"lib", suffix: ~".rlib"}; } alt cx.os { - os_win32 { return {prefix: ~"", suffix: ~".dll"}; } - os_macos { return {prefix: ~"lib", suffix: ~".dylib"}; } - os_linux { return {prefix: ~"lib", suffix: ~".so"}; } - os_freebsd { return {prefix: ~"lib", suffix: ~".so"}; } + os_win32 => return {prefix: ~"", suffix: ~".dll"}, + os_macos => return {prefix: ~"lib", suffix: ~".dylib"}, + os_linux => return {prefix: ~"lib", suffix: ~".so"}, + os_freebsd => return {prefix: ~"lib", suffix: ~".so"} } } @@ -80,7 +80,7 @@ fn find_library_crate_aux(cx: ctxt, } else { debug!{"%s is a candidate", path}; alt get_metadata_section(cx.os, path) { - option::some(cvec) { + option::some(cvec) => { if !crate_matches(cvec, cx.metas, cx.hash) { debug!{"skipping %s, metadata doesn't match", path}; option::none::<()> @@ -90,7 +90,7 @@ fn find_library_crate_aux(cx: ctxt, option::none::<()> } } - _ { + _ => { debug!{"could not load metadata for %s", path}; option::none::<()> } @@ -119,15 +119,15 @@ fn find_library_crate_aux(cx: ctxt, fn crate_name_from_metas(metas: ~[@ast::meta_item]) -> @~str { let name_items = attr::find_meta_items_by_name(metas, ~"name"); alt vec::last_opt(name_items) { - some(i) { + some(i) => { alt attr::get_meta_item_value_str(i) { - some(n) { n } + some(n) => n, // FIXME (#2406): Probably want a warning here since the user // is using the wrong type of meta item. - _ { fail } + _ => fail } } - none { fail ~"expected to find the crate name" } + none => fail ~"expected to find the crate name" } } @@ -176,8 +176,8 @@ fn get_metadata_section(os: os, }); if mb as int == 0 { return option::none::<@~[u8]>; } let of = alt mk_object_file(mb) { - option::some(of) { of } - _ { return option::none::<@~[u8]>; } + option::some(of) => of, + _ => return option::none::<@~[u8]> }; let si = mk_section_iter(of.llof); while llvm::LLVMIsSectionIteratorAtEnd(of.llof, si.llsi) == False { @@ -198,18 +198,18 @@ fn get_metadata_section(os: os, fn meta_section_name(os: os) -> ~str { alt os { - os_macos { ~"__DATA,__note.rustc" } - os_win32 { ~".note.rustc" } - os_linux { ~".note.rustc" } - os_freebsd { ~".note.rustc" } + os_macos => ~"__DATA,__note.rustc", + os_win32 => ~".note.rustc", + os_linux => ~".note.rustc", + os_freebsd => ~".note.rustc" } } // A diagnostic function for dumping crate metadata to an output stream fn list_file_metadata(os: os, path: ~str, out: io::writer) { alt get_metadata_section(os, path) { - option::some(bytes) { decoder::list_crate_metadata(bytes, out); } - option::none { + option::some(bytes) => decoder::list_crate_metadata(bytes, out), + option::none => { out.write_str(~"could not find metadata in " + path + ~".\n"); } } diff --git a/src/rustc/metadata/tydecode.rs b/src/rustc/metadata/tydecode.rs index ad3f09f8086..fee68f5592d 100644 --- a/src/rustc/metadata/tydecode.rs +++ b/src/rustc/metadata/tydecode.rs @@ -58,8 +58,8 @@ fn parse_ty_data(data: @~[u8], crate_num: int, pos: uint, tcx: ty::ctxt, fn parse_ret_ty(st: @pstate, conv: conv_did) -> (ast::ret_style, ty::t) { alt peek(st) { - '!' { next(st); (ast::noreturn, ty::mk_bot(st.tcx)) } - _ { (ast::return_val, parse_ty(st, conv)) } + '!' => { next(st); (ast::noreturn, ty::mk_bot(st.tcx)) } + _ => (ast::return_val, parse_ty(st, conv)) } } @@ -69,8 +69,8 @@ fn parse_path(st: @pstate) -> @ast::path { vec::push(idents, parse_ident_(st, is_last)); loop { alt peek(st) { - ':' { next(st); next(st); } - c { + ':' => { next(st); next(st); } + c => { if c == '(' { return @{span: ast_util::dummy_sp(), global: false, idents: idents, @@ -87,11 +87,11 @@ fn parse_ty_rust_fn(st: @pstate, conv: conv_did) -> ty::t { fn parse_proto(c: char) -> ast::proto { alt c { - '~' { ast::proto_uniq } - '@' { ast::proto_box } - '&' { ast::proto_block } - 'n' { ast::proto_bare } - _ { fail ~"illegal fn type kind " + str::from_char(c); } + '~' => ast::proto_uniq, + '@' => ast::proto_box, + '&' => ast::proto_block, + 'n' => ast::proto_bare, + _ => fail ~"illegal fn type kind " + str::from_char(c) } } @@ -106,9 +106,9 @@ fn parse_vstore(st: @pstate) -> ty::vstore { } alt check next(st) { - '~' { ty::vstore_uniq } - '@' { ty::vstore_box } - '&' { ty::vstore_slice(parse_region(st)) } + '~' => ty::vstore_uniq, + '@' => ty::vstore_box, + '&' => ty::vstore_slice(parse_region(st)) } } @@ -129,10 +129,10 @@ fn parse_substs(st: @pstate, conv: conv_did) -> ty::substs { fn parse_bound_region(st: @pstate) -> ty::bound_region { alt check next(st) { - 's' { ty::br_self } - 'a' { ty::br_anon } - '[' { ty::br_named(@parse_str(st, ']')) } - 'c' { + 's' => ty::br_self, + 'a' => ty::br_anon, + '[' => ty::br_named(@parse_str(st, ']')), + 'c' => { let id = parse_int(st); assert next(st) == '|'; ty::br_cap_avoid(id, @parse_bound_region(st)) @@ -142,10 +142,10 @@ fn parse_bound_region(st: @pstate) -> ty::bound_region { fn parse_region(st: @pstate) -> ty::region { alt check next(st) { - 'b' { + 'b' => { ty::re_bound(parse_bound_region(st)) } - 'f' { + 'f' => { assert next(st) == '['; let id = parse_int(st); assert next(st) == '|'; @@ -153,12 +153,12 @@ fn parse_region(st: @pstate) -> ty::region { assert next(st) == ']'; ty::re_free(id, br) } - 's' { + 's' => { let id = parse_int(st); assert next(st) == '|'; ty::re_scope(id) } - 't' { + 't' => { ty::re_static } } @@ -166,8 +166,8 @@ fn parse_region(st: @pstate) -> ty::region { fn parse_opt<T>(st: @pstate, f: fn() -> T) -> option<T> { alt check next(st) { - 'n' { none } - 's' { some(f()) } + 'n' => none, + 's' => some(f()) } } @@ -182,67 +182,67 @@ fn parse_str(st: @pstate, term: char) -> ~str { fn parse_ty(st: @pstate, conv: conv_did) -> ty::t { alt check next(st) { - 'n' { return ty::mk_nil(st.tcx); } - 'z' { return ty::mk_bot(st.tcx); } - 'b' { return ty::mk_bool(st.tcx); } - 'i' { return ty::mk_int(st.tcx); } - 'u' { return ty::mk_uint(st.tcx); } - 'l' { return ty::mk_float(st.tcx); } - 'M' { + 'n' => return ty::mk_nil(st.tcx), + 'z' => return ty::mk_bot(st.tcx), + 'b' => return ty::mk_bool(st.tcx), + 'i' => return ty::mk_int(st.tcx), + 'u' => return ty::mk_uint(st.tcx), + 'l' => return ty::mk_float(st.tcx), + 'M' => { alt check next(st) { - 'b' { return ty::mk_mach_uint(st.tcx, ast::ty_u8); } - 'w' { return ty::mk_mach_uint(st.tcx, ast::ty_u16); } - 'l' { return ty::mk_mach_uint(st.tcx, ast::ty_u32); } - 'd' { return ty::mk_mach_uint(st.tcx, ast::ty_u64); } - 'B' { return ty::mk_mach_int(st.tcx, ast::ty_i8); } - 'W' { return ty::mk_mach_int(st.tcx, ast::ty_i16); } - 'L' { return ty::mk_mach_int(st.tcx, ast::ty_i32); } - 'D' { return ty::mk_mach_int(st.tcx, ast::ty_i64); } - 'f' { return ty::mk_mach_float(st.tcx, ast::ty_f32); } - 'F' { return ty::mk_mach_float(st.tcx, ast::ty_f64); } + 'b' => return ty::mk_mach_uint(st.tcx, ast::ty_u8), + 'w' => return ty::mk_mach_uint(st.tcx, ast::ty_u16), + 'l' => return ty::mk_mach_uint(st.tcx, ast::ty_u32), + 'd' => return ty::mk_mach_uint(st.tcx, ast::ty_u64), + 'B' => return ty::mk_mach_int(st.tcx, ast::ty_i8), + 'W' => return ty::mk_mach_int(st.tcx, ast::ty_i16), + 'L' => return ty::mk_mach_int(st.tcx, ast::ty_i32), + 'D' => return ty::mk_mach_int(st.tcx, ast::ty_i64), + 'f' => return ty::mk_mach_float(st.tcx, ast::ty_f32), + 'F' => return ty::mk_mach_float(st.tcx, ast::ty_f64) } } - 'c' { return ty::mk_char(st.tcx); } - 't' { + 'c' => return ty::mk_char(st.tcx), + 't' => { assert (next(st) == '['); let def = parse_def(st, conv); let substs = parse_substs(st, conv); assert next(st) == ']'; return ty::mk_enum(st.tcx, def, substs); } - 'x' { + 'x' => { assert next(st) == '['; let def = parse_def(st, conv); let substs = parse_substs(st, conv); assert next(st) == ']'; return ty::mk_trait(st.tcx, def, substs); } - 'p' { + 'p' => { let did = parse_def(st, conv); return ty::mk_param(st.tcx, parse_int(st) as uint, did); } - 's' { + 's' => { return ty::mk_self(st.tcx); } - '@' { return ty::mk_box(st.tcx, parse_mt(st, conv)); } - '~' { return ty::mk_uniq(st.tcx, parse_mt(st, conv)); } - '*' { return ty::mk_ptr(st.tcx, parse_mt(st, conv)); } - '&' { + '@' => return ty::mk_box(st.tcx, parse_mt(st, conv)), + '~' => return ty::mk_uniq(st.tcx, parse_mt(st, conv)), + '*' => return ty::mk_ptr(st.tcx, parse_mt(st, conv)), + '&' => { let r = parse_region(st); let mt = parse_mt(st, conv); return ty::mk_rptr(st.tcx, r, mt); } - 'U' { return ty::mk_unboxed_vec(st.tcx, parse_mt(st, conv)); } - 'V' { + 'U' => return ty::mk_unboxed_vec(st.tcx, parse_mt(st, conv)), + 'V' => { let mt = parse_mt(st, conv); let v = parse_vstore(st); return ty::mk_evec(st.tcx, mt, v); } - 'v' { + 'v' => { let v = parse_vstore(st); return ty::mk_estr(st.tcx, v); } - 'R' { + 'R' => { assert (next(st) == '['); let mut fields: ~[ty::field] = ~[]; while peek(st) != ']' { @@ -252,36 +252,36 @@ fn parse_ty(st: @pstate, conv: conv_did) -> ty::t { st.pos = st.pos + 1u; return ty::mk_rec(st.tcx, fields); } - 'T' { + 'T' => { assert (next(st) == '['); let mut params = ~[]; while peek(st) != ']' { vec::push(params, parse_ty(st, conv)); } st.pos = st.pos + 1u; return ty::mk_tup(st.tcx, params); } - 'f' { + 'f' => { parse_ty_rust_fn(st, conv) } - 'X' { + 'X' => { return ty::mk_var(st.tcx, ty::tv_vid(parse_int(st) as uint)); } - 'Y' { return ty::mk_type(st.tcx); } - 'C' { + 'Y' => return ty::mk_type(st.tcx), + 'C' => { let ck = alt check next(st) { - '&' { ty::ck_block } - '@' { ty::ck_box } - '~' { ty::ck_uniq } + '&' => ty::ck_block, + '@' => ty::ck_box, + '~' => ty::ck_uniq }; return ty::mk_opaque_closure_ptr(st.tcx, ck); } - '#' { + '#' => { let pos = parse_hex(st); assert (next(st) == ':'); let len = parse_hex(st); assert (next(st) == '#'); alt st.tcx.rcache.find({cnum: st.crate, pos: pos, len: len}) { - some(tt) { return tt; } - none { + some(tt) => return tt, + none => { let ps = @{pos: pos with *st}; let tt = parse_ty(ps, conv); st.tcx.rcache.insert({cnum: st.crate, pos: pos, len: len}, tt); @@ -289,13 +289,13 @@ fn parse_ty(st: @pstate, conv: conv_did) -> ty::t { } } } - '"' { + '"' => { let def = parse_def(st, conv); let inner = parse_ty(st, conv); ty::mk_with_id(st.tcx, inner, def) } - 'B' { ty::mk_opaque_box(st.tcx) } - 'a' { + 'B' => ty::mk_opaque_box(st.tcx), + 'a' => { debug!{"saw a class"}; assert (next(st) == '['); debug!{"saw a ["}; @@ -305,16 +305,16 @@ fn parse_ty(st: @pstate, conv: conv_did) -> ty::t { assert (next(st) == ']'); return ty::mk_class(st.tcx, did, substs); } - c { error!{"unexpected char in type string: %c", c}; fail;} + c => { error!{"unexpected char in type string: %c", c}; fail;} } } fn parse_mt(st: @pstate, conv: conv_did) -> ty::mt { let mut m; alt peek(st) { - 'm' { next(st); m = ast::m_mutbl; } - '?' { next(st); m = ast::m_const; } - _ { m = ast::m_imm; } + 'm' => { next(st); m = ast::m_mutbl; } + '?' => { next(st); m = ast::m_const; } + _ => { m = ast::m_imm; } } return {ty: parse_ty(st, conv), mutbl: m}; } @@ -352,10 +352,10 @@ fn parse_hex(st: @pstate) -> uint { fn parse_purity(c: char) -> purity { alt check c { - 'u' {unsafe_fn} - 'p' {pure_fn} - 'i' {impure_fn} - 'c' {extern_fn} + 'u' => unsafe_fn, + 'p' => pure_fn, + 'i' => impure_fn, + 'c' => extern_fn } } @@ -366,11 +366,11 @@ fn parse_ty_fn(st: @pstate, conv: conv_did) -> ty::fn_ty { let mut inputs: ~[ty::arg] = ~[]; while peek(st) != ']' { let mode = alt check peek(st) { - '&' { ast::by_mutbl_ref } - '-' { ast::by_move } - '+' { ast::by_copy } - '=' { ast::by_ref } - '#' { ast::by_val } + '&' => ast::by_mutbl_ref, + '-' => ast::by_move, + '+' => ast::by_copy, + '=' => ast::by_ref, + '#' => ast::by_val }; st.pos += 1u; vec::push(inputs, {mode: ast::expl(mode), ty: parse_ty(st, conv)}); @@ -395,14 +395,14 @@ fn parse_def_id(buf: &[u8]) -> ast::def_id { let def_part = vec::slice(buf, colon_idx + 1u, len); let crate_num = alt uint::parse_buf(crate_part, 10u) { - some(cn) { cn as int } - none { fail (fmt!{"internal error: parse_def_id: crate number \ - expected, but found %?", crate_part}); } + some(cn) => cn as int, + none => fail (fmt!{"internal error: parse_def_id: crate number \ + expected, but found %?", crate_part}) }; let def_num = alt uint::parse_buf(def_part, 10u) { - some(dn) { dn as int } - none { fail (fmt!{"internal error: parse_def_id: id expected, but \ - found %?", def_part}); } + some(dn) => dn as int, + none => fail (fmt!{"internal error: parse_def_id: id expected, but \ + found %?", def_part}) }; return {crate: crate_num, node: def_num}; } @@ -418,12 +418,12 @@ fn parse_bounds(st: @pstate, conv: conv_did) -> @~[ty::param_bound] { let mut bounds = ~[]; loop { vec::push(bounds, alt check next(st) { - 'S' { ty::bound_send } - 'C' { ty::bound_copy } - 'K' { ty::bound_const } - 'O' { ty::bound_owned } - 'I' { ty::bound_trait(parse_ty(st, conv)) } - '.' { break; } + 'S' => ty::bound_send, + 'C' => ty::bound_copy, + 'K' => ty::bound_const, + 'O' => ty::bound_owned, + 'I' => ty::bound_trait(parse_ty(st, conv)), + '.' => break }); } @bounds diff --git a/src/rustc/metadata/tyencode.rs b/src/rustc/metadata/tyencode.rs index 01fc90cc19d..a9685dabba7 100644 --- a/src/rustc/metadata/tyencode.rs +++ b/src/rustc/metadata/tyencode.rs @@ -35,17 +35,17 @@ enum abbrev_ctxt { ac_no_abbrevs, ac_use_abbrevs(hashmap<ty::t, ty_abbrev>), } fn cx_uses_abbrevs(cx: @ctxt) -> bool { alt cx.abbrevs { - ac_no_abbrevs { return false; } - ac_use_abbrevs(_) { return true; } + ac_no_abbrevs => return false, + ac_use_abbrevs(_) => return true } } fn enc_ty(w: io::writer, cx: @ctxt, t: ty::t) { alt cx.abbrevs { - ac_no_abbrevs { + ac_no_abbrevs => { let result_str = alt cx.tcx.short_names_cache.find(t) { - some(s) { *s } - none { + some(s) => *s, + none => { let buf = io::mem_buffer(); enc_sty(io::mem_buffer_writer(buf), cx, ty::get(t).struct); cx.tcx.short_names_cache.insert(t, @io::mem_buffer_str(buf)); @@ -54,13 +54,13 @@ fn enc_ty(w: io::writer, cx: @ctxt, t: ty::t) { }; w.write_str(result_str); } - ac_use_abbrevs(abbrevs) { + ac_use_abbrevs(abbrevs) => { alt abbrevs.find(t) { - some(a) { w.write_str(*a.s); return; } - none { + some(a) => { w.write_str(*a.s); return; } + none => { let pos = w.tell(); alt ty::type_def_id(t) { - some(def_id) { + some(def_id) => { // Do not emit node ids that map to unexported names. Those // are not helpful. if def_id.crate != local_crate || @@ -70,7 +70,7 @@ fn enc_ty(w: io::writer, cx: @ctxt, t: ty::t) { w.write_char('|'); } } - _ {} + _ => {} } enc_sty(w, cx, ty::get(t).struct); let end = w.tell(); @@ -97,17 +97,17 @@ fn enc_ty(w: io::writer, cx: @ctxt, t: ty::t) { } fn enc_mt(w: io::writer, cx: @ctxt, mt: ty::mt) { alt mt.mutbl { - m_imm { } - m_mutbl { w.write_char('m'); } - m_const { w.write_char('?'); } + m_imm => (), + m_mutbl => w.write_char('m'), + m_const => w.write_char('?') } enc_ty(w, cx, mt.ty); } fn enc_opt<T>(w: io::writer, t: option<T>, enc_f: fn(T)) { alt t { - none { w.write_char('n') } - some(v) { + none => w.write_char('n'), + some(v) => { w.write_char('s'); enc_f(v); } @@ -124,11 +124,11 @@ fn enc_substs(w: io::writer, cx: @ctxt, substs: ty::substs) { fn enc_region(w: io::writer, cx: @ctxt, r: ty::region) { alt r { - ty::re_bound(br) { + ty::re_bound(br) => { w.write_char('b'); enc_bound_region(w, br); } - ty::re_free(id, br) { + ty::re_free(id, br) => { w.write_char('f'); w.write_char('['); w.write_int(id); @@ -136,15 +136,15 @@ fn enc_region(w: io::writer, cx: @ctxt, r: ty::region) { enc_bound_region(w, br); w.write_char(']'); } - ty::re_scope(nid) { + ty::re_scope(nid) => { w.write_char('s'); w.write_int(nid); w.write_char('|'); } - ty::re_static { + ty::re_static => { w.write_char('t'); } - ty::re_var(_) { + ty::re_var(_) => { // these should not crop up after typeck cx.diag.handler().bug(~"Cannot encode region variables"); } @@ -153,14 +153,14 @@ fn enc_region(w: io::writer, cx: @ctxt, r: ty::region) { fn enc_bound_region(w: io::writer, br: ty::bound_region) { alt br { - ty::br_self { w.write_char('s') } - ty::br_anon { w.write_char('a') } - ty::br_named(s) { + ty::br_self => w.write_char('s'), + ty::br_anon => w.write_char('a'), + ty::br_named(s) => { w.write_char('['); w.write_str(*s); w.write_char(']') } - ty::br_cap_avoid(id, br) { + ty::br_cap_avoid(id, br) => { w.write_char('c'); w.write_int(id); w.write_char('|'); @@ -172,17 +172,17 @@ fn enc_bound_region(w: io::writer, br: ty::bound_region) { fn enc_vstore(w: io::writer, cx: @ctxt, v: ty::vstore) { w.write_char('/'); alt v { - ty::vstore_fixed(u) { + ty::vstore_fixed(u) => { w.write_uint(u); w.write_char('|'); } - ty::vstore_uniq { + ty::vstore_uniq => { w.write_char('~'); } - ty::vstore_box { + ty::vstore_box => { w.write_char('@'); } - ty::vstore_slice(r) { + ty::vstore_slice(r) => { w.write_char('&'); enc_region(w, cx, r); } @@ -191,73 +191,73 @@ fn enc_vstore(w: io::writer, cx: @ctxt, v: ty::vstore) { fn enc_sty(w: io::writer, cx: @ctxt, st: ty::sty) { alt st { - ty::ty_nil { w.write_char('n'); } - ty::ty_bot { w.write_char('z'); } - ty::ty_bool { w.write_char('b'); } - ty::ty_int(t) { + ty::ty_nil => w.write_char('n'), + ty::ty_bot => w.write_char('z'), + ty::ty_bool => w.write_char('b'), + ty::ty_int(t) => { alt t { - ty_i { w.write_char('i'); } - ty_char { w.write_char('c'); } - ty_i8 { w.write_str(&"MB"); } - ty_i16 { w.write_str(&"MW"); } - ty_i32 { w.write_str(&"ML"); } - ty_i64 { w.write_str(&"MD"); } + ty_i => w.write_char('i'), + ty_char => w.write_char('c'), + ty_i8 => w.write_str(&"MB"), + ty_i16 => w.write_str(&"MW"), + ty_i32 => w.write_str(&"ML"), + ty_i64 => w.write_str(&"MD") } } - ty::ty_uint(t) { + ty::ty_uint(t) => { alt t { - ty_u { w.write_char('u'); } - ty_u8 { w.write_str(&"Mb"); } - ty_u16 { w.write_str(&"Mw"); } - ty_u32 { w.write_str(&"Ml"); } - ty_u64 { w.write_str(&"Md"); } + ty_u => w.write_char('u'), + ty_u8 => w.write_str(&"Mb"), + ty_u16 => w.write_str(&"Mw"), + ty_u32 => w.write_str(&"Ml"), + ty_u64 => w.write_str(&"Md") } } - ty::ty_float(t) { + ty::ty_float(t) => { alt t { - ty_f { w.write_char('l'); } - ty_f32 { w.write_str(&"Mf"); } - ty_f64 { w.write_str(&"MF"); } + ty_f => w.write_char('l'), + ty_f32 => w.write_str(&"Mf"), + ty_f64 => w.write_str(&"MF"), } } - ty::ty_enum(def, substs) { + ty::ty_enum(def, substs) => { w.write_str(&"t["); w.write_str(cx.ds(def)); w.write_char('|'); enc_substs(w, cx, substs); w.write_char(']'); } - ty::ty_trait(def, substs) { + ty::ty_trait(def, substs) => { w.write_str(&"x["); w.write_str(cx.ds(def)); w.write_char('|'); enc_substs(w, cx, substs); w.write_char(']'); } - ty::ty_tup(ts) { + ty::ty_tup(ts) => { w.write_str(&"T["); for ts.each |t| { enc_ty(w, cx, t); } w.write_char(']'); } - ty::ty_box(mt) { w.write_char('@'); enc_mt(w, cx, mt); } - ty::ty_uniq(mt) { w.write_char('~'); enc_mt(w, cx, mt); } - ty::ty_ptr(mt) { w.write_char('*'); enc_mt(w, cx, mt); } - ty::ty_rptr(r, mt) { + ty::ty_box(mt) => { w.write_char('@'); enc_mt(w, cx, mt); } + ty::ty_uniq(mt) => { w.write_char('~'); enc_mt(w, cx, mt); } + ty::ty_ptr(mt) => { w.write_char('*'); enc_mt(w, cx, mt); } + ty::ty_rptr(r, mt) => { w.write_char('&'); enc_region(w, cx, r); enc_mt(w, cx, mt); } - ty::ty_evec(mt, v) { + ty::ty_evec(mt, v) => { w.write_char('V'); enc_mt(w, cx, mt); enc_vstore(w, cx, v); } - ty::ty_estr(v) { + ty::ty_estr(v) => { w.write_char('v'); enc_vstore(w, cx, v); } - ty::ty_unboxed_vec(mt) { w.write_char('U'); enc_mt(w, cx, mt); } - ty::ty_rec(fields) { + ty::ty_unboxed_vec(mt) => { w.write_char('U'); enc_mt(w, cx, mt); } + ty::ty_rec(fields) => { w.write_str(&"R["); for fields.each |field| { w.write_str(*field.ident); @@ -266,33 +266,33 @@ fn enc_sty(w: io::writer, cx: @ctxt, st: ty::sty) { } w.write_char(']'); } - ty::ty_fn(f) { + ty::ty_fn(f) => { enc_ty_fn(w, cx, f); } - ty::ty_var(id) { + ty::ty_var(id) => { w.write_char('X'); w.write_uint(id.to_uint()); } - ty::ty_var_integral(id) { + ty::ty_var_integral(id) => { w.write_char('X'); w.write_char('I'); w.write_uint(id.to_uint()); } - ty::ty_param({idx: id, def_id: did}) { + ty::ty_param({idx: id, def_id: did}) => { w.write_char('p'); w.write_str(cx.ds(did)); w.write_char('|'); w.write_str(uint::str(id)); } - ty::ty_self { + ty::ty_self => { w.write_char('s'); } - ty::ty_type { w.write_char('Y'); } - ty::ty_opaque_closure_ptr(ty::ck_block) { w.write_str(&"C&"); } - ty::ty_opaque_closure_ptr(ty::ck_box) { w.write_str(&"C@"); } - ty::ty_opaque_closure_ptr(ty::ck_uniq) { w.write_str(&"C~"); } - ty::ty_opaque_box { w.write_char('B'); } - ty::ty_class(def, substs) { + ty::ty_type => w.write_char('Y'), + ty::ty_opaque_closure_ptr(ty::ck_block) => w.write_str(&"C&"), + ty::ty_opaque_closure_ptr(ty::ck_box) => w.write_str(&"C@"), + ty::ty_opaque_closure_ptr(ty::ck_uniq) => w.write_str(&"C~"), + ty::ty_opaque_box => w.write_char('B'), + ty::ty_class(def, substs) => { debug!{"~~~~ %s", ~"a["}; w.write_str(&"a["); let s = cx.ds(def); @@ -308,29 +308,29 @@ fn enc_sty(w: io::writer, cx: @ctxt, st: ty::sty) { } fn enc_proto(w: io::writer, proto: proto) { alt proto { - proto_uniq { w.write_str(&"f~"); } - proto_box { w.write_str(&"f@"); } - proto_block { w.write_str(~"f&"); } - proto_bare { w.write_str(&"fn"); } + proto_uniq => w.write_str(&"f~"), + proto_box => w.write_str(&"f@"), + proto_block => w.write_str(~"f&"), + proto_bare => w.write_str(&"fn") } } fn enc_mode(w: io::writer, cx: @ctxt, m: mode) { alt ty::resolved_mode(cx.tcx, m) { - by_mutbl_ref { w.write_char('&'); } - by_move { w.write_char('-'); } - by_copy { w.write_char('+'); } - by_ref { w.write_char('='); } - by_val { w.write_char('#'); } + by_mutbl_ref => w.write_char('&'), + by_move => w.write_char('-'), + by_copy => w.write_char('+'), + by_ref => w.write_char('='), + by_val => w.write_char('#') } } fn enc_purity(w: io::writer, p: purity) { alt p { - pure_fn { w.write_char('p'); } - impure_fn { w.write_char('i'); } - unsafe_fn { w.write_char('u'); } - extern_fn { w.write_char('c'); } + pure_fn => w.write_char('p'), + impure_fn => w.write_char('i'), + unsafe_fn => w.write_char('u'), + extern_fn => w.write_char('c') } } @@ -344,19 +344,19 @@ fn enc_ty_fn(w: io::writer, cx: @ctxt, ft: ty::fn_ty) { } w.write_char(']'); alt ft.ret_style { - noreturn { w.write_char('!'); } - _ { enc_ty(w, cx, ft.output); } + noreturn => w.write_char('!'), + _ => enc_ty(w, cx, ft.output) } } fn enc_bounds(w: io::writer, cx: @ctxt, bs: @~[ty::param_bound]) { for vec::each(*bs) |bound| { alt bound { - ty::bound_send { w.write_char('S'); } - ty::bound_copy { w.write_char('C'); } - ty::bound_const { w.write_char('K'); } - ty::bound_owned { w.write_char('O'); } - ty::bound_trait(tp) { + ty::bound_send => w.write_char('S'), + ty::bound_copy => w.write_char('C'), + ty::bound_const => w.write_char('K'), + ty::bound_owned => w.write_char('O'), + ty::bound_trait(tp) => { w.write_char('I'); enc_ty(w, cx, tp); } diff --git a/src/rustc/middle/astencode.rs b/src/rustc/middle/astencode.rs index 5478f8fb423..054c51bfe36 100644 --- a/src/rustc/middle/astencode.rs +++ b/src/rustc/middle/astencode.rs @@ -112,8 +112,8 @@ fn decode_inlined_item(cdata: cstore::crate_metadata, par_doc: ebml::doc) -> option<ast::inlined_item> { let dcx = @{cdata: cdata, tcx: tcx, maps: maps}; alt par_doc.opt_child(c::tag_ast) { - none { none } - some(ast_doc) { + none => none, + some(ast_doc) => { debug!{"> Decoding inlined fn: %s::?", ast_map::path_to_str(path)}; let ast_dsr = ebml::ebml_deserializer(ast_doc); let from_id_range = ast_util::deserialize_id_range(ast_dsr); @@ -130,11 +130,11 @@ fn decode_inlined_item(cdata: cstore::crate_metadata, debug!{"< Decoded inlined fn: %s::%s", ast_map::path_to_str(path), *ii.ident()}; alt ii { - ast::ii_item(i) { + ast::ii_item(i) => { debug!{">>> DECODED ITEM >>>\n%s\n<<< DECODED ITEM <<<", syntax::print::pprust::item_to_str(i)}; } - _ { } + _ => { } } some(ii) } @@ -247,8 +247,8 @@ fn simplify_ast(ii: ast::inlined_item) -> ast::inlined_item { let stmts_sans_items = do vec::filter(blk.stmts) |stmt| { alt stmt.node { ast::stmt_expr(_, _) | ast::stmt_semi(_, _) | - ast::stmt_decl(@{node: ast::decl_local(_), span: _}, _) { true } - ast::stmt_decl(@{node: ast::decl_item(_), span: _}, _) { false } + ast::stmt_decl(@{node: ast::decl_local(_), span: _}, _) => true, + ast::stmt_decl(@{node: ast::decl_item(_), span: _}, _) => false } }; let blk_sans_items = { stmts: stmts_sans_items with blk }; @@ -261,23 +261,23 @@ fn simplify_ast(ii: ast::inlined_item) -> ast::inlined_item { }); alt ii { - ast::ii_item(i) { + ast::ii_item(i) => { ast::ii_item(fld.fold_item(i).get()) //hack: we're not dropping items } - ast::ii_method(d, m) { + ast::ii_method(d, m) => { ast::ii_method(d, fld.fold_method(m)) } - ast::ii_foreign(i) { + ast::ii_foreign(i) => { ast::ii_foreign(fld.fold_foreign_item(i)) } - ast::ii_ctor(ctor, nm, tps, parent_id) { + ast::ii_ctor(ctor, nm, tps, parent_id) => { let ctor_body = fld.fold_block(ctor.node.body); let ctor_decl = fold::fold_fn_decl(ctor.node.dec, fld); ast::ii_ctor({node: {body: ctor_body, dec: ctor_decl with ctor.node} with ctor}, nm, tps, parent_id) } - ast::ii_dtor(dtor, nm, tps, parent_id) { + ast::ii_dtor(dtor, nm, tps, parent_id) => { let dtor_body = fld.fold_block(dtor.node.body); ast::ii_dtor({node: {body: dtor_body with dtor.node} @@ -301,16 +301,16 @@ fn renumber_ast(xcx: extended_decode_ctxt, ii: ast::inlined_item) }); alt ii { - ast::ii_item(i) { + ast::ii_item(i) => { ast::ii_item(fld.fold_item(i).get()) } - ast::ii_method(d, m) { + ast::ii_method(d, m) => { ast::ii_method(xcx.tr_def_id(d), fld.fold_method(m)) } - ast::ii_foreign(i) { + ast::ii_foreign(i) => { ast::ii_foreign(fld.fold_foreign_item(i)) } - ast::ii_ctor(ctor, nm, tps, parent_id) { + ast::ii_ctor(ctor, nm, tps, parent_id) => { let ctor_body = fld.fold_block(ctor.node.body); let ctor_attrs = fld.fold_attributes(ctor.node.attrs); let ctor_decl = fold::fold_fn_decl(ctor.node.dec, fld); @@ -322,7 +322,7 @@ fn renumber_ast(xcx: extended_decode_ctxt, ii: ast::inlined_item) with ctor.node} with ctor}, nm, new_params, new_parent) } - ast::ii_dtor(dtor, nm, tps, parent_id) { + ast::ii_dtor(dtor, nm, tps, parent_id) => { let dtor_body = fld.fold_block(dtor.node.body); let dtor_attrs = fld.fold_attributes(dtor.node.attrs); let new_params = fold::fold_ty_params(tps, fld); @@ -353,29 +353,29 @@ fn decode_def(xcx: extended_decode_ctxt, doc: ebml::doc) -> ast::def { impl of tr for ast::def { fn tr(xcx: extended_decode_ctxt) -> ast::def { alt self { - ast::def_fn(did, p) { ast::def_fn(did.tr(xcx), p) } - ast::def_self(nid) { ast::def_self(xcx.tr_id(nid)) } - ast::def_mod(did) { ast::def_mod(did.tr(xcx)) } - ast::def_foreign_mod(did) { ast::def_foreign_mod(did.tr(xcx)) } - ast::def_const(did) { ast::def_const(did.tr(xcx)) } - ast::def_arg(nid, m) { ast::def_arg(xcx.tr_id(nid), m) } - ast::def_local(nid, b) { ast::def_local(xcx.tr_id(nid), b) } - ast::def_variant(e_did, v_did) { + ast::def_fn(did, p) => ast::def_fn(did.tr(xcx), p), + ast::def_self(nid) => ast::def_self(xcx.tr_id(nid)), + ast::def_mod(did) => ast::def_mod(did.tr(xcx)), + ast::def_foreign_mod(did) => ast::def_foreign_mod(did.tr(xcx)), + ast::def_const(did) => ast::def_const(did.tr(xcx)), + ast::def_arg(nid, m) => ast::def_arg(xcx.tr_id(nid), m), + ast::def_local(nid, b) => ast::def_local(xcx.tr_id(nid), b), + ast::def_variant(e_did, v_did) => { ast::def_variant(e_did.tr(xcx), v_did.tr(xcx)) } - ast::def_ty(did) { ast::def_ty(did.tr(xcx)) } - ast::def_prim_ty(p) { ast::def_prim_ty(p) } - ast::def_ty_param(did, v) { ast::def_ty_param(did.tr(xcx), v) } - ast::def_binding(nid, bm) { ast::def_binding(xcx.tr_id(nid), bm) } - ast::def_use(did) { ast::def_use(did.tr(xcx)) } - ast::def_upvar(nid1, def, nid2) { + ast::def_ty(did) => ast::def_ty(did.tr(xcx)), + ast::def_prim_ty(p) => ast::def_prim_ty(p), + ast::def_ty_param(did, v) => ast::def_ty_param(did.tr(xcx), v), + ast::def_binding(nid, bm) => ast::def_binding(xcx.tr_id(nid), bm), + ast::def_use(did) => ast::def_use(did.tr(xcx)), + ast::def_upvar(nid1, def, nid2) => { ast::def_upvar(xcx.tr_id(nid1), @(*def).tr(xcx), xcx.tr_id(nid2)) } - ast::def_class(did, has_constructor) { + ast::def_class(did, has_constructor) => { ast::def_class(did.tr(xcx), has_constructor) } - ast::def_region(nid) { ast::def_region(xcx.tr_id(nid)) } - ast::def_typaram_binder(nid) { + ast::def_region(nid) => ast::def_region(xcx.tr_id(nid)), + ast::def_typaram_binder(nid) => { ast::def_typaram_binder(xcx.tr_id(nid)) } } @@ -423,13 +423,13 @@ impl helper of read_method_map_entry_helper for ebml::ebml_deserializer { impl of tr for method_origin { fn tr(xcx: extended_decode_ctxt) -> method_origin { alt self { - typeck::method_static(did) { + typeck::method_static(did) => { typeck::method_static(did.tr(xcx)) } - typeck::method_param(mp) { + typeck::method_param(mp) => { typeck::method_param({trait_id:mp.trait_id.tr(xcx) with mp}) } - typeck::method_trait(did, m) { + typeck::method_trait(did, m) => { typeck::method_trait(did.tr(xcx), m) } } @@ -456,7 +456,7 @@ fn encode_vtable_origin(ecx: @e::encode_ctxt, vtable_origin: typeck::vtable_origin) { do ebml_w.emit_enum(~"vtable_origin") { alt vtable_origin { - typeck::vtable_static(def_id, tys, vtable_res) { + typeck::vtable_static(def_id, tys, vtable_res) => { do ebml_w.emit_enum_variant(~"vtable_static", 0u, 3u) { do ebml_w.emit_enum_variant_arg(0u) { ebml_w.emit_def_id(def_id) @@ -469,7 +469,7 @@ fn encode_vtable_origin(ecx: @e::encode_ctxt, } } } - typeck::vtable_param(pn, bn) { + typeck::vtable_param(pn, bn) => { do ebml_w.emit_enum_variant(~"vtable_param", 1u, 2u) { do ebml_w.emit_enum_variant_arg(0u) { ebml_w.emit_uint(pn); @@ -479,7 +479,7 @@ fn encode_vtable_origin(ecx: @e::encode_ctxt, } } } - typeck::vtable_trait(def_id, tys) { + typeck::vtable_trait(def_id, tys) => { do ebml_w.emit_enum_variant(~"vtable_trait", 1u, 3u) { do ebml_w.emit_enum_variant_arg(0u) { ebml_w.emit_def_id(def_id) @@ -509,7 +509,7 @@ impl helpers of vtable_deserialization_helpers for ebml::ebml_deserializer { do self.read_enum(~"vtable_origin") { do self.read_enum_variant |i| { alt check i { - 0u { + 0u => { typeck::vtable_static( do self.read_enum_variant_arg(0u) { self.read_def_id(xcx) @@ -522,7 +522,7 @@ impl helpers of vtable_deserialization_helpers for ebml::ebml_deserializer { } ) } - 1u { + 1u => { typeck::vtable_param( do self.read_enum_variant_arg(0u) { self.read_uint() @@ -532,7 +532,7 @@ impl helpers of vtable_deserialization_helpers for ebml::ebml_deserializer { } ) } - 2u { + 2u => { typeck::vtable_trait( do self.read_enum_variant_arg(0u) { self.read_def_id(xcx) @@ -993,9 +993,9 @@ fn test_simplification() { } }); alt (item_out, item_exp) { - (ast::ii_item(item_out), ast::ii_item(item_exp)) { + (ast::ii_item(item_out), ast::ii_item(item_exp)) => { assert pprust::item_to_str(item_out) == pprust::item_to_str(item_exp); } - _ { fail; } + _ => fail } } diff --git a/src/rustc/middle/block_use.rs b/src/rustc/middle/block_use.rs index 6c103915aaf..3f7ddd94eed 100644 --- a/src/rustc/middle/block_use.rs +++ b/src/rustc/middle/block_use.rs @@ -14,17 +14,17 @@ fn check_crate(tcx: ty::ctxt, crate: @crate) { fn visit_expr(ex: @expr, cx: ctx, v: visit::vt<ctx>) { if !cx.allow_block { alt ty::get(ty::expr_ty(cx.tcx, ex)).struct { - ty::ty_fn({proto: p, _}) if is_blockish(p) { + ty::ty_fn({proto: p, _}) if is_blockish(p) => { cx.tcx.sess.span_err(ex.span, ~"expressions with stack closure type \ can only appear in callee or (by-ref) argument position"); } - _ {} + _ => {} } } let outer = cx.allow_block; alt ex.node { - expr_call(f, args, _) { + expr_call(f, args, _) => { cx.allow_block = true; v.visit_expr(f, cx, v); let mut i = 0u; @@ -34,11 +34,11 @@ fn visit_expr(ex: @expr, cx: ctx, v: visit::vt<ctx>) { i += 1u; } } - expr_loop_body(body) | expr_do_body(body) { + expr_loop_body(body) | expr_do_body(body) => { cx.allow_block = true; v.visit_expr(body, cx, v); } - _ { + _ => { cx.allow_block = false; visit::visit_expr(ex, cx, v); } diff --git a/src/rustc/middle/borrowck.rs b/src/rustc/middle/borrowck.rs index d1f38ca17e9..4e9f770232f 100644 --- a/src/rustc/middle/borrowck.rs +++ b/src/rustc/middle/borrowck.rs @@ -457,8 +457,8 @@ impl methods of get_type_for_node for ty::ctxt { impl error_methods for borrowck_ctxt { fn report_if_err(bres: bckres<()>) { alt bres { - ok(()) { } - err(e) { self.report(e); } + ok(()) => (), + err(e) => self.report(e) } } @@ -479,13 +479,13 @@ impl error_methods for borrowck_ctxt { fn add_to_mutbl_map(cmt: cmt) { alt cmt.cat { - cat_local(id) | cat_arg(id) { + cat_local(id) | cat_arg(id) => { self.mutbl_map.insert(id, ()); } - cat_stack_upvar(cmt) { + cat_stack_upvar(cmt) => { self.add_to_mutbl_map(cmt); } - _ {} + _ => () } } } @@ -493,65 +493,65 @@ impl error_methods for borrowck_ctxt { impl to_str_methods for borrowck_ctxt { fn cat_to_repr(cat: categorization) -> ~str { alt cat { - cat_special(sk_method) { ~"method" } - cat_special(sk_static_item) { ~"static_item" } - cat_special(sk_self) { ~"self" } - cat_special(sk_heap_upvar) { ~"heap-upvar" } - cat_stack_upvar(_) { ~"stack-upvar" } - cat_rvalue { ~"rvalue" } - cat_local(node_id) { fmt!{"local(%d)", node_id} } - cat_binding(node_id) { fmt!{"binding(%d)", node_id} } - cat_arg(node_id) { fmt!{"arg(%d)", node_id} } - cat_deref(cmt, derefs, ptr) { + cat_special(sk_method) => ~"method", + cat_special(sk_static_item) => ~"static_item", + cat_special(sk_self) => ~"self", + cat_special(sk_heap_upvar) => ~"heap-upvar", + cat_stack_upvar(_) => ~"stack-upvar", + cat_rvalue => ~"rvalue", + cat_local(node_id) => fmt!{"local(%d)", node_id}, + cat_binding(node_id) => fmt!{"binding(%d)", node_id}, + cat_arg(node_id) => fmt!{"arg(%d)", node_id}, + cat_deref(cmt, derefs, ptr) => { fmt!{"%s->(%s, %u)", self.cat_to_repr(cmt.cat), self.ptr_sigil(ptr), derefs} } - cat_comp(cmt, comp) { + cat_comp(cmt, comp) => { fmt!{"%s.%s", self.cat_to_repr(cmt.cat), self.comp_to_repr(comp)} } - cat_discr(cmt, _) { self.cat_to_repr(cmt.cat) } + cat_discr(cmt, _) => self.cat_to_repr(cmt.cat) } } fn mut_to_str(mutbl: ast::mutability) -> ~str { alt mutbl { - m_mutbl { ~"mutable" } - m_const { ~"const" } - m_imm { ~"immutable" } + m_mutbl => ~"mutable", + m_const => ~"const", + m_imm => ~"immutable" } } fn ptr_sigil(ptr: ptr_kind) -> ~str { alt ptr { - uniq_ptr { ~"~" } - gc_ptr { ~"@" } - region_ptr(_) { ~"&" } - unsafe_ptr { ~"*" } + uniq_ptr => ~"~", + gc_ptr => ~"@", + region_ptr(_) => ~"&", + unsafe_ptr => ~"*" } } fn comp_to_repr(comp: comp_kind) -> ~str { alt comp { - comp_field(fld, _) { *fld } - comp_index(*) { ~"[]" } - comp_tuple { ~"()" } - comp_variant(_) { ~"<enum>" } + comp_field(fld, _) => *fld, + comp_index(*) => ~"[]", + comp_tuple => ~"()", + comp_variant(_) => ~"<enum>" } } fn lp_to_str(lp: @loan_path) -> ~str { alt *lp { - lp_local(node_id) { + lp_local(node_id) => { fmt!{"local(%d)", node_id} } - lp_arg(node_id) { + lp_arg(node_id) => { fmt!{"arg(%d)", node_id} } - lp_deref(lp, ptr) { + lp_deref(lp, ptr) => { fmt!{"%s->(%s)", self.lp_to_str(lp), self.ptr_sigil(ptr)} } - lp_comp(lp, comp) { + lp_comp(lp, comp) => { fmt!{"%s.%s", self.lp_to_str(lp), self.comp_to_repr(comp)} } @@ -570,38 +570,32 @@ impl to_str_methods for borrowck_ctxt { fn cmt_to_str(cmt: cmt) -> ~str { let mut_str = self.mut_to_str(cmt.mutbl); alt cmt.cat { - cat_special(sk_method) { ~"method" } - cat_special(sk_static_item) { ~"static item" } - cat_special(sk_self) { ~"self reference" } - cat_special(sk_heap_upvar) { + cat_special(sk_method) => ~"method", + cat_special(sk_static_item) => ~"static item", + cat_special(sk_self) => ~"self reference", + cat_special(sk_heap_upvar) => { ~"captured outer variable in a heap closure" } - cat_rvalue { ~"non-lvalue" } - cat_local(_) { mut_str + ~" local variable" } - cat_binding(_) { ~"pattern binding" } - cat_arg(_) { ~"argument" } - cat_deref(_, _, pk) { fmt!{"dereference of %s %s pointer", - mut_str, self.ptr_sigil(pk)} } - cat_stack_upvar(_) { + cat_rvalue => ~"non-lvalue", + cat_local(_) => mut_str + ~" local variable", + cat_binding(_) => ~"pattern binding", + cat_arg(_) => ~"argument", + cat_deref(_, _, pk) => fmt!{"dereference of %s %s pointer", + mut_str, self.ptr_sigil(pk)}, + cat_stack_upvar(_) => { ~"captured outer " + mut_str + ~" variable in a stack closure" } - cat_comp(_, comp_field(*)) { mut_str + ~" field" } - cat_comp(_, comp_tuple) { ~"tuple content" } - cat_comp(_, comp_variant(_)) { ~"enum content" } - cat_comp(_, comp_index(t, _)) { + cat_comp(_, comp_field(*)) => mut_str + ~" field", + cat_comp(_, comp_tuple) => ~"tuple content", + cat_comp(_, comp_variant(_)) => ~"enum content", + cat_comp(_, comp_index(t, _)) => { alt ty::get(t).struct { - ty::ty_evec(*) { - mut_str + ~" vec content" - } - - ty::ty_estr(*) { - mut_str + ~" str content" - } - - _ { mut_str + ~" indexed content" } + ty::ty_evec(*) => mut_str + ~" vec content", + ty::ty_estr(*) => mut_str + ~" str content", + _ => mut_str + ~" indexed content" } } - cat_discr(cmt, _) { + cat_discr(cmt, _) => { self.cmt_to_str(cmt) } } @@ -609,29 +603,29 @@ impl to_str_methods for borrowck_ctxt { fn bckerr_code_to_str(code: bckerr_code) -> ~str { alt code { - err_mutbl(req, act) { + err_mutbl(req, act) => { fmt!{"creating %s alias to aliasable, %s memory", self.mut_to_str(req), self.mut_to_str(act)} } - err_mut_uniq { + err_mut_uniq => { ~"unique value in aliasable, mutable location" } - err_mut_variant { + err_mut_variant => { ~"enum variant in aliasable, mutable location" } - err_root_not_permitted { + err_root_not_permitted => { // note: I don't expect users to ever see this error // message, reasons are discussed in attempt_root() in // preserve.rs. ~"rooting is not permitted" } - err_out_of_root_scope(super_scope, sub_scope) { + err_out_of_root_scope(super_scope, sub_scope) => { fmt!{"managed value would have to be rooted for lifetime %s, \ but can only be rooted for lifetime %s", self.region_to_str(sub_scope), self.region_to_str(super_scope)} } - err_out_of_scope(super_scope, sub_scope) { + err_out_of_scope(super_scope, sub_scope) => { fmt!{"borrowed pointer has lifetime %s, \ but the borrowed value only has lifetime %s", self.region_to_str(sub_scope), @@ -651,7 +645,7 @@ impl to_str_methods for borrowck_ctxt { // mutable structure. fn inherent_mutability(ck: comp_kind) -> mutability { alt ck { - comp_tuple | comp_variant(_) {m_imm} - comp_field(_, m) | comp_index(_, m) {m} + comp_tuple | comp_variant(_) => m_imm, + comp_field(_, m) | comp_index(_, m) => m } } diff --git a/src/rustc/middle/borrowck/categorization.rs b/src/rustc/middle/borrowck/categorization.rs index f2516a30bca..f3d39aa91ef 100644 --- a/src/rustc/middle/borrowck/categorization.rs +++ b/src/rustc/middle/borrowck/categorization.rs @@ -46,48 +46,46 @@ fn opt_deref_kind(t: ty::t) -> option<deref_kind> { alt ty::get(t).struct { ty::ty_uniq(*) | ty::ty_evec(_, ty::vstore_uniq) | - ty::ty_estr(ty::vstore_uniq) { + ty::ty_estr(ty::vstore_uniq) => { some(deref_ptr(uniq_ptr)) } ty::ty_rptr(r, _) | ty::ty_evec(_, ty::vstore_slice(r)) | - ty::ty_estr(ty::vstore_slice(r)) { + ty::ty_estr(ty::vstore_slice(r)) => { some(deref_ptr(region_ptr(r))) } ty::ty_box(*) | ty::ty_evec(_, ty::vstore_box) | - ty::ty_estr(ty::vstore_box) { + ty::ty_estr(ty::vstore_box) => { some(deref_ptr(gc_ptr)) } - ty::ty_ptr(*) { + ty::ty_ptr(*) => { some(deref_ptr(unsafe_ptr)) } - ty::ty_enum(did, _) { + ty::ty_enum(did, _) => { some(deref_comp(comp_variant(did))) } - ty::ty_evec(mt, ty::vstore_fixed(_)) { + ty::ty_evec(mt, ty::vstore_fixed(_)) => { some(deref_comp(comp_index(t, mt.mutbl))) } - ty::ty_estr(ty::vstore_fixed(_)) { + ty::ty_estr(ty::vstore_fixed(_)) => { some(deref_comp(comp_index(t, m_imm))) } - _ { - none - } + _ => none } } fn deref_kind(tcx: ty::ctxt, t: ty::t) -> deref_kind { alt opt_deref_kind(t) { - some(k) {k} - none { + some(k) => k, + none => { tcx.sess.bug( fmt!{"deref_cat() invoked on non-derefable type %s", ty_to_str(tcx, t)}); @@ -100,11 +98,11 @@ impl public_methods for borrowck_ctxt { // a borrowed expression must be either an @, ~, or a @vec, ~vec let expr_ty = ty::expr_ty(self.tcx, expr); alt ty::get(expr_ty).struct { - ty::ty_evec(*) | ty::ty_estr(*) { + ty::ty_evec(*) | ty::ty_estr(*) => { self.cat_index(expr, expr) } - ty::ty_uniq(*) | ty::ty_box(*) | ty::ty_rptr(*) { + ty::ty_uniq(*) | ty::ty_box(*) | ty::ty_rptr(*) => { let cmt = self.cat_expr(expr); self.cat_deref(expr, cmt, 0u, true).get() } @@ -115,7 +113,7 @@ impl public_methods for borrowck_ctxt { } */ - _ { + _ => { self.tcx.sess.span_bug( expr.span, fmt!{"Borrowing of non-derefable type `%s`", @@ -131,15 +129,15 @@ impl public_methods for borrowck_ctxt { let tcx = self.tcx; let expr_ty = tcx.ty(expr); alt expr.node { - ast::expr_unary(ast::deref, e_base) { + ast::expr_unary(ast::deref, e_base) => { if self.method_map.contains_key(expr.id) { return self.cat_rvalue(expr, expr_ty); } let base_cmt = self.cat_expr(e_base); alt self.cat_deref(expr, base_cmt, 0u, true) { - some(cmt) { return cmt; } - none { + some(cmt) => return cmt, + none => { tcx.sess.span_bug( e_base.span, fmt!{"Explicit deref of non-derefable type `%s`", @@ -148,7 +146,7 @@ impl public_methods for borrowck_ctxt { } } - ast::expr_field(base, f_name, _) { + ast::expr_field(base, f_name, _) => { if self.method_map.contains_key(expr.id) { return self.cat_method_ref(expr, expr_ty); } @@ -157,7 +155,7 @@ impl public_methods for borrowck_ctxt { self.cat_field(expr, base_cmt, f_name) } - ast::expr_index(base, _) { + ast::expr_index(base, _) => { if self.method_map.contains_key(expr.id) { return self.cat_rvalue(expr, expr_ty); } @@ -165,7 +163,7 @@ impl public_methods for borrowck_ctxt { self.cat_index(expr, base) } - ast::expr_path(_) { + ast::expr_path(_) => { let def = self.tcx.def_map.get(expr.id); self.cat_def(expr.id, expr.span, expr_ty, def) } @@ -182,7 +180,7 @@ impl public_methods for borrowck_ctxt { ast::expr_block(*) | ast::expr_loop(*) | ast::expr_alt(*) | ast::expr_lit(*) | ast::expr_break | ast::expr_mac(*) | ast::expr_again | ast::expr_rec(*) | ast::expr_struct(*) | - ast::expr_unary_move(*) | ast::expr_repeat(*) { + ast::expr_unary_move(*) | ast::expr_repeat(*) => { return self.cat_rvalue(expr, expr_ty); } } @@ -198,29 +196,29 @@ impl public_methods for borrowck_ctxt { ast::def_use(_) | ast::def_variant(*) | ast::def_ty(_) | ast::def_prim_ty(_) | ast::def_ty_param(*) | ast::def_class(*) | - ast::def_typaram_binder(*) | ast::def_region(_) { + ast::def_typaram_binder(*) | ast::def_region(_) => { @{id:id, span:span, cat:cat_special(sk_static_item), lp:none, mutbl:m_imm, ty:expr_ty} } - ast::def_arg(vid, mode) { + ast::def_arg(vid, mode) => { // Idea: make this could be rewritten to model by-ref // stuff as `&const` and `&mut`? // m: mutability of the argument // lp: loan path, must be none for aliasable things let {m,lp} = alt ty::resolved_mode(self.tcx, mode) { - ast::by_mutbl_ref { + ast::by_mutbl_ref => { {m: m_mutbl, lp: none} } - ast::by_move | ast::by_copy { + ast::by_move | ast::by_copy => { {m: m_imm, lp: some(@lp_arg(vid))} } - ast::by_ref { + ast::by_ref => { {m: m_imm, lp: none} } - ast::by_val { + ast::by_val => { // by-value is this hybrid mode where we have a // pointer but we do not own it. This is not // considered loanable because, for example, a by-ref @@ -234,23 +232,23 @@ impl public_methods for borrowck_ctxt { mutbl:m, ty:expr_ty} } - ast::def_self(_) { + ast::def_self(_) => { @{id:id, span:span, cat:cat_special(sk_self), lp:none, mutbl:m_imm, ty:expr_ty} } - ast::def_upvar(upvid, inner, fn_node_id) { + ast::def_upvar(upvid, inner, fn_node_id) => { let ty = ty::node_id_to_type(self.tcx, fn_node_id); let proto = ty::ty_fn_proto(ty); alt proto { - ast::proto_block { + ast::proto_block => { let upcmt = self.cat_def(id, span, expr_ty, *inner); @{id:id, span:span, cat:cat_stack_upvar(upcmt), lp:upcmt.lp, mutbl:upcmt.mutbl, ty:upcmt.ty} } - ast::proto_bare | ast::proto_uniq | ast::proto_box { + ast::proto_bare | ast::proto_uniq | ast::proto_box => { // FIXME #2152 allow mutation of moved upvars @{id:id, span:span, cat:cat_special(sk_heap_upvar), lp:none, @@ -259,21 +257,21 @@ impl public_methods for borrowck_ctxt { } } - ast::def_local(vid, mutbl) { + ast::def_local(vid, mutbl) => { let m = if mutbl {m_mutbl} else {m_imm}; @{id:id, span:span, cat:cat_local(vid), lp:some(@lp_local(vid)), mutbl:m, ty:expr_ty} } - ast::def_binding(vid, ast::bind_by_value) { + ast::def_binding(vid, ast::bind_by_value) => { // by-value bindings are basically local variables @{id:id, span:span, cat:cat_local(vid), lp:some(@lp_local(vid)), mutbl:m_imm, ty:expr_ty} } - ast::def_binding(pid, ast::bind_by_ref) { + ast::def_binding(pid, ast::bind_by_ref) => { // bindings are "special" since they are implicit pointers. // lookup the mutability for this binding that we found in @@ -322,8 +320,8 @@ impl public_methods for borrowck_ctxt { fn cat_field<N:ast_node>(node: N, base_cmt: cmt, f_name: ast::ident) -> cmt { let f_mutbl = alt field_mutbl(self.tcx, base_cmt.ty, f_name) { - some(f_mutbl) { f_mutbl } - none { + some(f_mutbl) => f_mutbl, + none => { self.tcx.sess.span_bug( node.span(), fmt!{"Cannot find field `%s` in type `%s`", @@ -342,7 +340,7 @@ impl public_methods for borrowck_ctxt { expl: bool) -> option<cmt> { do ty::deref(self.tcx, base_cmt.ty, expl).map |mt| { alt deref_kind(self.tcx, base_cmt.ty) { - deref_ptr(ptr) { + deref_ptr(ptr) => { let lp = do base_cmt.lp.chain |l| { // Given that the ptr itself is loanable, we can // loan out deref'd uniq ptrs as the data they are @@ -371,7 +369,7 @@ impl public_methods for borrowck_ctxt { mutbl:m, ty:mt.ty} } - deref_comp(comp) { + deref_comp(comp) => { let lp = base_cmt.lp.map(|l| @lp_comp(l, comp) ); let m = self.inherited_mutability(base_cmt.mutbl, mt.mutbl); @{id:node.id(), span:node.span(), @@ -386,8 +384,8 @@ impl public_methods for borrowck_ctxt { let base_cmt = self.cat_autoderef(base); let mt = alt ty::index(self.tcx, base_cmt.ty) { - some(mt) { mt } - none { + some(mt) => mt, + none => { self.tcx.sess.span_bug( expr.span, fmt!{"Explicit index of non-index type `%s`", @@ -396,7 +394,7 @@ impl public_methods for borrowck_ctxt { }; return alt deref_kind(self.tcx, base_cmt.ty) { - deref_ptr(ptr) { + deref_ptr(ptr) => { // (a) the contents are loanable if the base is loanable // and this is a *unique* vector let deref_lp = alt ptr { @@ -423,7 +421,7 @@ impl public_methods for borrowck_ctxt { comp(expr, deref_cmt, base_cmt.ty, m, mt.ty) } - deref_comp(_) { + deref_comp(_) => { // fixed-length vectors have no deref comp(expr, base_cmt, base_cmt.ty, mt.mutbl, mt.ty) } @@ -468,8 +466,8 @@ impl private_methods for borrowck_ctxt { loop { ctr += 1u; alt self.cat_deref(base, cmt, ctr, false) { - none { return cmt; } - some(cmt1) { cmt = cmt1; } + none => return cmt, + some(cmt1) => cmt = cmt1 } } } @@ -480,25 +478,25 @@ fn field_mutbl(tcx: ty::ctxt, f_name: ast::ident) -> option<ast::mutability> { // Need to refactor so that records/class fields can be treated uniformly. alt ty::get(base_ty).struct { - ty::ty_rec(fields) { + ty::ty_rec(fields) => { for fields.each |f| { if f.ident == f_name { return some(f.mt.mutbl); } } } - ty::ty_class(did, substs) { + ty::ty_class(did, substs) => { for ty::lookup_class_fields(tcx, did).each |fld| { if fld.ident == f_name { let m = alt fld.mutability { - ast::class_mutable { ast::m_mutbl } - ast::class_immutable { ast::m_imm } + ast::class_mutable => ast::m_mutbl, + ast::class_immutable => ast::m_imm }; return some(m); } } } - _ { } + _ => { } } return none; diff --git a/src/rustc/middle/borrowck/check_loans.rs b/src/rustc/middle/borrowck/check_loans.rs index 022bdcebfb1..f84fca5c197 100644 --- a/src/rustc/middle/borrowck/check_loans.rs +++ b/src/rustc/middle/borrowck/check_loans.rs @@ -65,16 +65,16 @@ impl methods for assignment_type { // the liveness pass guarantees that immutable local variables // are only assigned once; but it doesn't consider &mut alt self { - at_straight_up {true} - at_swap {true} - at_mutbl_ref {false} + at_straight_up => true, + at_swap => true, + at_mutbl_ref => false } } fn ing_form(desc: ~str) -> ~str { alt self { - at_straight_up { ~"assigning to " + desc } - at_swap { ~"swapping to and from " + desc } - at_mutbl_ref { ~"taking mut reference to " + desc } + at_straight_up => ~"assigning to " + desc, + at_swap => ~"swapping to and from " + desc, + at_mutbl_ref => ~"taking mut reference to " + desc } } } @@ -85,13 +85,13 @@ impl methods for check_loan_ctxt { fn purity(scope_id: ast::node_id) -> option<purity_cause> { let default_purity = alt self.declared_purity { // an unsafe declaration overrides all - ast::unsafe_fn { return none; } + ast::unsafe_fn => return none, // otherwise, remember what was declared as the // default, but we must scan for requirements // imposed by the borrow check - ast::pure_fn { some(pc_pure_fn) } - ast::extern_fn | ast::impure_fn { none } + ast::pure_fn => some(pc_pure_fn), + ast::extern_fn | ast::impure_fn => none }; // scan to see if this scope or any enclosing scope requires @@ -102,13 +102,13 @@ impl methods for check_loan_ctxt { let pure_map = self.req_maps.pure_map; loop { alt pure_map.find(scope_id) { - none {} - some(e) {return some(pc_cmt(e));} + none => (), + some(e) => return some(pc_cmt(e)) } alt region_map.find(scope_id) { - none { return default_purity; } - some(next_scope_id) { scope_id = next_scope_id; } + none => return default_purity, + some(next_scope_id) => scope_id = next_scope_id } } } @@ -129,8 +129,8 @@ impl methods for check_loan_ctxt { } alt region_map.find(scope_id) { - none { return; } - some(next_scope_id) { scope_id = next_scope_id; } + none => return, + some(next_scope_id) => scope_id = next_scope_id, } } } @@ -174,9 +174,9 @@ impl methods for check_loan_ctxt { // (d) B is not a fn. alt opt_expr { - some(expr) { + some(expr) => { alt expr.node { - ast::expr_path(_) if pc == pc_pure_fn { + ast::expr_path(_) if pc == pc_pure_fn => { let def = self.tcx().def_map.get(expr.id); let did = ast_util::def_id_of_def(def); let is_fn_arg = @@ -185,24 +185,24 @@ impl methods for check_loan_ctxt { if is_fn_arg { return; } // case (a) above } ast::expr_fn_block(*) | ast::expr_fn(*) | - ast::expr_loop_body(*) | ast::expr_do_body(*) { + ast::expr_loop_body(*) | ast::expr_do_body(*) => { if self.is_stack_closure(expr.id) { // case (b) above return; } } - _ {} + _ => () } } - none {} + none => () } let callee_ty = ty::node_id_to_type(tcx, callee_id); alt ty::get(callee_ty).struct { - ty::ty_fn(fn_ty) { + ty::ty_fn(fn_ty) => { alt fn_ty.purity { - ast::pure_fn { return; } // case (c) above - ast::impure_fn | ast::unsafe_fn | ast::extern_fn { + ast::pure_fn => return, // case (c) above + ast::impure_fn | ast::unsafe_fn | ast::extern_fn => { self.report_purity_error( pc, callee_span, fmt!{"access to %s function", @@ -210,7 +210,7 @@ impl methods for check_loan_ctxt { } } } - _ { return; } // case (d) above + _ => return, // case (d) above } } @@ -220,30 +220,30 @@ impl methods for check_loan_ctxt { let fn_ty = ty::node_id_to_type(self.tcx(), id); let proto = ty::ty_fn_proto(fn_ty); alt proto { - ast::proto_block {true} - ast::proto_bare | ast::proto_uniq | ast::proto_box {false} + ast::proto_block => true, + ast::proto_bare | ast::proto_uniq | ast::proto_box => false } } fn is_allowed_pure_arg(expr: @ast::expr) -> bool { return alt expr.node { - ast::expr_path(_) { + ast::expr_path(_) => { let def = self.tcx().def_map.get(expr.id); let did = ast_util::def_id_of_def(def); did.crate == ast::local_crate && (*self.fn_args).contains(did.node) } - ast::expr_fn_block(*) | ast::expr_fn(*) { + ast::expr_fn_block(*) | ast::expr_fn(*) => { self.is_stack_closure(expr.id) } - _ {false} + _ => false }; } fn check_for_conflicting_loans(scope_id: ast::node_id) { let new_loanss = alt self.req_maps.req_loan_map.find(scope_id) { - none { return; } - some(loanss) { loanss } + none => return, + some(loanss) => loanss }; let par_scope_id = self.tcx().region_map.get(scope_id); @@ -253,11 +253,11 @@ impl methods for check_loan_ctxt { if old_loan.lp != new_loan.lp { again; } alt (old_loan.mutbl, new_loan.mutbl) { (m_const, _) | (_, m_const) | - (m_mutbl, m_mutbl) | (m_imm, m_imm) { + (m_mutbl, m_mutbl) | (m_imm, m_imm) => { /*ok*/ } - (m_mutbl, m_imm) | (m_imm, m_mutbl) { + (m_mutbl, m_imm) | (m_imm, m_mutbl) => { self.bccx.span_err( new_loan.cmt.span, fmt!{"loan of %s as %s \ @@ -277,20 +277,20 @@ impl methods for check_loan_ctxt { fn is_local_variable(cmt: cmt) -> bool { alt cmt.cat { - cat_local(_) {true} - _ {false} + cat_local(_) => true, + _ => false } } fn is_self_field(cmt: cmt) -> bool { alt cmt.cat { - cat_comp(cmt_base, comp_field(*)) { + cat_comp(cmt_base, comp_field(*)) => { alt cmt_base.cat { - cat_special(sk_self) { true } - _ { false } + cat_special(sk_self) => true, + _ => false } } - _ { false } + _ => false } } @@ -308,8 +308,8 @@ impl methods for check_loan_ctxt { // are only assigned once } else { alt cmt.mutbl { - m_mutbl { /*ok*/ } - m_const | m_imm { + m_mutbl => { /*ok*/ } + m_const | m_imm => { self.bccx.span_err( ex.span, at.ing_form(self.bccx.cmt_to_str(cmt))); @@ -322,8 +322,8 @@ impl methods for check_loan_ctxt { // assigned, because it is uniquely tied to this function and // is not visible from the outside alt self.purity(ex.id) { - none {} - some(pc) { + none => (), + some(pc) => { if cmt.lp.is_none() { self.report_purity_error( pc, ex.span, at.ing_form(self.bccx.cmt_to_str(cmt))); @@ -353,8 +353,8 @@ impl methods for check_loan_ctxt { for self.walk_loans_of(ex.id, lp) |loan| { alt loan.mutbl { - m_mutbl | m_const { /*ok*/ } - m_imm { + m_mutbl | m_const => { /*ok*/ } + m_imm => { self.bccx.span_err( ex.span, fmt!{"%s prohibited due to outstanding loan", @@ -376,22 +376,22 @@ impl methods for check_loan_ctxt { // let y = &x; // x loaned out as immutable // x.f = none; // changes type of y.f, which appears to be imm alt *lp { - lp_comp(lp_base, ck) if inherent_mutability(ck) != m_mutbl { + lp_comp(lp_base, ck) if inherent_mutability(ck) != m_mutbl => { self.check_for_loan_conflicting_with_assignment( at, ex, cmt, lp_base); } - lp_comp(*) | lp_local(*) | lp_arg(*) | lp_deref(*) {} + lp_comp(*) | lp_local(*) | lp_arg(*) | lp_deref(*) => () } } fn report_purity_error(pc: purity_cause, sp: span, msg: ~str) { alt pc { - pc_pure_fn { + pc_pure_fn => { self.tcx().sess.span_err( sp, fmt!{"%s prohibited in pure context", msg}); } - pc_cmt(e) { + pc_cmt(e) => { if self.reported.insert(e.cmt.id, ()) { self.tcx().sess.span_err( e.cmt.span, @@ -416,18 +416,17 @@ impl methods for check_loan_ctxt { alt cmt.cat { // Rvalues, locals, and arguments can be moved: - cat_rvalue | cat_local(_) | cat_arg(_) { } + cat_rvalue | cat_local(_) | cat_arg(_) => {} // We allow moving out of static items because the old code // did. This seems consistent with permitting moves out of // rvalues, I guess. - cat_special(sk_static_item) { } + cat_special(sk_static_item) => {} - cat_deref(_, _, unsafe_ptr) { - } + cat_deref(_, _, unsafe_ptr) => {} // Nothing else. - _ { + _ => { self.bccx.span_err( cmt.span, fmt!{"moving out of %s", self.bccx.cmt_to_str(cmt)}); @@ -439,8 +438,8 @@ impl methods for check_loan_ctxt { // check for a conflicting loan: let lp = alt cmt.lp { - none { return; } - some(lp) { lp } + none => return, + some(lp) => lp }; for self.walk_loans_of(cmt.id, lp) |loan| { self.bccx.span_err( @@ -461,8 +460,8 @@ impl methods for check_loan_ctxt { fn check_last_use(expr: @ast::expr) { let cmt = self.bccx.cat_expr(expr); let lp = alt cmt.lp { - none { return; } - some(lp) { lp } + none => return, + some(lp) => lp }; for self.walk_loans_of(cmt.id, lp) |_loan| { debug!{"Removing last use entry %? due to outstanding loan", @@ -478,8 +477,8 @@ impl methods for check_loan_ctxt { callee_span: span, args: ~[@ast::expr]) { alt self.purity(expr.id) { - none {} - some(pc) { + none => {} + some(pc) => { self.check_pure_callee_or_arg( pc, callee, callee_id, callee_span); for args.each |arg| { @@ -493,13 +492,13 @@ impl methods for check_loan_ctxt { ty::node_id_to_type(self.tcx(), callee_id)); do vec::iter2(args, arg_tys) |arg, arg_ty| { alt ty::resolved_mode(self.tcx(), arg_ty.mode) { - ast::by_move { + ast::by_move => { self.check_move_out(arg); } - ast::by_mutbl_ref { + ast::by_mutbl_ref => { self.check_assignment(at_mutbl_ref, arg); } - ast::by_ref | ast::by_copy | ast::by_val { + ast::by_ref | ast::by_copy | ast::by_val => { } } } @@ -523,19 +522,19 @@ fn check_loans_in_fn(fk: visit::fn_kind, decl: ast::fn_decl, body: ast::blk, // able to "see" into those functions anyway, so it // wouldn't be very helpful. alt fk { - visit::fk_ctor(*) { + visit::fk_ctor(*) => { self.in_ctor = true; self.declared_purity = decl.purity; self.fn_args = @decl.inputs.map(|i| i.id ); } visit::fk_anon(*) | - visit::fk_fn_block(*) if is_stack_closure { + visit::fk_fn_block(*) if is_stack_closure => { self.in_ctor = false; // inherits the purity/fn_args from enclosing ctxt } visit::fk_anon(*) | visit::fk_fn_block(*) | visit::fk_method(*) | visit::fk_item_fn(*) | - visit::fk_dtor(*) { + visit::fk_dtor(*) => { self.in_ctor = false; self.declared_purity = decl.purity; self.fn_args = @decl.inputs.map(|i| i.id ); @@ -553,10 +552,10 @@ fn check_loans_in_local(local: @ast::local, &&self: check_loan_ctxt, vt: visit::vt<check_loan_ctxt>) { alt local.node.init { - some({op: ast::init_move, expr: expr}) { + some({op: ast::init_move, expr: expr}) => { self.check_move_out(expr); } - some({op: ast::init_assign, _}) | none {} + some({op: ast::init_assign, _}) | none => {} } visit::visit_local(local, self, vt); } @@ -567,27 +566,27 @@ fn check_loans_in_expr(expr: @ast::expr, self.check_for_conflicting_loans(expr.id); alt expr.node { - ast::expr_path(*) if self.bccx.last_use_map.contains_key(expr.id) { + ast::expr_path(*) if self.bccx.last_use_map.contains_key(expr.id) => { self.check_last_use(expr); } - ast::expr_swap(l, r) { + ast::expr_swap(l, r) => { self.check_assignment(at_swap, l); self.check_assignment(at_swap, r); } - ast::expr_move(dest, src) { + ast::expr_move(dest, src) => { self.check_assignment(at_straight_up, dest); self.check_move_out(src); } - ast::expr_unary_move(src) { + ast::expr_unary_move(src) => { self.check_move_out(src); } ast::expr_assign(dest, _) | - ast::expr_assign_op(_, dest, _) { + ast::expr_assign_op(_, dest, _) => { self.check_assignment(at_straight_up, dest); } ast::expr_fn(_, _, _, cap_clause) | - ast::expr_fn_block(_, _, cap_clause) { + ast::expr_fn_block(_, _, cap_clause) => { for (*cap_clause).each |cap_item| { if cap_item.is_move { let def = self.tcx().def_map.get(cap_item.id); @@ -601,25 +600,25 @@ fn check_loans_in_expr(expr: @ast::expr, } } } - ast::expr_addr_of(mutbl, base) { + ast::expr_addr_of(mutbl, base) => { alt mutbl { - m_const { /*all memory is const*/ } - m_mutbl { + m_const => { /*all memory is const*/ } + m_mutbl => { // If we are taking an &mut ptr, make sure the memory // being pointed at is assignable in the first place: self.check_assignment(at_mutbl_ref, base); } - m_imm { + m_imm => { // XXX explain why no check is req'd here } } } - ast::expr_call(f, args, _) { + ast::expr_call(f, args, _) => { self.check_call(expr, some(f), f.id, f.span, args); } ast::expr_index(_, rval) | ast::expr_binary(_, _, rval) - if self.bccx.method_map.contains_key(expr.id) { + if self.bccx.method_map.contains_key(expr.id) => { self.check_call(expr, none, expr.callee_id, @@ -627,14 +626,14 @@ fn check_loans_in_expr(expr: @ast::expr, ~[rval]); } ast::expr_unary(*) | ast::expr_index(*) - if self.bccx.method_map.contains_key(expr.id) { + if self.bccx.method_map.contains_key(expr.id) => { self.check_call(expr, none, expr.callee_id, expr.span, ~[]); } - _ { } + _ => { } } visit::visit_expr(expr, self, vt); @@ -647,12 +646,12 @@ fn check_loans_in_block(blk: ast::blk, self.check_for_conflicting_loans(blk.node.id); alt blk.node.rules { - ast::default_blk { + ast::default_blk => { } - ast::unchecked_blk { + ast::unchecked_blk => { self.declared_purity = ast::impure_fn; } - ast::unsafe_blk { + ast::unsafe_blk => { self.declared_purity = ast::unsafe_fn; } } diff --git a/src/rustc/middle/borrowck/gather_loans.rs b/src/rustc/middle/borrowck/gather_loans.rs index 673cfa379a8..88e329f63c0 100644 --- a/src/rustc/middle/borrowck/gather_loans.rs +++ b/src/rustc/middle/borrowck/gather_loans.rs @@ -71,9 +71,9 @@ fn req_loans_in_fn(fk: visit::fn_kind, self.root_ub = body.node.id; alt fk { - visit::fk_anon(*) | visit::fk_fn_block(*) {} + visit::fk_anon(*) | visit::fk_fn_block(*) => {} visit::fk_item_fn(*) | visit::fk_method(*) | - visit::fk_ctor(*) | visit::fk_dtor(*) { + visit::fk_ctor(*) | visit::fk_dtor(*) => { self.item_ub = body.node.id; } } @@ -100,33 +100,33 @@ fn req_loans_in_expr(ex: @ast::expr, // Special checks for various kinds of expressions: alt ex.node { - ast::expr_addr_of(mutbl, base) { + ast::expr_addr_of(mutbl, base) => { let base_cmt = self.bccx.cat_expr(base); // make sure that the thing we are pointing out stays valid // for the lifetime `scope_r` of the resulting ptr: let scope_r = alt check ty::get(tcx.ty(ex)).struct { - ty::ty_rptr(r, _) { r } + ty::ty_rptr(r, _) => r }; self.guarantee_valid(base_cmt, mutbl, scope_r); visit::visit_expr(ex, self, vt); } - ast::expr_call(f, args, _) { + ast::expr_call(f, args, _) => { let arg_tys = ty::ty_fn_args(ty::expr_ty(self.tcx(), f)); let scope_r = ty::re_scope(ex.id); do vec::iter2(args, arg_tys) |arg, arg_ty| { alt ty::resolved_mode(self.tcx(), arg_ty.mode) { - ast::by_mutbl_ref { + ast::by_mutbl_ref => { let arg_cmt = self.bccx.cat_expr(arg); self.guarantee_valid(arg_cmt, m_mutbl, scope_r); } - ast::by_ref { + ast::by_ref => { let arg_cmt = self.bccx.cat_expr(arg); self.guarantee_valid(arg_cmt, m_imm, scope_r); } - ast::by_val { + ast::by_val => { // Rust's by-val does not actually give ownership to // the callee. This means that if a pointer type is // passed, it is effectively a borrow, and so the @@ -153,27 +153,27 @@ fn req_loans_in_expr(ex: @ast::expr, // alt opt_deref_kind(arg_ty.ty) { some(deref_ptr(region_ptr(_))) | - some(deref_ptr(unsafe_ptr)) { + some(deref_ptr(unsafe_ptr)) => { /* region pointers are (by induction) guaranteed */ /* unsafe pointers are the user's problem */ } some(deref_comp(_)) | - none { + none => { /* not a pointer, no worries */ } - some(deref_ptr(_)) { + some(deref_ptr(_)) => { let arg_cmt = self.bccx.cat_borrow_of_expr(arg); self.guarantee_valid(arg_cmt, m_const, scope_r); } } } - ast::by_move | ast::by_copy {} + ast::by_move | ast::by_copy => {} } } visit::visit_expr(ex, self, vt); } - ast::expr_alt(ex_v, arms, _) { + ast::expr_alt(ex_v, arms, _) => { let cmt = self.bccx.cat_expr(ex_v); for arms.each |arm| { for arm.pats.each |pat| { @@ -185,7 +185,8 @@ fn req_loans_in_expr(ex: @ast::expr, ast::expr_index(rcvr, _) | ast::expr_binary(_, rcvr, _) | - ast::expr_unary(_, rcvr) if self.bccx.method_map.contains_key(ex.id) { + ast::expr_unary(_, rcvr) + if self.bccx.method_map.contains_key(ex.id) => { // Receivers in method calls are always passed by ref. // // Here, in an overloaded operator, the call is this expression, @@ -202,7 +203,7 @@ fn req_loans_in_expr(ex: @ast::expr, } ast::expr_field(rcvr, _, _) - if self.bccx.method_map.contains_key(ex.id) { + if self.bccx.method_map.contains_key(ex.id) => { // Receivers in method calls are always passed by ref. // // Here, the field a.b is in fact a closure. Eventually, this @@ -218,7 +219,7 @@ fn req_loans_in_expr(ex: @ast::expr, } // see explanation attached to the `root_ub` field: - ast::expr_while(cond, body) { + ast::expr_while(cond, body) => { // during the condition, can only root for the condition self.root_ub = cond.id; vt.visit_expr(cond, self, vt); @@ -229,7 +230,7 @@ fn req_loans_in_expr(ex: @ast::expr, } // see explanation attached to the `root_ub` field: - ast::expr_loop(body) { + ast::expr_loop(body) => { self.root_ub = body.node.id; visit::visit_expr(ex, self, vt); } @@ -275,7 +276,7 @@ impl methods for gather_loan_ctxt { // duration of the reference: if there is an attempt to move // it within that scope, the loan will be detected and an // error will be reported. - some(_) { + some(_) => { alt self.bccx.loan(cmt, scope_r, req_mutbl) { err(e) => { self.bccx.report(e); } ok(loans) if loans.len() == 0 => {} @@ -313,7 +314,7 @@ impl methods for gather_loan_ctxt { // also check that the mutability of the desired pointer // matches with the actual mutability (but if an immutable // pointer is desired, that is ok as long as we are pure) - none { + none => { let result: bckres<preserve_condition> = { do self.check_mutbl(req_mutbl, cmt).chain |pc1| { do self.bccx.preserve(cmt, scope_r, @@ -325,13 +326,13 @@ impl methods for gather_loan_ctxt { }; alt result { - ok(pc_ok) { + ok(pc_ok) => { // we were able guarantee the validity of the ptr, // perhaps by rooting or because it is immutably // rooted. good. self.bccx.stable_paths += 1; } - ok(pc_if_pure(e)) { + ok(pc_if_pure(e)) => { // we are only able to guarantee the validity if // the scope is pure alt scope_r { @@ -397,10 +398,10 @@ impl methods for gather_loan_ctxt { fn add_loans(scope_id: ast::node_id, loans: @dvec<loan>) { alt self.req_maps.req_loan_map.find(scope_id) { - some(l) { + some(l) => { (*l).push(loans); } - none { + none => { self.req_maps.req_loan_map.insert( scope_id, @dvec::from_vec(~[mut loans])); } @@ -450,21 +451,21 @@ impl methods for gather_loan_ctxt { let tcx = self.tcx(); alt pat.node { - ast::pat_wild { + ast::pat_wild => { // _ } - ast::pat_enum(_, none) { + ast::pat_enum(_, none) => { // variant(*) } - ast::pat_enum(_, some(subpats)) { + ast::pat_enum(_, some(subpats)) => { // variant(x, y, z) let enum_did = alt self.bccx.tcx.def_map .find(pat.id) { - some(ast::def_variant(enum_did, _)) {enum_did} - e {tcx.sess.span_bug(pat.span, - fmt!{"resolved to %?, \ - not variant", e})} + some(ast::def_variant(enum_did, _)) => enum_did, + e => tcx.sess.span_bug(pat.span, + fmt!{"resolved to %?, \ + not variant", e}) }; for subpats.each |subpat| { @@ -473,11 +474,11 @@ impl methods for gather_loan_ctxt { } } - ast::pat_ident(_, _, none) if self.pat_is_variant(pat) { + ast::pat_ident(_, _, none) if self.pat_is_variant(pat) => { // nullary variant debug!{"nullary variant"}; } - ast::pat_ident(_, id, o_pat) { + ast::pat_ident(_, id, o_pat) => { // XXX: Needs to take by-ref/by-val into account. // x or x @ p --- `x` must remain valid for the scope of the alt @@ -504,7 +505,7 @@ impl methods for gather_loan_ctxt { } } - ast::pat_rec(field_pats, _) { + ast::pat_rec(field_pats, _) => { // {f1: p1, ..., fN: pN} for field_pats.each |fp| { let cmt_field = self.bccx.cat_field(fp.pat, cmt, fp.ident); @@ -512,7 +513,7 @@ impl methods for gather_loan_ctxt { } } - ast::pat_tup(subpats) { + ast::pat_tup(subpats) => { // (p1, ..., pN) for subpats.each |subpat| { let subcmt = self.bccx.cat_tuple_elt(subpat, cmt); @@ -520,19 +521,19 @@ impl methods for gather_loan_ctxt { } } - ast::pat_box(subpat) | ast::pat_uniq(subpat) { + ast::pat_box(subpat) | ast::pat_uniq(subpat) => { // @p1, ~p1 alt self.bccx.cat_deref(subpat, cmt, 0u, true) { - some(subcmt) { + some(subcmt) => { self.gather_pat(subcmt, subpat, arm_id, alt_id); } - none { + none => { tcx.sess.span_bug(pat.span, ~"Non derefable type"); } } } - ast::pat_lit(_) | ast::pat_range(_, _) { /*always ok*/ } + ast::pat_lit(_) | ast::pat_range(_, _) => { /*always ok*/ } } } diff --git a/src/rustc/middle/borrowck/loan.rs b/src/rustc/middle/borrowck/loan.rs index b466cfd3a43..5479afd10b7 100644 --- a/src/rustc/middle/borrowck/loan.rs +++ b/src/rustc/middle/borrowck/loan.rs @@ -71,25 +71,25 @@ impl loan_methods for loan_ctxt { } alt cmt.cat { - cat_binding(_) | cat_rvalue | cat_special(_) { + cat_binding(_) | cat_rvalue | cat_special(_) => { // should never be loanable self.bccx.tcx.sess.span_bug( cmt.span, ~"rvalue with a non-none lp"); } - cat_local(local_id) | cat_arg(local_id) { + cat_local(local_id) | cat_arg(local_id) => { let local_scope_id = self.tcx().region_map.get(local_id); self.ok_with_loan_of(cmt, ty::re_scope(local_scope_id), req_mutbl) } - cat_stack_upvar(cmt) { + cat_stack_upvar(cmt) => { self.loan(cmt, req_mutbl) // NDM correct? } - cat_discr(base, _) { + cat_discr(base, _) => { self.loan(base, req_mutbl) } cat_comp(cmt_base, comp_field(*)) | cat_comp(cmt_base, comp_index(*)) | - cat_comp(cmt_base, comp_tuple) { + cat_comp(cmt_base, comp_tuple) => { // For most components, the type of the embedded data is // stable. Therefore, the base structure need only be // const---unless the component must be immutable. In @@ -98,7 +98,7 @@ impl loan_methods for loan_ctxt { // overwritten and the component along with it. self.loan_stable_comp(cmt, cmt_base, req_mutbl) } - cat_comp(cmt_base, comp_variant(enum_did)) { + cat_comp(cmt_base, comp_variant(enum_did)) => { // For enums, the memory is unstable if there are multiple // variants, because if the enum value is overwritten then // the memory changes type. @@ -108,7 +108,7 @@ impl loan_methods for loan_ctxt { self.loan_unstable_deref(cmt, cmt_base, req_mutbl) } } - cat_deref(cmt_base, _, uniq_ptr) { + cat_deref(cmt_base, _, uniq_ptr) => { // For unique pointers, the memory being pointed out is // unstable because if the unique pointer is overwritten // then the memory is freed. @@ -116,7 +116,7 @@ impl loan_methods for loan_ctxt { } cat_deref(cmt1, _, unsafe_ptr) | cat_deref(cmt1, _, gc_ptr) | - cat_deref(cmt1, _, region_ptr(_)) { + cat_deref(cmt1, _, region_ptr(_)) => { // Aliased data is simply not lendable. self.bccx.tcx.sess.span_bug( cmt.span, @@ -132,8 +132,8 @@ impl loan_methods for loan_ctxt { cmt_base: cmt, req_mutbl: ast::mutability) -> bckres<()> { let base_mutbl = alt req_mutbl { - m_imm { m_imm } - m_const | m_mutbl { m_const } + m_imm => m_imm, + m_const | m_mutbl => m_const }; do self.loan(cmt_base, base_mutbl).chain |_ok| { diff --git a/src/rustc/middle/borrowck/preserve.rs b/src/rustc/middle/borrowck/preserve.rs index 0b7601f59d2..568030c85b5 100644 --- a/src/rustc/middle/borrowck/preserve.rs +++ b/src/rustc/middle/borrowck/preserve.rs @@ -64,13 +64,13 @@ impl private_methods for &preserve_ctxt { let _i = indenter(); alt cmt.cat { - cat_special(sk_self) | cat_special(sk_heap_upvar) { + cat_special(sk_self) | cat_special(sk_heap_upvar) => { self.compare_scope(cmt, ty::re_scope(self.item_ub)) } - cat_special(sk_static_item) | cat_special(sk_method) { + cat_special(sk_static_item) | cat_special(sk_method) => { ok(pc_ok) } - cat_rvalue { + cat_rvalue => { // when we borrow an rvalue, we can keep it rooted but only // up to the root_ub point @@ -85,10 +85,10 @@ impl private_methods for &preserve_ctxt { // FIXME(#2977)--need to update trans! self.compare_scope(cmt, scope_region) } - cat_stack_upvar(cmt) { + cat_stack_upvar(cmt) => { self.preserve(cmt) } - cat_local(local_id) { + cat_local(local_id) => { // Normally, local variables are lendable, and so this // case should never trigger. However, if we are // preserving an expression like a.b where the field `b` @@ -103,14 +103,14 @@ impl private_methods for &preserve_ctxt { let local_scope_id = self.tcx().region_map.get(local_id); self.compare_scope(cmt, ty::re_scope(local_scope_id)) } - cat_binding(local_id) { + cat_binding(local_id) => { // Bindings are these kind of weird implicit pointers (cc // #2329). We require (in gather_loans) that they be // rooted in an immutable location. let local_scope_id = self.tcx().region_map.get(local_id); self.compare_scope(cmt, ty::re_scope(local_scope_id)) } - cat_arg(local_id) { + cat_arg(local_id) => { // This can happen as not all args are lendable (e.g., && // modes). In that case, the caller guarantees stability // for at least the scope of the fn. This is basically a @@ -120,12 +120,12 @@ impl private_methods for &preserve_ctxt { } cat_comp(cmt_base, comp_field(*)) | cat_comp(cmt_base, comp_index(*)) | - cat_comp(cmt_base, comp_tuple) { + cat_comp(cmt_base, comp_tuple) => { // Most embedded components: if the base is stable, the // type never changes. self.preserve(cmt_base) } - cat_comp(cmt_base, comp_variant(enum_did)) { + cat_comp(cmt_base, comp_variant(enum_did)) => { if ty::enum_is_univariant(self.tcx(), enum_did) { self.preserve(cmt_base) } else { @@ -135,22 +135,22 @@ impl private_methods for &preserve_ctxt { self.require_imm(cmt, cmt_base, err_mut_variant) } } - cat_deref(cmt_base, _, uniq_ptr) { + cat_deref(cmt_base, _, uniq_ptr) => { // Overwriting the base could cause this memory to be // freed, so require imm. self.require_imm(cmt, cmt_base, err_mut_uniq) } - cat_deref(_, _, region_ptr(region)) { + cat_deref(_, _, region_ptr(region)) => { // References are always "stable" for lifetime `region` by // induction (when the reference of type &MT was created, // the memory must have been stable). self.compare_scope(cmt, region) } - cat_deref(_, _, unsafe_ptr) { + cat_deref(_, _, unsafe_ptr) => { // Unsafe pointers are the user's problem ok(pc_ok) } - cat_deref(base, derefs, gc_ptr) { + cat_deref(base, derefs, gc_ptr) => { // GC'd pointers of type @MT: if this pointer lives in // immutable, stable memory, then everything is fine. But // otherwise we have no guarantee the pointer will stay @@ -164,7 +164,7 @@ impl private_methods for &preserve_ctxt { ok(pc_ok) => { ok(pc_ok) } - ok(pc_if_pure(_)) { + ok(pc_if_pure(_)) => { debug!{"must root @T, otherwise purity req'd"}; self.attempt_root(cmt, base, derefs) } @@ -178,7 +178,7 @@ impl private_methods for &preserve_ctxt { self.attempt_root(cmt, base, derefs) } } - cat_discr(base, alt_id) { + cat_discr(base, alt_id) => { // Subtle: in an alt, we must ensure that each binding // variable remains valid for the duration of the arm in // which it appears, presuming that this arm is taken. diff --git a/src/rustc/middle/capture.rs b/src/rustc/middle/capture.rs index dcb7a70ab50..1af377e1ba2 100644 --- a/src/rustc/middle/capture.rs +++ b/src/rustc/middle/capture.rs @@ -102,15 +102,15 @@ fn compute_capture_vars(tcx: ty::ctxt, // named and add that let implicit_mode = alt fn_proto { - ast::proto_block { cap_ref } - ast::proto_bare | ast::proto_box | ast::proto_uniq { cap_copy } + ast::proto_block => cap_ref, + ast::proto_bare | ast::proto_box | ast::proto_uniq => cap_copy }; do vec::iter(*freevars) |fvar| { let fvar_def_id = ast_util::def_id_of_def(fvar.def).node; alt cap_map.find(fvar_def_id) { - option::some(_) { /* was explicitly named, do nothing */ } - option::none { + option::some(_) => { /* was explicitly named, do nothing */ } + option::none => { cap_map.insert(fvar_def_id, {def:fvar.def, span: fvar.span, cap_item: none, diff --git a/src/rustc/middle/check_alt.rs b/src/rustc/middle/check_alt.rs index 3986cb38bbf..28fbfacb78c 100644 --- a/src/rustc/middle/check_alt.rs +++ b/src/rustc/middle/check_alt.rs @@ -23,7 +23,7 @@ fn check_crate(tcx: ty::ctxt, crate: @crate) { fn check_expr(tcx: ty::ctxt, ex: @expr, &&s: (), v: visit::vt<()>) { visit::visit_expr(ex, s, v); alt ex.node { - expr_alt(scrut, arms, mode) { + expr_alt(scrut, arms, mode) => { check_arms(tcx, arms); /* Check for exhaustiveness */ // Check for empty enum, because is_useful only works on inhabited @@ -34,13 +34,13 @@ fn check_expr(tcx: ty::ctxt, ex: @expr, &&s: (), v: visit::vt<()>) { return; } alt ty::get(pat_ty).struct { - ty_enum(did, _) { + ty_enum(did, _) => { if (*enum_variants(tcx, did)).is_empty() && arms.is_empty() { return; } } - _ { /* We assume only enum types can be uninhabited */ } + _ => { /* We assume only enum types can be uninhabited */ } } if mode == alt_exhaustive { @@ -48,7 +48,7 @@ fn check_expr(tcx: ty::ctxt, ex: @expr, &&s: (), v: visit::vt<()>) { check_exhaustive(tcx, ex.span, arms); } } - _ { } + _ => () } } @@ -59,10 +59,10 @@ fn check_arms(tcx: ty::ctxt, arms: ~[arm]) { for arm.pats.each |pat| { let v = ~[pat]; alt is_useful(tcx, seen, v) { - not_useful { + not_useful => { tcx.sess.span_err(pat.span, ~"unreachable pattern"); } - _ {} + _ => () } if option::is_none(arm.guard) { vec::push(seen, v); } } @@ -79,30 +79,30 @@ fn raw_pat(p: @pat) -> @pat { fn check_exhaustive(tcx: ty::ctxt, sp: span, pats: ~[@pat]) { assert(pats.is_not_empty()); let ext = alt is_useful(tcx, vec::map(pats, |p| ~[p]), ~[wild()]) { - not_useful { return; } // This is good, wildcard pattern isn't reachable - useful_ { none } - useful(ty, ctor) { + not_useful => return, // This is good, wildcard pattern isn't reachable + useful_ => none, + useful(ty, ctor) => { alt ty::get(ty).struct { - ty::ty_bool { + ty::ty_bool => { alt check ctor { - val(const_int(1i64)) { some(@~"true") } - val(const_int(0i64)) { some(@~"false") } + val(const_int(1i64)) => some(@~"true"), + val(const_int(0i64)) => some(@~"false") } } - ty::ty_enum(id, _) { - let vid = alt check ctor { variant(id) { id } }; + ty::ty_enum(id, _) => { + let vid = alt check ctor { variant(id) => id }; alt check vec::find(*ty::enum_variants(tcx, id), |v| v.id == vid) { - some(v) { some(v.name) } + some(v) => some(v.name) } } - _ { none } + _ => none } } }; let msg = ~"non-exhaustive patterns" + alt ext { - some(s) { ~": " + *s + ~" not covered" } - none { ~"" } + some(s) => ~": " + *s + ~" not covered", + none => ~"" }; tcx.sess.span_err(sp, msg); } @@ -135,52 +135,52 @@ fn is_useful(tcx: ty::ctxt, m: matrix, v: ~[@pat]) -> useful { if m.len() == 0u { return useful_; } if m[0].len() == 0u { return not_useful; } let real_pat = alt vec::find(m, |r| r[0].id != 0) { - some(r) { r[0] } none { v[0] } + some(r) => r[0], none => v[0] }; let left_ty = if real_pat.id == 0 { ty::mk_nil(tcx) } else { ty::node_id_to_type(tcx, real_pat.id) }; alt pat_ctor_id(tcx, v[0]) { - none { + none => { alt missing_ctor(tcx, m, left_ty) { - none { + none => { alt ty::get(left_ty).struct { - ty::ty_bool { + ty::ty_bool => { alt is_useful_specialized(tcx, m, v, val(const_int(1i64)), 0u, left_ty){ - not_useful { + not_useful => { is_useful_specialized(tcx, m, v, val(const_int(0i64)), 0u, left_ty) } - u { u } + u => u } } - ty::ty_enum(eid, _) { + ty::ty_enum(eid, _) => { for (*ty::enum_variants(tcx, eid)).each |va| { alt is_useful_specialized(tcx, m, v, variant(va.id), va.args.len(), left_ty) { - not_useful {} - u { return u; } + not_useful => (), + u => return u } } not_useful } - _ { + _ => { let arity = ctor_arity(tcx, single, left_ty); is_useful_specialized(tcx, m, v, single, arity, left_ty) } } } - some(ctor) { + some(ctor) => { alt is_useful(tcx, vec::filter_map(m, |r| default(tcx, r) ), vec::tail(v)) { - useful_ { useful(left_ty, ctor) } - u { u } + useful_ => useful(left_ty, ctor), + u => u } } } } - some(v0_ctor) { + some(v0_ctor) => { let arity = ctor_arity(tcx, v0_ctor, left_ty); is_useful_specialized(tcx, m, v, v0_ctor, arity, left_ty) } @@ -191,8 +191,8 @@ fn is_useful_specialized(tcx: ty::ctxt, m: matrix, v: ~[@pat], ctor: ctor, arity: uint, lty: ty::t) -> useful { let ms = vec::filter_map(m, |r| specialize(tcx, r, ctor, arity, lty) ); alt is_useful(tcx, ms, option::get(specialize(tcx, v, ctor, arity, lty))){ - useful_ { useful(lty, ctor) } - u { u } + useful_ => useful(lty, ctor), + u => u } } @@ -202,8 +202,8 @@ fn pat_ctor_id(tcx: ty::ctxt, p: @pat) -> option<ctor> { pat_wild => { none } pat_ident(_, _, _) | pat_enum(_, _) => { alt tcx.def_map.find(pat.id) { - some(def_variant(_, id)) { some(variant(id)) } - _ { none } + some(def_variant(_, id)) => some(variant(id)), + _ => none } } pat_lit(expr) => { some(val(eval_const_expr(tcx, expr))) } @@ -232,13 +232,13 @@ fn is_wild(tcx: ty::ctxt, p: @pat) -> bool { fn missing_ctor(tcx: ty::ctxt, m: matrix, left_ty: ty::t) -> option<ctor> { alt ty::get(left_ty).struct { - ty::ty_box(_) | ty::ty_uniq(_) | ty::ty_tup(_) | ty::ty_rec(_) { + ty::ty_box(_) | ty::ty_uniq(_) | ty::ty_tup(_) | ty::ty_rec(_) => { for m.each |r| { if !is_wild(tcx, r[0]) { return none; } } return some(single); } - ty::ty_enum(eid, _) { + ty::ty_enum(eid, _) => { let mut found = ~[]; for m.each |r| { do option::iter(pat_ctor_id(tcx, r[0])) |id| { @@ -255,36 +255,36 @@ fn missing_ctor(tcx: ty::ctxt, m: matrix, left_ty: ty::t) -> option<ctor> { fail; } else { none } } - ty::ty_nil { none } - ty::ty_bool { + ty::ty_nil => none, + ty::ty_bool => { let mut true_found = false, false_found = false; for m.each |r| { alt check pat_ctor_id(tcx, r[0]) { - none {} - some(val(const_int(1i64))) { true_found = true; } - some(val(const_int(0i64))) { false_found = true; } + none => (), + some(val(const_int(1i64))) => true_found = true, + some(val(const_int(0i64))) => false_found = true } } if true_found && false_found { none } else if true_found { some(val(const_int(0i64))) } else { some(val(const_int(1i64))) } } - _ { some(single) } + _ => some(single) } } fn ctor_arity(tcx: ty::ctxt, ctor: ctor, ty: ty::t) -> uint { alt ty::get(ty).struct { - ty::ty_tup(fs) { fs.len() } - ty::ty_rec(fs) { fs.len() } - ty::ty_box(_) | ty::ty_uniq(_) { 1u } - ty::ty_enum(eid, _) { - let id = alt check ctor { variant(id) { id } }; + ty::ty_tup(fs) => fs.len(), + ty::ty_rec(fs) => fs.len(), + ty::ty_box(_) | ty::ty_uniq(_) => 1u, + ty::ty_enum(eid, _) => { + let id = alt check ctor { variant(id) => id }; alt check vec::find(*ty::enum_variants(tcx, eid), |v| v.id == id ) { - some(v) { v.args.len() } + some(v) => v.args.len() } } - _ { 0u } + _ => 0u } } @@ -296,57 +296,59 @@ fn specialize(tcx: ty::ctxt, r: ~[@pat], ctor_id: ctor, arity: uint, left_ty: ty::t) -> option<~[@pat]> { let r0 = raw_pat(r[0]); alt r0.node { - pat_wild { some(vec::append(vec::from_elem(arity, wild()), - vec::tail(r))) } - pat_ident(_, _, _) { + pat_wild => some(vec::append(vec::from_elem(arity, wild()), + vec::tail(r))), + pat_ident(_, _, _) => { alt tcx.def_map.find(r0.id) { - some(def_variant(_, id)) { + some(def_variant(_, id)) => { if variant(id) == ctor_id { some(vec::tail(r)) } else { none } } - _ { some(vec::append(vec::from_elem(arity, wild()), vec::tail(r))) } + _ => some(vec::append(vec::from_elem(arity, wild()), vec::tail(r))) } } - pat_enum(_, args) { + pat_enum(_, args) => { alt check tcx.def_map.get(r0.id) { - def_variant(_, id) if variant(id) == ctor_id { + def_variant(_, id) if variant(id) == ctor_id => { let args = alt args { - some(args) { args } - none { vec::from_elem(arity, wild()) } + some(args) => args, + none => vec::from_elem(arity, wild()) }; some(vec::append(args, vec::tail(r))) } - def_variant(_, _) { none } + def_variant(_, _) => none } } - pat_rec(flds, _) { + pat_rec(flds, _) => { let ty_flds = alt check ty::get(left_ty).struct { - ty::ty_rec(flds) { flds } + ty::ty_rec(flds) => flds }; let args = vec::map(ty_flds, |ty_f| { alt vec::find(flds, |f| f.ident == ty_f.ident ) { - some(f) { f.pat } _ { wild() } + some(f) => f.pat, _ => wild() } }); some(vec::append(args, vec::tail(r))) } - pat_tup(args) { some(vec::append(args, vec::tail(r))) } - pat_box(a) | pat_uniq(a) { some(vec::append(~[a], vec::tail(r))) } - pat_lit(expr) { + pat_tup(args) => some(vec::append(args, vec::tail(r))), + pat_box(a) | pat_uniq(a) => some(vec::append(~[a], vec::tail(r))), + pat_lit(expr) => { let e_v = eval_const_expr(tcx, expr); let match_ = alt check ctor_id { - val(v) { compare_const_vals(e_v, v) == 0 } - range(c_lo, c_hi) { compare_const_vals(c_lo, e_v) >= 0 && - compare_const_vals(c_hi, e_v) <= 0 } - single { true } + val(v) => compare_const_vals(e_v, v) == 0, + range(c_lo, c_hi) => { + compare_const_vals(c_lo, e_v) >= 0 && + compare_const_vals(c_hi, e_v) <= 0 + } + single => true }; if match_ { some(vec::tail(r)) } else { none } } - pat_range(lo, hi) { + pat_range(lo, hi) => { let (c_lo, c_hi) = alt check ctor_id { - val(v) { (v, v) } - range(lo, hi) { (lo, hi) } - single { return some(vec::tail(r)); } + val(v) => (v, v), + range(lo, hi) => (lo, hi), + single => return some(vec::tail(r)), }; let v_lo = eval_const_expr(tcx, lo), v_hi = eval_const_expr(tcx, hi); @@ -372,10 +374,10 @@ fn check_local(tcx: ty::ctxt, loc: @local, &&s: (), v: visit::vt<()>) { fn is_refutable(tcx: ty::ctxt, pat: @pat) -> bool { alt tcx.def_map.find(pat.id) { - some(def_variant(enum_id, var_id)) { + some(def_variant(enum_id, var_id)) => { if vec::len(*ty::enum_variants(tcx, enum_id)) != 1u { return true; } } - _ {} + _ => () } alt pat.node { diff --git a/src/rustc/middle/check_const.rs b/src/rustc/middle/check_const.rs index 3d485338ffb..4d2ffa4b3e9 100644 --- a/src/rustc/middle/check_const.rs +++ b/src/rustc/middle/check_const.rs @@ -21,18 +21,18 @@ fn check_item(sess: session, ast_map: ast_map::map, def_map: resolve3::DefMap, it: @item, &&_is_const: bool, v: visit::vt<bool>) { alt it.node { - item_const(_, ex) { + item_const(_, ex) => { v.visit_expr(ex, true, v); check_item_recursion(sess, ast_map, def_map, it); } - item_enum(vs, _) { + item_enum(vs, _) => { for vs.each |var| { do option::iter(var.node.disr_expr) |ex| { v.visit_expr(ex, true, v); } } } - _ { visit::visit_item(it, false, v); } + _ => visit::visit_item(it, false, v) } } @@ -40,18 +40,18 @@ fn check_pat(p: @pat, &&_is_const: bool, v: visit::vt<bool>) { fn is_str(e: @expr) -> bool { alt e.node { expr_vstore(@{node: expr_lit(@{node: lit_str(_), _}), _}, - vstore_uniq) { true } - _ { false } + vstore_uniq) => true, + _ => false } } alt p.node { // Let through plain ~-string literals here - pat_lit(a) { if !is_str(a) { v.visit_expr(a, true, v); } } - pat_range(a, b) { + pat_lit(a) => if !is_str(a) { v.visit_expr(a, true, v); } + pat_range(a, b) => { if !is_str(a) { v.visit_expr(a, true, v); } if !is_str(b) { v.visit_expr(b, true, v); } } - _ { visit::visit_pat(p, false, v); } + _ => visit::visit_pat(p, false, v) } } @@ -61,20 +61,20 @@ fn check_expr(sess: session, def_map: resolve3::DefMap, if is_const { alt e.node { expr_unary(box(_), _) | expr_unary(uniq(_), _) | - expr_unary(deref, _){ + expr_unary(deref, _) => { sess.span_err(e.span, ~"disallowed operator in constant expression"); return; } - expr_lit(@{node: lit_str(_), _}) { } - expr_binary(_, _, _) | expr_unary(_, _) { + expr_lit(@{node: lit_str(_), _}) => { } + expr_binary(_, _, _) | expr_unary(_, _) => { if method_map.contains_key(e.id) { sess.span_err(e.span, ~"user-defined operators are not \ allowed in constant expressions"); } } - expr_lit(_) {} - expr_cast(_, _) { + expr_lit(_) => (), + expr_cast(_, _) => { let ety = ty::expr_ty(tcx, e); if !ty::type_is_numeric(ety) { sess.span_err(e.span, ~"can not cast to `" + @@ -82,16 +82,16 @@ fn check_expr(sess: session, def_map: resolve3::DefMap, ~"` in a constant expression"); } } - expr_path(_) { + expr_path(_) => { alt def_map.find(e.id) { - some(def_const(def_id)) { + some(def_const(def_id)) => { if !ast_util::is_local(def_id) { sess.span_err( e.span, ~"paths in constants may only refer to \ crate-local constants"); } } - _ { + _ => { sess.span_err( e.span, ~"paths in constants may only refer to constants"); @@ -103,14 +103,14 @@ fn check_expr(sess: session, def_map: resolve3::DefMap, expr_vec(_, m_imm) | expr_addr_of(m_imm, _) | expr_tup(*) | - expr_rec(*) { } - expr_addr_of(*) { + expr_rec(*) => { } + expr_addr_of(*) => { sess.span_err( e.span, ~"borrowed pointers in constants may only refer to \ immutable values"); } - _ { + _ => { sess.span_err(e.span, ~"constant contains unimplemented expression type"); return; @@ -118,7 +118,7 @@ fn check_expr(sess: session, def_map: resolve3::DefMap, } } alt e.node { - expr_lit(@{node: lit_int(v, t), _}) { + expr_lit(@{node: lit_int(v, t), _}) => { if t != ty_char { if (v as u64) > ast_util::int_ty_max( if t == ty_i { sess.targ_cfg.int_type } else { t }) { @@ -126,13 +126,13 @@ fn check_expr(sess: session, def_map: resolve3::DefMap, } } } - expr_lit(@{node: lit_uint(v, t), _}) { + expr_lit(@{node: lit_uint(v, t), _}) => { if v > ast_util::uint_ty_max( if t == ty_u { sess.targ_cfg.uint_type } else { t }) { sess.span_err(e.span, ~"literal out of range for its type"); } } - _ {} + _ => () } visit::visit_expr(e, is_const, v); } @@ -176,19 +176,19 @@ fn check_item_recursion(sess: session, ast_map: ast_map::map, fn visit_expr(e: @expr, &&env: env, v: visit::vt<env>) { alt e.node { - expr_path(path) { + expr_path(path) => { alt env.def_map.find(e.id) { - some(def_const(def_id)) { + some(def_const(def_id)) => { alt check env.ast_map.get(def_id.node) { - ast_map::node_item(it, _) { + ast_map::node_item(it, _) => { v.visit_item(it, env, v); } } } - _ { } + _ => () } } - _ { } + _ => () } visit::visit_expr(e, env, v); } diff --git a/src/rustc/middle/check_loop.rs b/src/rustc/middle/check_loop.rs index 69bb7220a4c..0ac3caa633b 100644 --- a/src/rustc/middle/check_loop.rs +++ b/src/rustc/middle/check_loop.rs @@ -11,40 +11,40 @@ fn check_crate(tcx: ty::ctxt, crate: @crate) { }, visit_expr: |e: @expr, cx: ctx, v: visit::vt<ctx>| { alt e.node { - expr_while(e, b) { + expr_while(e, b) => { v.visit_expr(e, cx, v); v.visit_block(b, {in_loop: true with cx}, v); } - expr_loop(b) { + expr_loop(b) => { v.visit_block(b, {in_loop: true with cx}, v); } - expr_fn(_, _, _, _) { + expr_fn(_, _, _, _) => { visit::visit_expr(e, {in_loop: false, can_ret: true}, v); } - expr_fn_block(_, b, _) { + expr_fn_block(_, b, _) => { v.visit_block(b, {in_loop: false, can_ret: false}, v); } - expr_loop_body(@{node: expr_fn_block(_, b, _), _}) { + expr_loop_body(@{node: expr_fn_block(_, b, _), _}) => { let blk = is_blockish(ty::ty_fn_proto(ty::expr_ty(tcx, e))); v.visit_block(b, {in_loop: true, can_ret: blk}, v); } - expr_break { + expr_break => { if !cx.in_loop { tcx.sess.span_err(e.span, ~"`break` outside of loop"); } } - expr_again { + expr_again => { if !cx.in_loop { tcx.sess.span_err(e.span, ~"`again` outside of loop"); } } - expr_ret(oe) { + expr_ret(oe) => { if !cx.can_ret { tcx.sess.span_err(e.span, ~"`ret` in block function"); } visit::visit_expr_opt(oe, cx, v); } - _ { visit::visit_expr(e, cx, v); } + _ => visit::visit_expr(e, cx, v) } } with *visit::default_visitor() diff --git a/src/rustc/middle/const_eval.rs b/src/rustc/middle/const_eval.rs index 50ec4e62175..66c19a14e6f 100644 --- a/src/rustc/middle/const_eval.rs +++ b/src/rustc/middle/const_eval.rs @@ -42,11 +42,11 @@ enum constness { fn join(a: constness, b: constness) -> constness { alt (a,b) { - (integral_const, integral_const) { integral_const } + (integral_const, integral_const) => integral_const, (integral_const, general_const) | (general_const, integral_const) - | (general_const, general_const) { general_const } - _ { non_const } + | (general_const, general_const) => general_const, + _ => non_const } } @@ -59,43 +59,43 @@ fn classify(e: @expr, tcx: ty::ctxt) -> constness { let did = ast_util::local_def(e.id); alt tcx.ccache.find(did) { - some(x) { x } - none { + some(x) => x, + none => { let cn = alt e.node { - ast::expr_lit(lit) { + ast::expr_lit(lit) => { alt lit.node { ast::lit_str(*) | - ast::lit_float(*) { general_const } - _ { integral_const } + ast::lit_float(*) => general_const, + _ => integral_const } } ast::expr_copy(inner) | - ast::expr_unary(_, inner) { + ast::expr_unary(_, inner) => { classify(inner, def_map, tcx) } - ast::expr_binary(_, a, b) { + ast::expr_binary(_, a, b) => { join(classify(a, def_map, tcx), classify(b, def_map, tcx)) } ast::expr_tup(es) | - ast::expr_vec(es, ast::m_imm) { + ast::expr_vec(es, ast::m_imm) => { join_all(vec::map(es, |e| classify(e, def_map, tcx))) } - ast::expr_vstore(e, vstore) { + ast::expr_vstore(e, vstore) => { alt vstore { ast::vstore_fixed(_) | - ast::vstore_slice(_) { classify(e, def_map, tcx) } + ast::vstore_slice(_) => classify(e, def_map, tcx), ast::vstore_uniq | - ast::vstore_box { non_const } + ast::vstore_box => non_const } } - ast::expr_rec(fs, none) { + ast::expr_rec(fs, none) => { let cs = do vec::map(fs) |f| { if f.node.mutbl == ast::m_imm { classify(f.node.expr, def_map, tcx) @@ -106,7 +106,7 @@ fn classify(e: @expr, join_all(cs) } - ast::expr_cast(base, _) { + ast::expr_cast(base, _) => { let ty = ty::expr_ty(tcx, e); let base = classify(base, def_map, tcx); if ty::type_is_integral(ty) { @@ -118,24 +118,24 @@ fn classify(e: @expr, } } - ast::expr_field(base, _, _) { + ast::expr_field(base, _, _) => { classify(base, def_map, tcx) } - ast::expr_index(base, idx) { + ast::expr_index(base, idx) => { join(classify(base, def_map, tcx), classify(idx, def_map, tcx)) } - ast::expr_addr_of(ast::m_imm, base) { + ast::expr_addr_of(ast::m_imm, base) => { classify(base, def_map, tcx) } // FIXME: #1272, we can probably do something CCI-ish // surrounding nonlocal constants. But we don't yet. - ast::expr_path(_) { + ast::expr_path(_) => { alt def_map.find(e.id) { - some(ast::def_const(def_id)) { + some(ast::def_const(def_id)) => { if ast_util::is_local(def_id) { let ty = ty::expr_ty(tcx, e); if ty::type_is_integral(ty) { @@ -147,10 +147,10 @@ fn classify(e: @expr, non_const } } - some(_) { + some(_) => { non_const } - none { + none => { tcx.sess.span_bug(e.span, ~"unknown path when \ classifying constants"); @@ -158,7 +158,7 @@ fn classify(e: @expr, } } - _ { non_const } + _ => non_const }; tcx.ccache.insert(did, cn); cn @@ -192,115 +192,139 @@ fn eval_const_expr(tcx: middle::ty::ctxt, e: @expr) -> const_val { import middle::ty; fn fromb(b: bool) -> const_val { const_int(b as i64) } alt check e.node { - expr_unary(neg, inner) { + expr_unary(neg, inner) => { alt check eval_const_expr(tcx, inner) { - const_float(f) { const_float(-f) } - const_int(i) { const_int(-i) } - const_uint(i) { const_uint(-i) } + const_float(f) => const_float(-f), + const_int(i) => const_int(-i), + const_uint(i) => const_uint(-i) } } - expr_unary(not, inner) { + expr_unary(not, inner) => { alt check eval_const_expr(tcx, inner) { - const_int(i) { const_int(!i) } - const_uint(i) { const_uint(!i) } + const_int(i) => const_int(!i), + const_uint(i) => const_uint(!i) } } - expr_binary(op, a, b) { + expr_binary(op, a, b) => { alt check (eval_const_expr(tcx, a), eval_const_expr(tcx, b)) { - (const_float(a), const_float(b)) { + (const_float(a), const_float(b)) => { alt check op { - add { const_float(a + b) } subtract { const_float(a - b) } - mul { const_float(a * b) } div { const_float(a / b) } - rem { const_float(a % b) } eq { fromb(a == b) } - lt { fromb(a < b) } le { fromb(a <= b) } ne { fromb(a != b) } - ge { fromb(a >= b) } gt { fromb(a > b) } + add => const_float(a + b), + subtract => const_float(a - b), + mul => const_float(a * b), + div => const_float(a / b), + rem => const_float(a % b), + eq => fromb(a == b), + lt => fromb(a < b), + le => fromb(a <= b), + ne => fromb(a != b), + ge => fromb(a >= b), + gt => fromb(a > b) } } - (const_int(a), const_int(b)) { + (const_int(a), const_int(b)) => { alt check op { - add { const_int(a + b) } subtract { const_int(a - b) } - mul { const_int(a * b) } div { const_int(a / b) } - rem { const_int(a % b) } and | bitand { const_int(a & b) } - or | bitor { const_int(a | b) } bitxor { const_int(a ^ b) } - shl { const_int(a << b) } shr { const_int(a >> b) } - eq { fromb(a == b) } lt { fromb(a < b) } - le { fromb(a <= b) } ne { fromb(a != b) } - ge { fromb(a >= b) } gt { fromb(a > b) } + add => const_int(a + b), + subtract => const_int(a - b), + mul => const_int(a * b), + div => const_int(a / b), + rem => const_int(a % b), + and | bitand => const_int(a & b), + or | bitor => const_int(a | b), + bitxor => const_int(a ^ b), + shl => const_int(a << b), + shr => const_int(a >> b), + eq => fromb(a == b), + lt => fromb(a < b), + le => fromb(a <= b), + ne => fromb(a != b), + ge => fromb(a >= b), + gt => fromb(a > b) } } - (const_uint(a), const_uint(b)) { + (const_uint(a), const_uint(b)) => { alt check op { - add { const_uint(a + b) } subtract { const_uint(a - b) } - mul { const_uint(a * b) } div { const_uint(a / b) } - rem { const_uint(a % b) } and | bitand { const_uint(a & b) } - or | bitor { const_uint(a | b) } bitxor { const_uint(a ^ b) } - shl { const_uint(a << b) } shr { const_uint(a >> b) } - eq { fromb(a == b) } lt { fromb(a < b) } - le { fromb(a <= b) } ne { fromb(a != b) } - ge { fromb(a >= b) } gt { fromb(a > b) } + add => const_uint(a + b), + subtract => const_uint(a - b), + mul => const_uint(a * b), + div => const_uint(a / b), + rem => const_uint(a % b), + and | bitand => const_uint(a & b), + or | bitor => const_uint(a | b), + bitxor => const_uint(a ^ b), + shl => const_uint(a << b), + shr => const_uint(a >> b), + eq => fromb(a == b), + lt => fromb(a < b), + le => fromb(a <= b), + ne => fromb(a != b), + ge => fromb(a >= b), + gt => fromb(a > b) } } // shifts can have any integral type as their rhs - (const_int(a), const_uint(b)) { + (const_int(a), const_uint(b)) => { alt check op { - shl { const_int(a << b) } shr { const_int(a >> b) } + shl => const_int(a << b), + shr => const_int(a >> b) } } - (const_uint(a), const_int(b)) { + (const_uint(a), const_int(b)) => { alt check op { - shl { const_uint(a << b) } shr { const_uint(a >> b) } + shl => const_uint(a << b), + shr => const_uint(a >> b) } } } } - expr_cast(base, _) { + expr_cast(base, _) => { let ety = ty::expr_ty(tcx, e); let base = eval_const_expr(tcx, base); alt check ty::get(ety).struct { - ty::ty_float(_) { + ty::ty_float(_) => { alt check base { - const_uint(u) { const_float(u as f64) } - const_int(i) { const_float(i as f64) } - const_float(_) { base } + const_uint(u) => const_float(u as f64), + const_int(i) => const_float(i as f64), + const_float(_) => base } } - ty::ty_uint(_) { + ty::ty_uint(_) => { alt check base { - const_uint(_) { base } - const_int(i) { const_uint(i as u64) } - const_float(f) { const_uint(f as u64) } + const_uint(_) => base, + const_int(i) => const_uint(i as u64), + const_float(f) => const_uint(f as u64) } } - ty::ty_int(_) | ty::ty_bool { + ty::ty_int(_) | ty::ty_bool => { alt check base { - const_uint(u) { const_int(u as i64) } - const_int(_) { base } - const_float(f) { const_int(f as i64) } + const_uint(u) => const_int(u as i64), + const_int(_) => base, + const_float(f) => const_int(f as i64) } } } } - expr_lit(lit) { lit_to_const(lit) } + expr_lit(lit) => lit_to_const(lit), // If we have a vstore, just keep going; it has to be a string - expr_vstore(e, _) { eval_const_expr(tcx, e) } + expr_vstore(e, _) => eval_const_expr(tcx, e) } } fn lit_to_const(lit: @lit) -> const_val { alt lit.node { - lit_str(s) { const_str(*s) } - lit_int(n, _) { const_int(n) } - lit_uint(n, _) { const_uint(n) } - lit_int_unsuffixed(n) { const_int(n) } - lit_float(n, _) { const_float(option::get(float::from_str(*n)) as f64) } - lit_nil { const_int(0i64) } - lit_bool(b) { const_int(b as i64) } + lit_str(s) => const_str(*s), + lit_int(n, _) => const_int(n), + lit_uint(n, _) => const_uint(n), + lit_int_unsuffixed(n) => const_int(n), + lit_float(n, _) => const_float(option::get(float::from_str(*n)) as f64), + lit_nil => const_int(0i64), + lit_bool(b) => const_int(b as i64) } } fn compare_const_vals(a: const_val, b: const_val) -> int { alt (a, b) { - (const_int(a), const_int(b)) { + (const_int(a), const_int(b)) => { if a == b { 0 } else if a < b { @@ -309,7 +333,7 @@ fn compare_const_vals(a: const_val, b: const_val) -> int { 1 } } - (const_uint(a), const_uint(b)) { + (const_uint(a), const_uint(b)) => { if a == b { 0 } else if a < b { @@ -318,7 +342,7 @@ fn compare_const_vals(a: const_val, b: const_val) -> int { 1 } } - (const_float(a), const_float(b)) { + (const_float(a), const_float(b)) => { if a == b { 0 } else if a < b { @@ -327,7 +351,7 @@ fn compare_const_vals(a: const_val, b: const_val) -> int { 1 } } - (const_str(a), const_str(b)) { + (const_str(a), const_str(b)) => { if a == b { 0 } else if a < b { @@ -336,9 +360,7 @@ fn compare_const_vals(a: const_val, b: const_val) -> int { 1 } } - _ { - fail ~"compare_const_vals: ill-typed comparison"; - } + _ => fail ~"compare_const_vals: ill-typed comparison" } } diff --git a/src/rustc/middle/freevars.rs b/src/rustc/middle/freevars.rs index 29d44ede215..7c8e807a085 100644 --- a/src/rustc/middle/freevars.rs +++ b/src/rustc/middle/freevars.rs @@ -39,24 +39,24 @@ fn collect_freevars(def_map: resolve3::DefMap, blk: ast::blk) let walk_expr = fn@(expr: @ast::expr, &&depth: int, v: visit::vt<int>) { alt expr.node { - ast::expr_fn(proto, decl, _, _) { + ast::expr_fn(proto, decl, _, _) => { if proto != ast::proto_bare { visit::visit_expr(expr, depth + 1, v); } } - ast::expr_fn_block(_, _, _) { + ast::expr_fn_block(_, _, _) => { visit::visit_expr(expr, depth + 1, v); } - ast::expr_path(path) { + ast::expr_path(path) => { let mut i = 0; alt def_map.find(expr.id) { - none { fail (~"Not found: " + path_to_str(path)) } - some(df) { + none => fail (~"Not found: " + path_to_str(path)), + some(df) => { let mut def = df; while i < depth { alt copy def { - ast::def_upvar(_, inner, _) { def = *inner; } - _ { break; } + ast::def_upvar(_, inner, _) => { def = *inner; } + _ => break } i += 1; } @@ -70,7 +70,7 @@ fn collect_freevars(def_map: resolve3::DefMap, blk: ast::blk) } } } - _ { visit::visit_expr(expr, depth, v); } + _ => visit::visit_expr(expr, depth, v) } }; @@ -105,8 +105,8 @@ fn annotate_freevars(def_map: resolve3::DefMap, crate: @ast::crate) -> fn get_freevars(tcx: ty::ctxt, fid: ast::node_id) -> freevar_info { alt tcx.freevars.find(fid) { - none { fail ~"get_freevars: " + int::str(fid) + ~" has no freevars"; } - some(d) { return d; } + none => fail ~"get_freevars: " + int::str(fid) + ~" has no freevars", + some(d) => return d } } fn has_freevars(tcx: ty::ctxt, fid: ast::node_id) -> bool { diff --git a/src/rustc/middle/kind.rs b/src/rustc/middle/kind.rs index 263af391a93..e855e23b12b 100644 --- a/src/rustc/middle/kind.rs +++ b/src/rustc/middle/kind.rs @@ -145,10 +145,10 @@ fn with_appropriate_checker(cx: ctx, id: node_id, b: fn(check_fn)) { let fty = ty::node_id_to_type(cx.tcx, id); alt ty::ty_fn_proto(fty) { - proto_uniq { b(check_for_uniq) } - proto_box { b(check_for_box) } - proto_bare { b(check_for_bare) } - proto_block { b(check_for_block) } + proto_uniq => b(check_for_uniq), + proto_box => b(check_for_box), + proto_bare => b(check_for_bare), + proto_block => b(check_for_block) } } @@ -167,9 +167,9 @@ fn check_fn(fk: visit::fn_kind, decl: fn_decl, body: blk, sp: span, // variables. This list is used below to avoid checking and reporting // on a given variable twice. let cap_clause = alt fk { - visit::fk_anon(_, cc) | visit::fk_fn_block(cc) { cc } + visit::fk_anon(_, cc) | visit::fk_fn_block(cc) => cc, visit::fk_item_fn(*) | visit::fk_method(*) | - visit::fk_ctor(*) | visit::fk_dtor(*) { @~[] } + visit::fk_ctor(*) | visit::fk_dtor(*) => @~[] }; let captured_vars = do (*cap_clause).map |cap_item| { let cap_def = cx.tcx.def_map.get(cap_item.id); @@ -191,8 +191,8 @@ fn check_fn(fk: visit::fn_kind, decl: fn_decl, body: blk, sp: span, // a move and not a copy let is_move = { alt check cx.last_use_map.find(fn_id) { - some(vars) {(*vars).contains(id)} - none {false} + some(vars) => (*vars).contains(id), + none => false } }; @@ -206,8 +206,8 @@ fn check_fn(fk: visit::fn_kind, decl: fn_decl, body: blk, sp: span, fn check_block(b: blk, cx: ctx, v: visit::vt<ctx>) { alt b.node.expr { - some(ex) { maybe_copy(cx, ex); } - _ {} + some(ex) => maybe_copy(cx, ex), + _ => () } visit::visit_block(b, cx, v); } @@ -217,29 +217,29 @@ fn check_expr(e: @expr, cx: ctx, v: visit::vt<ctx>) { alt e.node { expr_assign(_, ex) | expr_unary(box(_), ex) | expr_unary(uniq(_), ex) | - expr_ret(some(ex)) { + expr_ret(some(ex)) => { maybe_copy(cx, ex); } - expr_cast(source, _) { + expr_cast(source, _) => { maybe_copy(cx, source); check_cast_for_escaping_regions(cx, source, e); } - expr_copy(expr) { check_copy_ex(cx, expr, false); } + expr_copy(expr) => check_copy_ex(cx, expr, false), // Vector add copies, but not "implicitly" - expr_assign_op(_, _, ex) { check_copy_ex(cx, ex, false) } - expr_binary(add, ls, rs) { + expr_assign_op(_, _, ex) => check_copy_ex(cx, ex, false), + expr_binary(add, ls, rs) => { check_copy_ex(cx, ls, false); check_copy_ex(cx, rs, false); } - expr_rec(fields, def) { + expr_rec(fields, def) => { for fields.each |field| { maybe_copy(cx, field.node.expr); } alt def { - some(ex) { + some(ex) => { // All noncopyable fields must be overridden let t = ty::expr_ty(cx.tcx, ex); let ty_fields = alt ty::get(t).struct { - ty::ty_rec(f) { f } - _ { cx.tcx.sess.span_bug(ex.span, ~"bad expr type in record"); } + ty::ty_rec(f) => f, + _ => cx.tcx.sess.span_bug(ex.span, ~"bad expr type in record") }; for ty_fields.each |tf| { if !vec::any(fields, |f| f.node.ident == tf.ident ) && @@ -249,32 +249,32 @@ fn check_expr(e: @expr, cx: ctx, v: visit::vt<ctx>) { } } } - _ {} + _ => {} } } - expr_tup(exprs) | expr_vec(exprs, _) { + expr_tup(exprs) | expr_vec(exprs, _) => { for exprs.each |expr| { maybe_copy(cx, expr); } } - expr_call(f, args, _) { + expr_call(f, args, _) => { let mut i = 0u; for ty::ty_fn_args(ty::expr_ty(cx.tcx, f)).each |arg_t| { alt ty::arg_mode(cx.tcx, arg_t) { - by_copy { maybe_copy(cx, args[i]); } - by_ref | by_val | by_mutbl_ref | by_move { } + by_copy => maybe_copy(cx, args[i]), + by_ref | by_val | by_mutbl_ref | by_move => () } i += 1u; } } - expr_path(_) | expr_field(_, _, _) { + expr_path(_) | expr_field(_, _, _) => { do option::iter(cx.tcx.node_type_substs.find(e.id)) |ts| { let bounds = alt check e.node { - expr_path(_) { + expr_path(_) => { let did = ast_util::def_id_of_def(cx.tcx.def_map.get(e.id)); ty::lookup_item_type(cx.tcx, did).bounds } - expr_field(base, _, _) { + expr_field(base, _, _) => { alt cx.method_map.get(e.id).origin { - typeck::method_static(did) { + typeck::method_static(did) => { // n.b.: When we encode class/impl methods, the bounds // that we encode include both the class/impl bounds // and then the method bounds themselves... @@ -282,7 +282,7 @@ fn check_expr(e: @expr, cx: ctx, v: visit::vt<ctx>) { } typeck::method_param({trait_id:trt_id, method_num:n_mth, _}) | - typeck::method_trait(trt_id, n_mth) { + typeck::method_trait(trt_id, n_mth) => { // ...trait methods bounds, in contrast, include only the // method bounds, so we must preprend the tps from the // trait itself. This ought to be harmonized. @@ -306,29 +306,29 @@ fn check_expr(e: @expr, cx: ctx, v: visit::vt<ctx>) { } } } - _ { } + _ => { } } visit::visit_expr(e, cx, v); } fn check_stmt(stmt: @stmt, cx: ctx, v: visit::vt<ctx>) { alt stmt.node { - stmt_decl(@{node: decl_local(locals), _}, _) { + stmt_decl(@{node: decl_local(locals), _}, _) => { for locals.each |local| { alt local.node.init { - some({op: init_assign, expr}) { maybe_copy(cx, expr); } - _ {} + some({op: init_assign, expr}) => maybe_copy(cx, expr), + _ => {} } } } - _ {} + _ => {} } visit::visit_stmt(stmt, cx, v); } fn check_ty(aty: @ty, cx: ctx, v: visit::vt<ctx>) { alt aty.node { - ty_path(_, id) { + ty_path(_, id) => { do option::iter(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; @@ -337,7 +337,7 @@ fn check_ty(aty: @ty, cx: ctx, v: visit::vt<ctx>) { } } } - _ {} + _ => {} } visit::visit_ty(aty, cx, v); } @@ -374,15 +374,15 @@ fn maybe_copy(cx: ctx, ex: @expr) { fn is_nullary_variant(cx: ctx, ex: @expr) -> bool { alt ex.node { - expr_path(_) { + expr_path(_) => { alt cx.tcx.def_map.get(ex.id) { - def_variant(edid, vdid) { + def_variant(edid, vdid) => { vec::len(ty::enum_variant_with_id(cx.tcx, edid, vdid).args) == 0u } - _ { false } + _ => false } } - _ { false } + _ => false } } @@ -399,24 +399,24 @@ fn check_imm_free_var(cx: ctx, def: def, sp: span) { let msg = ~"mutable variables cannot be implicitly captured; \ use a capture clause"; alt def { - def_local(_, is_mutbl) { + def_local(_, is_mutbl) => { if is_mutbl { cx.tcx.sess.span_err(sp, msg); } } - def_arg(_, mode) { + def_arg(_, mode) => { alt ty::resolved_mode(cx.tcx, mode) { - by_ref | by_val | by_move | by_copy { /* ok */ } - by_mutbl_ref { + by_ref | by_val | by_move | by_copy => { /* ok */ } + by_mutbl_ref => { cx.tcx.sess.span_err(sp, msg); } } } - def_upvar(_, def1, _) { + def_upvar(_, def1, _) => { check_imm_free_var(cx, *def1, sp); } - def_binding(*) | def_self(*) { /*ok*/ } - _ { + def_binding(*) | def_self(*) => { /*ok*/ } + _ => { cx.tcx.sess.span_bug( sp, fmt!{"unknown def for free variable: %?", def}); @@ -450,11 +450,11 @@ fn check_send(cx: ctx, ty: ty::t, sp: span) -> bool { fn check_owned(tcx: ty::ctxt, ty: ty::t, sp: span) -> bool { if !ty::kind_is_owned(ty::type_kind(tcx, ty)) { alt ty::get(ty).struct { - ty::ty_param(*) { + ty::ty_param(*) => { tcx.sess.span_err(sp, ~"value may contain borrowed \ pointers; use `owned` bound"); } - _ { + _ => { tcx.sess.span_err(sp, ~"value may contain borrowed \ pointers"); } diff --git a/src/rustc/middle/lang_items.rs b/src/rustc/middle/lang_items.rs index c3508319375..5abc64a3b0d 100644 --- a/src/rustc/middle/lang_items.rs +++ b/src/rustc/middle/lang_items.rs @@ -111,7 +111,7 @@ class LanguageItemCollector { } } } - meta_word(*) | meta_list(*) { + meta_word(*) | meta_list(*) => { // Skip. } } @@ -172,7 +172,7 @@ class LanguageItemCollector { dl_def(def_ty(did)) => { def_id = did; } - dl_def(_) | dl_impl(_) | dl_field { + dl_def(_) | dl_impl(_) | dl_field => { // Skip this. again; } diff --git a/src/rustc/middle/lint.rs b/src/rustc/middle/lint.rs index ca39157f3bf..61299171eae 100644 --- a/src/rustc/middle/lint.rs +++ b/src/rustc/middle/lint.rs @@ -56,25 +56,25 @@ enum lint { // type of thing. fn int_to_lint(i: int) -> lint { alt check i { - 0 { ctypes } - 1 { unused_imports } - 2 { while_true } - 3 { path_statement } - 4 { implicit_copies } - 5 { unrecognized_lint } - 6 { non_implicitly_copyable_typarams } - 7 { vecs_implicitly_copyable } - 8 { deprecated_mode } - 9 { non_camel_case_types } + 0 => ctypes, + 1 => unused_imports, + 2 => while_true, + 3 => path_statement, + 4 => implicit_copies, + 5 => unrecognized_lint, + 6 => non_implicitly_copyable_typarams, + 7 => vecs_implicitly_copyable, + 8 => deprecated_mode, + 9 => non_camel_case_types } } fn level_to_str(lv: level) -> ~str { alt lv { - allow { ~"allow" } - warn { ~"warn" } - deny { ~"deny" } - forbid { ~"forbid" } + allow => ~"allow", + warn => ~"warn", + deny => ~"deny", + forbid => ~"forbid" } } @@ -167,8 +167,8 @@ fn mk_lint_settings() -> lint_settings { fn get_lint_level(modes: lint_modes, lint: lint) -> level { alt modes.find(lint as uint) { - some(c) { c } - none { allow } + some(c) => c, + none => allow } } @@ -177,8 +177,8 @@ fn get_lint_settings_level(settings: lint_settings, _expr_id: ast::node_id, item_id: ast::node_id) -> level { alt settings.settings_map.find(item_id) { - some(modes) { get_lint_level(modes, lint_mode) } - none { get_lint_level(settings.default_settings, lint_mode) } + some(modes) => get_lint_level(modes, lint_mode), + none => get_lint_level(settings.default_settings, lint_mode) } } @@ -231,13 +231,13 @@ impl methods for ctxt { level_name)); for metas.each |meta| { alt meta.node { - ast::meta_list(_, metas) { + ast::meta_list(_, metas) => { for metas.each |meta| { alt meta.node { - ast::meta_word(lintname) { + ast::meta_word(lintname) => { vec::push(triples, (meta, level, lintname)); } - _ { + _ => { self.sess.span_err( meta.span, ~"malformed lint attribute"); @@ -245,7 +245,7 @@ impl methods for ctxt { } } } - _ { + _ => { self.sess.span_err(meta.span, ~"malformed lint attribute"); } @@ -256,14 +256,14 @@ impl methods for ctxt { for triples.each |pair| { let (meta, level, lintname) = pair; alt self.dict.find(*lintname) { - none { + none => { self.span_lint( new_ctxt.get_level(unrecognized_lint), meta.span, fmt!{"unknown `%s` attribute: `%s`", level_to_str(level), *lintname}); } - some(lint) { + some(lint) => { if new_ctxt.get_level(lint.lint) == forbid && level != forbid { @@ -355,18 +355,18 @@ fn check_item_while_true(cx: ty::ctxt, it: @ast::item) { let visit = item_stopping_visitor(visit::mk_simple_visitor(@{ visit_expr: fn@(e: @ast::expr) { alt e.node { - ast::expr_while(cond, _) { + ast::expr_while(cond, _) => { alt cond.node { - ast::expr_lit(@{node: ast::lit_bool(true),_}) { + ast::expr_lit(@{node: ast::lit_bool(true),_}) => { cx.sess.span_lint( while_true, e.id, it.id, e.span, ~"denote infinite loops with loop { ... }"); } - _ {} + _ => () } } - _ {} + _ => () } } with *visit::default_simple_visitor() @@ -381,42 +381,42 @@ fn check_item_ctypes(cx: ty::ctxt, it: @ast::item) { let tys = vec::map(decl.inputs, |a| a.ty ); for vec::each(vec::append_one(tys, decl.output)) |ty| { alt ty.node { - ast::ty_path(_, id) { + ast::ty_path(_, id) => { alt cx.def_map.get(id) { - ast::def_prim_ty(ast::ty_int(ast::ty_i)) { + ast::def_prim_ty(ast::ty_int(ast::ty_i)) => { cx.sess.span_lint( ctypes, id, fn_id, ty.span, ~"found rust type `int` in foreign module, while \ libc::c_int or libc::c_long should be used"); } - ast::def_prim_ty(ast::ty_uint(ast::ty_u)) { + ast::def_prim_ty(ast::ty_uint(ast::ty_u)) => { cx.sess.span_lint( ctypes, id, fn_id, ty.span, ~"found rust type `uint` in foreign module, while \ libc::c_uint or libc::c_ulong should be used"); } - _ { } + _ => () } } - _ { } + _ => () } } } alt it.node { ast::item_foreign_mod(nmod) if attr::foreign_abi(it.attrs) != - either::right(ast::foreign_abi_rust_intrinsic) { + either::right(ast::foreign_abi_rust_intrinsic) => { for nmod.items.each |ni| { alt ni.node { - ast::foreign_item_fn(decl, tps) { + ast::foreign_item_fn(decl, tps) => { check_foreign_fn(cx, it.id, decl); } } } } - _ {/* nothing to do */ } + _ => {/* nothing to do */ } } } @@ -427,13 +427,13 @@ fn check_item_path_statement(cx: ty::ctxt, it: @ast::item) { ast::stmt_semi(@{id: id, callee_id: _, node: ast::expr_path(@path), - span: _}, _) { + span: _}, _) => { cx.sess.span_lint( path_statement, id, it.id, s.span, ~"path statement with no effect"); } - _ {} + _ => () } } with *visit::default_simple_visitor() @@ -460,17 +460,17 @@ fn check_item_non_camel_case_types(cx: ty::ctxt, it: @ast::item) { alt it.node { ast::item_ty(*) | ast::item_class(*) | - ast::item_trait(*) | ast::item_impl(*) { + ast::item_trait(*) | ast::item_impl(*) => { check_case(cx, it.ident, it.id, it.id, it.span) } - ast::item_enum(variants, _) { + ast::item_enum(variants, _) => { check_case(cx, it.ident, it.id, it.id, it.span); for variants.each |variant| { check_case(cx, variant.node.name, variant.node.id, it.id, variant.span); } } - _ { } + _ => () } } @@ -487,7 +487,7 @@ fn check_fn(tcx: ty::ctxt, fk: visit::fn_kind, decl: ast::fn_decl, let fn_ty = ty::node_id_to_type(tcx, id); alt check ty::get(fn_ty).struct { - ty::ty_fn(fn_ty) { + ty::ty_fn(fn_ty) => { let mut counter = 0; do vec::iter2(fn_ty.inputs, decl.inputs) |arg_ty, arg_ast| { counter += 1; @@ -507,7 +507,7 @@ fn check_fn(tcx: ty::ctxt, fk: visit::fn_kind, decl: ast::fn_decl, fmt!{"argument %d uses an explicit mode", counter}); } - ast::infer(_) { + ast::infer(_) => { let kind = ty::type_kind(tcx, arg_ty.ty); if !ty::kind_is_safe_for_default_mode(kind) { tcx.sess.span_lint( diff --git a/src/rustc/middle/liveness.rs b/src/rustc/middle/liveness.rs index b6be4663a94..fe343d76cc9 100644 --- a/src/rustc/middle/liveness.rs +++ b/src/rustc/middle/liveness.rs @@ -202,9 +202,9 @@ enum var_kind { fn relevant_def(def: def) -> option<relevant_def> { alt def { - def_self(_) {some(rdef_self)} - def_arg(nid, _) | def_local(nid, _) {some(rdef_var(nid))} - _ {none} + def_self(_) => some(rdef_self), + def_arg(nid, _) | def_local(nid, _) => some(rdef_var(nid)), + _ => none } } @@ -261,13 +261,13 @@ class ir_maps { self.num_vars += 1u; alt vk { - vk_local(node_id, _) | vk_arg(node_id, _, _) { + vk_local(node_id, _) | vk_arg(node_id, _, _) => { self.variable_map.insert(node_id, v); } - vk_field(name) { + vk_field(name) => { self.field_map.insert(name, v); } - vk_self | vk_implicit_ret { + vk_self | vk_implicit_ret => { } } @@ -278,8 +278,8 @@ class ir_maps { fn variable(node_id: node_id, span: span) -> variable { alt self.variable_map.find(node_id) { - some(var) {var} - none { + some(var) => var, + none => { self.tcx.sess.span_bug( span, fmt!{"No variable registered for id %d", node_id}); } @@ -288,10 +288,10 @@ class ir_maps { fn variable_name(var: variable) -> ident { alt self.var_kinds[*var] { - vk_local(_, name) | vk_arg(_, name, _) {name} - vk_field(name) {@(~"self." + *name)} - vk_self {@~"self"} - vk_implicit_return {@~"<implicit-ret>"} + vk_local(_, name) | vk_arg(_, name, _) => name, + vk_field(name) => @(~"self." + *name), + vk_self => @~"self", + vk_implicit_return => @~"<implicit-ret>" } } @@ -301,8 +301,8 @@ class ir_maps { fn captures(expr: @expr) -> @~[capture_info] { alt self.capture_map.find(expr.id) { - some(caps) {caps} - none { + some(caps) => caps, + none => { self.tcx.sess.span_bug(expr.span, ~"no registered caps"); } } @@ -318,10 +318,10 @@ class ir_maps { alt vk { vk_arg(id, name, by_move) | vk_arg(id, name, by_copy) | - vk_local(id, name) { + vk_local(id, name) => { let v = alt self.last_use_map.find(expr_id) { - some(v) { v } - none { + some(v) => v, + none => { let v = @dvec(); self.last_use_map.insert(expr_id, v); v @@ -331,7 +331,7 @@ class ir_maps { (*v).push(id); } vk_arg(_, _, by_ref) | vk_arg(_, _, by_mutbl_ref) | - vk_arg(_, _, by_val) | vk_self | vk_field(_) | vk_implicit_ret { + vk_arg(_, _, by_val) | vk_self | vk_field(_) | vk_implicit_ret => { debug!{"--but it is not owned"}; } } @@ -360,10 +360,10 @@ fn visit_fn(fk: visit::fn_kind, decl: fn_decl, body: blk, visit::visit_fn(fk, decl, body, sp, id, fn_maps, v); alt fk { - visit::fk_ctor(_, _, _, _, class_did) { + visit::fk_ctor(_, _, _, _, class_did) => { add_class_fields(fn_maps, class_did); } - _ {} + _ => {} } // Special nodes and variables: @@ -416,7 +416,7 @@ fn visit_local(local: @local, &&self: @ir_maps, vt: vt<@ir_maps>) { fn visit_expr(expr: @expr, &&self: @ir_maps, vt: vt<@ir_maps>) { alt expr.node { // live nodes required for uses or definitions of variables: - expr_path(_) { + expr_path(_) => { let def = self.tcx.def_map.get(expr.id); debug!{"expr %d: path that leads to %?", expr.id, def}; if relevant_def(def).is_some() { @@ -425,7 +425,7 @@ fn visit_expr(expr: @expr, &&self: @ir_maps, vt: vt<@ir_maps>) { visit::visit_expr(expr, self, vt); } expr_fn(_, _, _, cap_clause) | - expr_fn_block(_, _, cap_clause) { + expr_fn_block(_, _, cap_clause) => { // Make a live_node for each captured variable, with the span // being the location that the variable is used. This results // in better error messages than just pointing at the closure @@ -436,15 +436,15 @@ fn visit_expr(expr: @expr, &&self: @ir_maps, vt: vt<@ir_maps>) { let mut call_caps = ~[]; for cvs.each |cv| { alt relevant_def(cv.def) { - some(rv) { + some(rv) => { let cv_ln = (*self).add_live_node(lnk_freevar(cv.span)); let is_move = alt cv.mode { - cap_move | cap_drop {true} // var must be dead afterwards - cap_copy | cap_ref {false} // var can still be used + cap_move | cap_drop => true, // var must be dead afterwards + cap_copy | cap_ref => false // var can still be used }; vec::push(call_caps, {ln: cv_ln, is_move: is_move, rv: rv}); } - none {} + none => {} } } (*self).set_captures(expr.id, call_caps); @@ -453,11 +453,11 @@ fn visit_expr(expr: @expr, &&self: @ir_maps, vt: vt<@ir_maps>) { } // live nodes required for interesting control flow: - expr_if(*) | expr_alt(*) | expr_while(*) | expr_loop(*) { + expr_if(*) | expr_alt(*) | expr_while(*) | expr_loop(*) => { (*self).add_live_node_for_node(expr.id, lnk_expr(expr.span)); visit::visit_expr(expr, self, vt); } - expr_binary(op, _, _) if ast_util::lazy_binop(op) { + expr_binary(op, _, _) if ast_util::lazy_binop(op) => { (*self).add_live_node_for_node(expr.id, lnk_expr(expr.span)); visit::visit_expr(expr, self, vt); } @@ -534,8 +534,8 @@ class liveness { fn live_node(node_id: node_id, span: span) -> live_node { alt self.ir.live_node_map.find(node_id) { - some(ln) {ln} - none { + some(ln) => ln, + none => { // This must be a mismatch between the ir_map construction // above and the propagation code below; the two sets of // code have to agree about which AST nodes are worth @@ -549,20 +549,20 @@ class liveness { fn variable_from_rdef(rv: relevant_def, span: span) -> variable { alt rv { - rdef_self {self.s.self_var} - rdef_var(nid) {self.variable(nid, span)} + rdef_self => self.s.self_var, + rdef_var(nid) => self.variable(nid, span) } } fn variable_from_path(expr: @expr) -> option<variable> { alt expr.node { - expr_path(_) { + expr_path(_) => { let def = self.tcx.def_map.get(expr.id); relevant_def(def).map( |rdef| self.variable_from_rdef(rdef, expr.span) ) } - _ {none} + _ => none } } @@ -573,12 +573,12 @@ class liveness { fn variable_from_def_map(node_id: node_id, span: span) -> option<variable> { alt self.tcx.def_map.find(node_id) { - some(def) { + some(def) => { relevant_def(def).map( |rdef| self.variable_from_rdef(rdef, span) ) } - none { + none => { self.tcx.sess.span_bug( span, ~"Not present in def map") } @@ -795,7 +795,7 @@ class liveness { // inputs passed by & mode should be considered live on exit: for decl.inputs.each |arg| { alt ty::resolved_mode(self.tcx, arg.mode) { - by_mutbl_ref | by_ref | by_val { + by_mutbl_ref | by_ref | by_val => { // These are "non-owned" modes, so register a read at // the end. This will prevent us from moving out of // such variables but also prevent us from registering @@ -803,7 +803,7 @@ class liveness { let var = self.variable(arg.id, blk.span); self.acc(self.s.exit_ln, var, ACC_READ); } - by_move | by_copy { + by_move | by_copy => { // These are owned modes. If we don't use the // variable, nobody will. } @@ -837,11 +837,11 @@ class liveness { fn propagate_through_stmt(stmt: @stmt, succ: live_node) -> live_node { alt stmt.node { - stmt_decl(decl, _) { + stmt_decl(decl, _) => { return self.propagate_through_decl(decl, succ); } - stmt_expr(expr, _) | stmt_semi(expr, _) { + stmt_expr(expr, _) | stmt_semi(expr, _) => { return self.propagate_through_expr(expr, succ); } } @@ -849,12 +849,12 @@ class liveness { fn propagate_through_decl(decl: @decl, succ: live_node) -> live_node { alt decl.node { - decl_local(locals) { + decl_local(locals) => { do locals.foldr(succ) |local, succ| { self.propagate_through_local(local, succ) } } - decl_item(_) { + decl_item(_) => { succ } } @@ -903,28 +903,28 @@ class liveness { alt expr.node { // Interesting cases with control flow or which gen/kill - expr_path(_) { + expr_path(_) => { self.access_path(expr, succ, ACC_READ | ACC_USE) } - expr_field(e, nm, _) { + expr_field(e, nm, _) => { // If this is a reference to `self.f` inside of a ctor, // then we treat it as a read of that variable. // Otherwise, we ignore it and just propagate down to // process `e`. alt self.as_self_field(e, nm) { - some((ln, var)) { + some((ln, var)) => { self.init_from_succ(ln, succ); self.acc(ln, var, ACC_READ | ACC_USE); ln } - none { + none => { self.propagate_through_expr(e, succ) } } } - expr_fn(*) | expr_fn_block(*) { + expr_fn(*) | expr_fn_block(*) => { // the construction of a closure itself is not important, // but we have to consider the closed over variables. let caps = (*self.ir).captures(expr); @@ -936,7 +936,7 @@ class liveness { } } - expr_if(cond, then, els) { + expr_if(cond, then, els) => { // // (cond) // | @@ -958,15 +958,15 @@ class liveness { self.propagate_through_expr(cond, ln) } - expr_while(cond, blk) { + expr_while(cond, blk) => { self.propagate_through_loop(expr, some(cond), blk, succ) } - expr_loop(blk) { + expr_loop(blk) => { self.propagate_through_loop(expr, none, blk, succ) } - expr_alt(e, arms, _) { + expr_alt(e, arms, _) => { // // (e) // | @@ -995,11 +995,12 @@ class liveness { self.propagate_through_expr(e, ln) } - expr_ret(o_e) | expr_fail(o_e) { // ignore succ and subst exit_ln: + expr_ret(o_e) | expr_fail(o_e) => { + // ignore succ and subst exit_ln: self.propagate_through_opt_expr(o_e, self.s.exit_ln) } - expr_break { + expr_break => { if !self.break_ln.is_valid() { self.tcx.sess.span_bug( expr.span, ~"break with invalid break_ln"); @@ -1008,7 +1009,7 @@ class liveness { self.break_ln } - expr_again { + expr_again => { if !self.cont_ln.is_valid() { self.tcx.sess.span_bug( expr.span, ~"cont with invalid cont_ln"); @@ -1017,7 +1018,7 @@ class liveness { self.cont_ln } - expr_move(l, r) | expr_assign(l, r) { + expr_move(l, r) | expr_assign(l, r) => { // see comment on lvalues in // propagate_through_lvalue_components() let succ = self.write_lvalue(l, succ, ACC_WRITE); @@ -1025,7 +1026,7 @@ class liveness { self.propagate_through_expr(r, succ) } - expr_swap(l, r) { + expr_swap(l, r) => { // see comment on lvalues in // propagate_through_lvalue_components() @@ -1040,7 +1041,7 @@ class liveness { self.propagate_through_lvalue_components(l, succ) } - expr_assign_op(_, l, r) { + expr_assign_op(_, l, r) => { // see comment on lvalues in // propagate_through_lvalue_components() let succ = self.write_lvalue(l, succ, ACC_WRITE|ACC_READ); @@ -1050,11 +1051,11 @@ class liveness { // Uninteresting cases: just propagate in rev exec order - expr_vstore(expr, _) { + expr_vstore(expr, _) => { self.propagate_through_expr(expr, succ) } - expr_vec(exprs, _) { + expr_vec(exprs, _) => { self.propagate_through_exprs(exprs, succ) } @@ -1063,20 +1064,20 @@ class liveness { self.propagate_through_expr(element, succ) } - expr_rec(fields, with_expr) { + expr_rec(fields, with_expr) => { let succ = self.propagate_through_opt_expr(with_expr, succ); do fields.foldr(succ) |field, succ| { self.propagate_through_expr(field.node.expr, succ) } } - expr_struct(_, fields) { + expr_struct(_, fields) => { do fields.foldr(succ) |field, succ| { self.propagate_through_expr(field.node.expr, succ) } } - expr_call(f, args, _) { + expr_call(f, args, _) => { // calling a fn with bot return type means that the fn // will fail, and hence the successors can be ignored let t_ret = ty::ty_fn_ret(ty::expr_ty(self.tcx, f)); @@ -1086,11 +1087,11 @@ class liveness { self.propagate_through_expr(f, succ) } - expr_tup(exprs) { + expr_tup(exprs) => { self.propagate_through_exprs(exprs, succ) } - expr_binary(op, l, r) if ast_util::lazy_binop(op) { + expr_binary(op, l, r) if ast_util::lazy_binop(op) => { let r_succ = self.propagate_through_expr(r, succ); let ln = self.live_node(expr.id, expr.span); @@ -1102,7 +1103,7 @@ class liveness { expr_log(_, l, r) | expr_index(l, r) | - expr_binary(_, l, r) { + expr_binary(_, l, r) => { self.propagate_through_exprs(~[l, r], succ) } @@ -1113,19 +1114,19 @@ class liveness { expr_loop_body(e) | expr_do_body(e) | expr_cast(e, _) | - expr_unary(_, e) { + expr_unary(_, e) => { self.propagate_through_expr(e, succ) } - expr_lit(*) { + expr_lit(*) => { succ } - expr_block(blk) { + expr_block(blk) => { self.propagate_through_block(blk, succ) } - expr_mac(*) { + expr_mac(*) => { self.tcx.sess.span_bug(expr.span, ~"unexpanded macro"); } } @@ -1184,20 +1185,12 @@ class liveness { // just ignore such cases and treat them as reads. alt expr.node { - expr_path(_) { - succ - } - - expr_field(e, nm, _) { - alt self.as_self_field(e, nm) { - some(_) {succ} - none {self.propagate_through_expr(e, succ)} - } - } - - _ { - self.propagate_through_expr(expr, succ) + expr_path(_) => succ, + expr_field(e, nm, _) => alt self.as_self_field(e, nm) { + some(_) => succ, + none => self.propagate_through_expr(e, succ) } + _ => self.propagate_through_expr(expr, succ) } } @@ -1206,35 +1199,28 @@ class liveness { succ: live_node, acc: uint) -> live_node { alt expr.node { - expr_path(_) { - self.access_path(expr, succ, acc) - } - - expr_field(e, nm, _) { - alt self.as_self_field(e, nm) { - some((ln, var)) { + expr_path(_) => self.access_path(expr, succ, acc), + expr_field(e, nm, _) => alt self.as_self_field(e, nm) { + some((ln, var)) => { self.init_from_succ(ln, succ); self.acc(ln, var, acc); ln - } - none { - succ - } } + none => succ } // We do not track other lvalues, so just propagate through // to their subcomponents. Also, it may happen that // non-lvalues occur here, because those are detected in the // later pass borrowck. - _ {succ} + _ => succ } } fn access_path(expr: @expr, succ: live_node, acc: uint) -> live_node { let def = self.tcx.def_map.get(expr.id); alt relevant_def(def) { - some(rdef_self) { + some(rdef_self) => { // Accessing `self` is like accessing every field of // the current object. This allows something like // `self = ...;` (it will be considered a write to @@ -1254,7 +1240,7 @@ class liveness { } ln } - some(rdef_var(nid)) { + some(rdef_var(nid)) => { let ln = self.live_node(expr.id, expr.span); if acc != 0u { self.init_from_succ(ln, succ); @@ -1263,9 +1249,7 @@ class liveness { } ln } - none { - succ - } + none => succ } } @@ -1275,20 +1259,20 @@ class liveness { // variable. we use the live_node id that will be assigned to // the reference to self but the variable id for `f`. alt expr.node { - expr_path(_) { + expr_path(_) => { let def = self.tcx.def_map.get(expr.id); alt def { - def_self(_) { + def_self(_) => { // Note: the field_map is empty unless we are in a ctor return self.ir.field_map.find(fld).map(|var| { let ln = self.live_node(expr.id, expr.span); (ln, var) }); } - _ { return none; } + _ => return none } } - _ { return none; } + _ => return none } } @@ -1361,20 +1345,20 @@ class liveness { fn check_local(local: @local, &&self: @liveness, vt: vt<@liveness>) { alt local.node.init { - some({op: op, expr: expr}) { + some({op: op, expr: expr}) => { // Initializer: alt op { - init_move {self.check_move_from_expr(expr, vt)} - init_assign {} + init_move => self.check_move_from_expr(expr, vt), + init_assign => () } self.warn_about_unused_or_dead_vars_in_pat(local.node.pat); if !local.node.is_mutbl { self.check_for_reassignments_in_pat(local.node.pat); } } - none { + none => { // No initializer: the variable might be unused; if not, it // should not be live at this point. @@ -1383,8 +1367,8 @@ fn check_local(local: @local, &&self: @liveness, vt: vt<@liveness>) { do (*self).pat_bindings(local.node.pat) |ln, var, sp| { if !self.warn_about_unused(sp, ln, var) { alt (*self).live_on_exit(ln, var) { - none { /* not live: good */ } - some(lnk) { + none => { /* not live: good */ } + some(lnk) => { self.report_illegal_read( local.span, lnk, var, possibly_uninitialized_variable); @@ -1400,7 +1384,7 @@ fn check_local(local: @local, &&self: @liveness, vt: vt<@liveness>) { fn check_expr(expr: @expr, &&self: @liveness, vt: vt<@liveness>) { alt expr.node { - expr_path(_) { + expr_path(_) => { for (*self).variable_from_def_map(expr.id, expr.span).each |var| { let ln = (*self).live_node(expr.id, expr.span); self.consider_last_use(expr, ln, var); @@ -1409,7 +1393,7 @@ fn check_expr(expr: @expr, &&self: @liveness, vt: vt<@liveness>) { visit::visit_expr(expr, self, vt); } - expr_fn(_, _, _, cap_clause) | expr_fn_block(_, _, cap_clause) { + expr_fn(_, _, _, cap_clause) | expr_fn_block(_, _, cap_clause) => { let caps = (*self.ir).captures(expr); for (*caps).each |cap| { let var = (*self).variable_from_rdef(cap.rv, expr.span); @@ -1422,41 +1406,41 @@ fn check_expr(expr: @expr, &&self: @liveness, vt: vt<@liveness>) { visit::visit_expr(expr, self, vt); } - expr_assign(l, r) { + expr_assign(l, r) => { self.check_lvalue(l, vt); vt.visit_expr(r, self, vt); visit::visit_expr(expr, self, vt); } - expr_move(l, r) { + expr_move(l, r) => { self.check_lvalue(l, vt); self.check_move_from_expr(r, vt); visit::visit_expr(expr, self, vt); } - expr_unary_move(r) { + expr_unary_move(r) => { self.check_move_from_expr(r, vt); visit::visit_expr(expr, self, vt); } - expr_assign_op(_, l, _) { + expr_assign_op(_, l, _) => { self.check_lvalue(l, vt); visit::visit_expr(expr, self, vt); } - expr_call(f, args, _) { + expr_call(f, args, _) => { let targs = ty::ty_fn_args(ty::expr_ty(self.tcx, f)); vt.visit_expr(f, self, vt); do vec::iter2(args, targs) |arg_expr, arg_ty| { alt ty::resolved_mode(self.tcx, arg_ty.mode) { - by_val | by_copy | by_ref | by_mutbl_ref{ + by_val | by_copy | by_ref | by_mutbl_ref => { vt.visit_expr(arg_expr, self, vt); } - by_move { + by_move => { self.check_move_from_expr(arg_expr, vt); } } @@ -1474,7 +1458,7 @@ fn check_expr(expr: @expr, &&self: @liveness, vt: vt<@liveness>) { expr_cast(*) | expr_unary(*) | expr_fail(*) | expr_ret(*) | expr_break | expr_again | expr_lit(_) | expr_block(*) | expr_swap(*) | expr_mac(*) | expr_addr_of(*) | - expr_struct(*) | expr_repeat(*) { + expr_struct(*) | expr_repeat(*) => { visit::visit_expr(expr, self, vt); } } @@ -1496,12 +1480,12 @@ impl check_methods for @liveness { fn check_fields(sp: span, entry_ln: live_node) { for self.ir.field_map.each |nm, var| { alt (*self).live_on_entry(entry_ln, var) { - none { /* ok */ } - some(lnk_exit) { + none => { /* ok */ } + some(lnk_exit) => { self.tcx.sess.span_err( sp, fmt!{"field `self.%s` is never initialized", *nm}); } - some(lnk) { + some(lnk) => { self.report_illegal_read( sp, lnk, var, possibly_uninitialized_field); } @@ -1524,10 +1508,10 @@ impl check_methods for @liveness { sp, ~"some control paths may return"); } else { alt fk { - visit::fk_ctor(*) { + visit::fk_ctor(*) => { // ctors are written as though they are unit. } - _ { + _ => { self.tcx.sess.span_err( sp, ~"not all control paths return a value"); } @@ -1541,19 +1525,15 @@ impl check_methods for @liveness { ln.to_str(), var.to_str()}; alt (*self).live_on_exit(ln, var) { - none { } - some(lnk) { - self.report_illegal_move(span, lnk, var); - } + none => {} + some(lnk) => self.report_illegal_move(span, lnk, var) } } fn consider_last_use(expr: @expr, ln: live_node, var: variable) { alt (*self).live_on_exit(ln, var) { - some(_) {} - none { - (*self.ir).add_last_use(expr.id, var); - } + some(_) => {} + none => (*self.ir).add_last_use(expr.id, var) } } @@ -1567,24 +1547,24 @@ impl check_methods for @liveness { } alt expr.node { - expr_path(_) { + expr_path(_) => { alt (*self).variable_from_path(expr) { - some(var) { + some(var) => { let ln = (*self).live_node(expr.id, expr.span); self.check_move_from_var(expr.span, ln, var); } - none {} + none => {} } } - expr_field(base, _, _) { + expr_field(base, _, _) => { // Moving from x.y is allowed if x is never used later. // (Note that the borrowck guarantees that anything // being moved from is uniquely tied to the stack frame) self.check_move_from_expr(base, vt); } - expr_index(base, idx) { + expr_index(base, idx) => { // Moving from x[y] is allowed if x is never used later. // (Note that the borrowck guarantees that anything // being moved from is uniquely tied to the stack frame) @@ -1592,7 +1572,7 @@ impl check_methods for @liveness { vt.visit_expr(idx, self, vt); } - _ { + _ => { // For other kinds of lvalues, no checks are required, // and any embedded expressions are actually rvalues vt.visit_expr(expr, self, vt); @@ -1602,9 +1582,9 @@ impl check_methods for @liveness { fn check_lvalue(expr: @expr, vt: vt<@liveness>) { alt expr.node { - expr_path(_) { + expr_path(_) => { alt self.tcx.def_map.get(expr.id) { - def_local(nid, false) { + def_local(nid, false) => { // Assignment to an immutable variable or argument: // only legal if there is no later assignment. let ln = (*self).live_node(expr.id, expr.span); @@ -1612,21 +1592,21 @@ impl check_methods for @liveness { self.check_for_reassignment(ln, var, expr.span); self.warn_about_dead_assign(expr.span, ln, var); } - def { + def => { alt relevant_def(def) { - some(rdef_var(nid)) { + some(rdef_var(nid)) => { let ln = (*self).live_node(expr.id, expr.span); let var = (*self).variable(nid, expr.span); self.warn_about_dead_assign(expr.span, ln, var); } - some(rdef_self) {} - none {} + some(rdef_self) => {} + none => {} } } } } - _ { + _ => { // For other kinds of lvalues, no checks are required, // and any embedded expressions are actually rvalues visit::visit_expr(expr, self, vt); @@ -1643,7 +1623,7 @@ impl check_methods for @liveness { fn check_for_reassignment(ln: live_node, var: variable, orig_span: span) { alt (*self).assigned_on_exit(ln, var) { - some(lnk_expr(span)) { + some(lnk_expr(span)) => { self.tcx.sess.span_err( span, ~"re-assignment of immutable variable"); @@ -1652,12 +1632,12 @@ impl check_methods for @liveness { orig_span, ~"prior assignment occurs here"); } - some(lnk) { + some(lnk) => { self.tcx.sess.span_bug( orig_span, fmt!{"illegal writer: %?", lnk}); } - none {} + none => {} } } @@ -1671,27 +1651,27 @@ impl check_methods for @liveness { if lnk == lnk_exit { let vk = self.ir.var_kinds[*var]; alt vk { - vk_arg(_, name, _) { + vk_arg(_, name, _) => { self.tcx.sess.span_err( move_span, fmt!{"illegal move from argument `%s`, which is not \ copy or move mode", *name}); return; } - vk_field(name) { + vk_field(name) => { self.tcx.sess.span_err( move_span, fmt!{"illegal move from field `%s`", *name}); return; } - vk_self { + vk_self => { self.tcx.sess.span_err( move_span, ~"illegal move from self (cannot move out of a field of \ self)"); return; } - vk_local(*) | vk_implicit_ret { + vk_local(*) | vk_implicit_ret => { self.tcx.sess.span_bug( move_span, fmt!{"illegal reader (%?) for `%?`", @@ -1711,24 +1691,26 @@ impl check_methods for @liveness { var: variable, rk: read_kind) { let msg = alt rk { - possibly_uninitialized_variable {~"possibly uninitialized variable"} - possibly_uninitialized_field {~"possibly uninitialized field"} - moved_variable {~"moved variable"} + possibly_uninitialized_variable => { + ~"possibly uninitialized variable" + } + possibly_uninitialized_field => ~"possibly uninitialized field", + moved_variable => ~"moved variable" }; let name = (*self.ir).variable_name(var); alt lnk { - lnk_freevar(span) { + lnk_freevar(span) => { self.tcx.sess.span_err( span, fmt!{"capture of %s: `%s`", msg, *name}); } - lnk_expr(span) { + lnk_expr(span) => { self.tcx.sess.span_err( span, fmt!{"use of %s: `%s`", msg, *name}); } lnk_exit | - lnk_vdef(_) { + lnk_vdef(_) => { self.tcx.sess.span_bug( chk_span, fmt!{"illegal reader: %?", lnk}); @@ -1745,20 +1727,20 @@ impl check_methods for @liveness { for decl.inputs.each |arg| { let var = (*self).variable(arg.id, arg.ty.span); alt ty::resolved_mode(self.tcx, arg.mode) { - by_mutbl_ref { + by_mutbl_ref => { // for mutable reference arguments, something like // x = 1; // is not worth warning about, as it has visible // side effects outside the fn. alt (*self).assigned_on_entry(entry_ln, var) { - some(_) { /*ok*/ } - none { + some(_) => { /*ok*/ } + none => { // but if it is not written, it ought to be used self.warn_about_unused(sp, entry_ln, var); } } } - by_val | by_ref | by_move | by_copy { + by_val | by_ref | by_move | by_copy => { self.warn_about_unused(sp, entry_ln, var); } } diff --git a/src/rustc/middle/pat_util.rs b/src/rustc/middle/pat_util.rs index 70a432d78c9..405afe20a1c 100644 --- a/src/rustc/middle/pat_util.rs +++ b/src/rustc/middle/pat_util.rs @@ -23,14 +23,12 @@ fn pat_id_map(dm: resolve3::DefMap, pat: @pat) -> pat_id_map { fn pat_is_variant(dm: resolve3::DefMap, pat: @pat) -> bool { alt pat.node { - pat_enum(_, _) { true } - pat_ident(_, _, none) { - alt dm.find(pat.id) { - some(def_variant(_, _)) { true } - _ { false } - } + pat_enum(_, _) => true, + pat_ident(_, _, none) => alt dm.find(pat.id) { + some(def_variant(_, _)) => true, + _ => false } - _ { false } + _ => false } } @@ -38,10 +36,10 @@ fn pat_bindings(dm: resolve3::DefMap, pat: @pat, it: fn(node_id, span, @path)) { do walk_pat(pat) |p| { alt p.node { - pat_ident(_, pth, _) if !pat_is_variant(dm, p) { + pat_ident(_, pth, _) if !pat_is_variant(dm, p) => { it(p.id, p.span, pth); } - _ {} + _ => {} } } } diff --git a/src/rustc/middle/region.rs b/src/rustc/middle/region.rs index ec0ad5cb770..9cece96b892 100644 --- a/src/rustc/middle/region.rs +++ b/src/rustc/middle/region.rs @@ -89,8 +89,8 @@ fn scope_contains(region_map: region_map, superscope: ast::node_id, let mut subscope = subscope; while superscope != subscope { alt region_map.find(subscope) { - none { return false; } - some(scope) { subscope = scope; } + none => return false, + some(scope) => subscope = scope } } return true; @@ -129,8 +129,8 @@ fn nearest_common_ancestor(region_map: region_map, scope_a: ast::node_id, let mut scope = scope; loop { alt region_map.find(scope) { - none { return result; } - some(superscope) { + none => return result, + some(superscope) => { vec::push(result, superscope); scope = superscope; } @@ -173,10 +173,10 @@ fn nearest_common_ancestor(region_map: region_map, scope_a: ast::node_id, /// Extracts that current parent from cx, failing if there is none. fn parent_id(cx: ctxt, span: span) -> ast::node_id { alt cx.parent { - none { + none => { cx.sess.span_bug(span, ~"crate should not be parent here"); } - some(parent_id) { + some(parent_id) => { parent_id } } @@ -185,8 +185,8 @@ fn parent_id(cx: ctxt, span: span) -> ast::node_id { /// Records the current parent (if any) as the parent of `child_id`. fn record_parent(cx: ctxt, child_id: ast::node_id) { alt cx.parent { - none { /* no-op */ } - some(parent_id) { + none => { /* no-op */ } + some(parent_id) => { debug!{"parent of node %d is node %d", child_id, parent_id}; cx.region_map.insert(child_id, parent_id); } @@ -208,19 +208,19 @@ fn resolve_arm(arm: ast::arm, cx: ctxt, visitor: visit::vt<ctxt>) { fn resolve_pat(pat: @ast::pat, cx: ctxt, visitor: visit::vt<ctxt>) { alt pat.node { - ast::pat_ident(_, path, _) { + ast::pat_ident(_, path, _) => { let defn_opt = cx.def_map.find(pat.id); alt defn_opt { - some(ast::def_variant(_,_)) { + some(ast::def_variant(_,_)) => { /* Nothing to do; this names a variant. */ } - _ { + _ => { /* This names a local. Bind it to the containing scope. */ record_parent(cx, pat.id); } } } - _ { /* no-op */ } + _ => { /* no-op */ } } visit::visit_pat(pat, cx, visitor); @@ -278,12 +278,12 @@ fn resolve_fn(fk: visit::fn_kind, decl: ast::fn_decl, body: ast::blk, let fn_cx = alt fk { visit::fk_item_fn(*) | visit::fk_method(*) | - visit::fk_ctor(*) | visit::fk_dtor(*) { + visit::fk_ctor(*) | visit::fk_dtor(*) => { // Top-level functions are a root scope. {parent: some(id) with cx} } - visit::fk_anon(*) | visit::fk_fn_block(*) { + visit::fk_anon(*) | visit::fk_fn_block(*) => { // Closures continue with the inherited scope. cx } @@ -425,9 +425,9 @@ impl methods for determine_rp_ctxt { // that flag to false when we enter a method. fn region_is_relevant(r: @ast::region) -> bool { alt r.node { - ast::re_anon {self.anon_implies_rp} - ast::re_named(@~"self") {true} - ast::re_named(_) {false} + ast::re_anon => self.anon_implies_rp, + ast::re_named(@~"self") => true, + ast::re_named(_) => false } } @@ -502,9 +502,9 @@ fn determine_rp_in_ty(ty: @ast::ty, // then check whether it is region-parameterized and consider // that as a direct dependency. alt ty.node { - ast::ty_path(_, id) { + ast::ty_path(_, id) => { alt cx.def_map.get(id) { - ast::def_ty(did) | ast::def_class(did, _) { + ast::def_ty(did) | ast::def_class(did, _) => { if did.crate == ast::local_crate { cx.add_dep(did.node, cx.item_id); } else { @@ -516,10 +516,10 @@ fn determine_rp_in_ty(ty: @ast::ty, } } } - _ {} + _ => {} } } - _ {} + _ => {} } alt ty.node { @@ -562,8 +562,8 @@ fn determine_rp_in_crate(sess: session, let id = cx.worklist.pop(); debug!{"popped %d from worklist", id}; alt cx.dep_map.find(id) { - none {} - some(vec) { + none => {} + some(vec) => { for vec.each |to_id| { cx.add_rp(to_id); } diff --git a/src/rustc/middle/resolve3.rs b/src/rustc/middle/resolve3.rs index 93173b4008f..fc7f079e172 100644 --- a/src/rustc/middle/resolve3.rs +++ b/src/rustc/middle/resolve3.rs @@ -248,8 +248,8 @@ class AtomTable { fn intern(string: @~str) -> Atom { alt self.atoms.find(string) { - none { /* fall through */ } - some(atom) { return atom; } + none => { /* fall through */ } + some(atom) => return atom } let atom = Atom(self.atom_count); @@ -368,11 +368,11 @@ class ImportResolution { fn target_for_namespace(namespace: Namespace) -> option<Target> { alt namespace { - ModuleNS { return copy self.module_target; } - TypeNS { return copy self.type_target; } - ValueNS { return copy self.value_target; } + ModuleNS => return copy self.module_target, + TypeNS => return copy self.type_target, + ValueNS => return copy self.value_target, - ImplNS { + ImplNS => { if (*self.impl_target).len() > 0u { return some(copy *(*self.impl_target).get_elt(0u)); } @@ -462,8 +462,8 @@ class Module { pure fn is_none<T>(x: option<T>) -> bool { alt x { - none { return true; } - some(_) { return false; } + none => return true, + some(_) => return false } } @@ -518,8 +518,8 @@ class NameBindings { /// Returns the module node if applicable. fn get_module_if_available() -> option<@Module> { alt self.module_def { - NoModuleDef { return none; } - ModuleDef(module_) { return some(module_); } + NoModuleDef => return none, + ModuleDef(module_) => return some(module_) } } @@ -529,11 +529,11 @@ class NameBindings { */ fn get_module() -> @Module { alt self.module_def { - NoModuleDef { + NoModuleDef => { fail ~"get_module called on a node with no module definition!"; } - ModuleDef(module_) { + ModuleDef(module_) => { return module_; } } @@ -541,47 +541,33 @@ class NameBindings { fn defined_in_namespace(namespace: Namespace) -> bool { alt namespace { - ModuleNS { return self.module_def != NoModuleDef; } - TypeNS { return self.type_def != none; } - ValueNS { return self.value_def != none; } - ImplNS { return self.impl_defs.len() >= 1u; } + ModuleNS => return self.module_def != NoModuleDef, + TypeNS => return self.type_def != none, + ValueNS => return self.value_def != none, + ImplNS => return self.impl_defs.len() >= 1u } } fn def_for_namespace(namespace: Namespace) -> option<def> { alt namespace { - TypeNS { - return self.type_def; + TypeNS => return self.type_def, + ValueNS => return self.value_def, + ModuleNS => alt self.module_def { + NoModuleDef => return none, + ModuleDef(module_) => alt module_.def_id { + none => return none, + some(def_id) => return some(def_mod(def_id)) } - ValueNS { - return self.value_def; - } - ModuleNS { - alt self.module_def { - NoModuleDef { - return none; - } - ModuleDef(module_) { - alt module_.def_id { - none { - return none; - } - some(def_id) { - return some(def_mod(def_id)); - } - } - } - } - } - ImplNS { - // Danger: Be careful what you use this for! def_ty is not - // necessarily the right def. + } + ImplNS => { + // Danger: Be careful what you use this for! def_ty is not + // necessarily the right def. - if self.impl_defs.len() == 0u { - return none; - } - return some(def_ty(self.impl_defs[0].did)); + if self.impl_defs.len() == 0u { + return none; } + return some(def_ty(self.impl_defs[0].did)); + } } } } @@ -765,7 +751,7 @@ class Resolver { fn get_module_from_parent(reduced_graph_parent: ReducedGraphParent) -> @Module { alt reduced_graph_parent { - ModuleReducedGraphParent(module_) { + ModuleReducedGraphParent(module_) => { return module_; } } @@ -791,7 +777,7 @@ class Resolver { let mut module_; alt reduced_graph_parent { - ModuleReducedGraphParent(parent_module) { + ModuleReducedGraphParent(parent_module) => { module_ = parent_module; } } @@ -799,12 +785,12 @@ class Resolver { // Add or reuse the child. let new_parent = ModuleReducedGraphParent(module_); alt module_.children.find(name) { - none { + none => { let child = @NameBindings(); module_.children.insert(name, child); return (child, new_parent); } - some(child) { + some(child) => { return (child, new_parent); } } @@ -819,17 +805,17 @@ class Resolver { // Check each statement. for block.node.stmts.each |statement| { alt statement.node { - stmt_decl(declaration, _) { + stmt_decl(declaration, _) => { alt declaration.node { - decl_item(_) { + decl_item(_) => { return true; } - _ { + _ => { // Keep searching. } } } - _ { + _ => { // Keep searching. } } @@ -843,7 +829,7 @@ class Resolver { fn get_parent_link(parent: ReducedGraphParent, name: Atom) -> ParentLink { alt parent { - ModuleReducedGraphParent(module_) { + ModuleReducedGraphParent(module_) => { return ModuleParentLink(module_, name); } } @@ -858,7 +844,7 @@ class Resolver { let (name_bindings, new_parent) = self.add_child(atom, parent); alt item.node { - item_mod(module_) { + item_mod(module_) => { let parent_link = self.get_parent_link(new_parent, atom); let def_id = { crate: 0, node: item.id }; (*name_bindings).define_module(parent_link, some(def_id)); @@ -868,7 +854,7 @@ class Resolver { visit_mod(module_, item.span, item.id, new_parent, visitor); } - item_foreign_mod(foreign_module) { + item_foreign_mod(foreign_module) => { let parent_link = self.get_parent_link(new_parent, atom); let def_id = { crate: 0, node: item.id }; (*name_bindings).define_module(parent_link, some(def_id)); @@ -880,22 +866,22 @@ class Resolver { } // These items live in the value namespace. - item_const(*) { + item_const(*) => { (*name_bindings).define_value(def_const(local_def(item.id))); } - item_fn(decl, _, _) { + item_fn(decl, _, _) => { let def = def_fn(local_def(item.id), decl.purity); (*name_bindings).define_value(def); visit_item(item, new_parent, visitor); } // These items live in the type namespace. - item_ty(*) { + item_ty(*) => { (*name_bindings).define_type(def_ty(local_def(item.id))); } // These items live in both the type and value namespaces. - item_enum(variants, _) { + item_enum(variants, _) => { (*name_bindings).define_type(def_ty(local_def(item.id))); for variants.each |variant| { @@ -905,7 +891,7 @@ class Resolver { visitor); } } - item_class(_, _, class_members, optional_ctor, _) { + item_class(_, _, class_members, optional_ctor, _) => { (*name_bindings).define_type(def_ty(local_def(item.id))); alt optional_ctor { @@ -928,7 +914,7 @@ class Resolver { let mut method_infos = ~[]; for class_members.each |class_member| { alt class_member.node { - class_method(method) { + class_method(method) => { // XXX: Combine with impl method code below. method_infos += ~[ @{ @@ -939,7 +925,7 @@ class Resolver { } ]; } - instance_var(*) { + instance_var(*) => { // Don't need to do anything with this. } } @@ -960,7 +946,7 @@ class Resolver { visit_item(item, new_parent, visitor); } - item_impl(_, _, _, methods) { + item_impl(_, _, _, methods) => { // Create the set of implementation information that the // implementation scopes (ImplScopes) need and write it into // the implementation definition list for this set of name @@ -988,17 +974,17 @@ class Resolver { visit_item(item, new_parent, visitor); } - item_trait(_, _, methods) { + item_trait(_, _, methods) => { // Add the names of all the methods to the trait info. let method_names = @atom_hashmap(); for methods.each |method| { let atom; alt method { - required(required_method) { + required(required_method) => { atom = (*self.atom_table).intern (required_method.ident); } - provided(provided_method) { + provided(provided_method) => { atom = (*self.atom_table).intern (provided_method.ident); } @@ -1013,7 +999,7 @@ class Resolver { visit_item(item, new_parent, visitor); } - item_mac(*) { + item_mac(*) => { fail ~"item macros unimplemented" } } @@ -1043,7 +1029,7 @@ class Resolver { parent: ReducedGraphParent, &&_visitor: vt<ReducedGraphParent>) { alt view_item.node { - view_item_import(view_paths) { + view_item_import(view_paths) => { for view_paths.each |view_path| { // Extract and intern the module part of the path. For // globs and lists, the path is found directly in the AST; @@ -1051,7 +1037,7 @@ class Resolver { let module_path = @dvec(); alt view_path.node { - view_path_simple(_, full_path, _) { + view_path_simple(_, full_path, _) => { let path_len = full_path.idents.len(); assert path_len != 0u; @@ -1065,7 +1051,7 @@ class Resolver { } view_path_glob(module_ident_path, _) | - view_path_list(module_ident_path, _, _) { + view_path_list(module_ident_path, _, _) => { for module_ident_path.idents.each |ident| { let atom = (*self.atom_table).intern(ident); (*module_path).push(atom); @@ -1076,7 +1062,7 @@ class Resolver { // Build up the import directives. let module_ = self.get_module_from_parent(parent); alt view_path.node { - view_path_simple(binding, full_path, _) { + view_path_simple(binding, full_path, _) => { let target_atom = (*self.atom_table).intern(binding); let source_ident = full_path.idents.last(); @@ -1089,7 +1075,7 @@ class Resolver { subclass, view_path.span); } - view_path_list(_, source_idents, _) { + view_path_list(_, source_idents, _) => { for source_idents.each |source_ident| { let name = source_ident.node.name; let atom = (*self.atom_table).intern(name); @@ -1100,7 +1086,7 @@ class Resolver { view_path.span); } } - view_path_glob(_, _) { + view_path_glob(_, _) => { self.build_import_directive(module_, module_path, @GlobImport, @@ -1110,11 +1096,11 @@ class Resolver { } } - view_item_export(view_paths) { + view_item_export(view_paths) => { let module_ = self.get_module_from_parent(parent); for view_paths.each |view_path| { alt view_path.node { - view_path_simple(ident, full_path, ident_id) { + view_path_simple(ident, full_path, ident_id) => { let last_ident = full_path.idents.last(); if last_ident != ident { self.session.span_err(view_item.span, @@ -1133,13 +1119,13 @@ class Resolver { module_.exported_names.insert(atom, ident_id); } - view_path_glob(*) { + view_path_glob(*) => { self.session.span_err(view_item.span, ~"export globs are \ unsupported"); } - view_path_list(path, path_list_idents, _) { + view_path_list(path, path_list_idents, _) => { if path.idents.len() == 1u && path_list_idents.len() == 0u { @@ -1170,9 +1156,9 @@ class Resolver { } } - view_item_use(name, _, node_id) { + view_item_use(name, _, node_id) => { alt find_use_stmt_cnum(self.session.cstore, node_id) { - some(crate_id) { + some(crate_id) => { let atom = (*self.atom_table).intern(name); let (child_name_bindings, new_parent) = self.add_child(atom, parent); @@ -1186,7 +1172,7 @@ class Resolver { self.build_reduced_graph_for_external_crate ((*child_name_bindings).get_module()); } - none { + none => { /* Ignore. */ } } @@ -1204,7 +1190,7 @@ class Resolver { let (name_bindings, new_parent) = self.add_child(name, parent); alt foreign_item.node { - foreign_item_fn(fn_decl, type_parameters) { + foreign_item_fn(fn_decl, type_parameters) => { let def = def_fn(local_def(foreign_item.id), fn_decl.purity); (*name_bindings).define_value(def); @@ -1277,7 +1263,7 @@ class Resolver { // Define or reuse the module node. alt child_name_bindings.module_def { - NoModuleDef { + NoModuleDef => { debug!{"(building reduced graph for external crate) \ autovivifying %s", ident}; let parent_link = self.get_parent_link(new_parent, @@ -1285,7 +1271,7 @@ class Resolver { (*child_name_bindings).define_module(parent_link, none); } - ModuleDef(_) { /* Fall through. */ } + ModuleDef(_) => { /* Fall through. */ } } current_module = (*child_name_bindings).get_module(); @@ -1298,11 +1284,11 @@ class Resolver { ModuleReducedGraphParent(current_module)); alt path_entry.def_like { - dl_def(def) { + dl_def(def) => { alt def { - def_mod(def_id) | def_foreign_mod(def_id) { + def_mod(def_id) | def_foreign_mod(def_id) => { alt copy child_name_bindings.module_def { - NoModuleDef { + NoModuleDef => { debug!{"(building reduced graph for \ external crate) building module \ %s", final_ident}; @@ -1311,7 +1297,7 @@ class Resolver { atom); alt modules.find(def_id) { - none { + none => { (*child_name_bindings). define_module(parent_link, some(def_id)); @@ -1319,7 +1305,7 @@ class Resolver { (*child_name_bindings). get_module()); } - some(existing_module) { + some(existing_module) => { // Create an import resolution to // avoid creating cycles in the // module graph. @@ -1331,12 +1317,12 @@ class Resolver { alt existing_module.parent_link { NoParentLink | - BlockParentLink(*) { + BlockParentLink(*) => { fail ~"can't happen"; } ModuleParentLink (parent_module, - atom) { + atom) => { let name_bindings = parent_module. @@ -1360,7 +1346,7 @@ class Resolver { } } } - ModuleDef(module_) { + ModuleDef(module_) => { debug!{"(building reduced graph for \ external crate) already created \ module"}; @@ -1370,12 +1356,12 @@ class Resolver { } } def_fn(def_id, _) | def_const(def_id) | - def_variant(_, def_id) { + def_variant(_, def_id) => { debug!{"(building reduced graph for external \ crate) building value %s", final_ident}; (*child_name_bindings).define_value(def); } - def_ty(def_id) { + def_ty(def_id) => { debug!{"(building reduced graph for external \ crate) building type %s", final_ident}; @@ -1384,10 +1370,10 @@ class Resolver { alt get_method_names_if_trait(self.session.cstore, def_id) { - none { + none => { // Nothing to do. } - some(method_names) { + some(method_names) => { let interned_method_names = @atom_hashmap(); for method_names.each |method_name| { @@ -1408,7 +1394,7 @@ class Resolver { (*child_name_bindings).define_type(def); } - def_class(def_id, has_constructor) { + def_class(def_id, has_constructor) => { debug!{"(building reduced graph for external \ crate) building type %s (value? %d)", final_ident, @@ -1422,12 +1408,12 @@ class Resolver { def_self(*) | def_arg(*) | def_local(*) | def_prim_ty(*) | def_ty_param(*) | def_binding(*) | def_use(*) | def_upvar(*) | def_region(*) | - def_typaram_binder(*) { + def_typaram_binder(*) => { fail fmt!{"didn't expect `%?`", def}; } } } - dl_impl(_) { + dl_impl(_) => { // Because of the infelicitous way the metadata is // written, we can't process this impl now. We'll get it // later. @@ -1435,7 +1421,7 @@ class Resolver { debug!{"(building reduced graph for external crate) \ ignoring impl %s", final_ident}; } - dl_field { + dl_field => { debug!{"(building reduced graph for external crate) \ ignoring field %s", final_ident}; } @@ -1452,10 +1438,10 @@ class Resolver { for module_.children.each |_name, child_node| { alt (*child_node).get_module_if_available() { - none { + none => { // Nothing to do. } - some(child_module) { + some(child_module) => { self. build_reduced_graph_for_impls_in_external_module_subtree (child_module); @@ -1479,13 +1465,13 @@ class Resolver { copy module_.def_id}; alt module_.def_id { - none { + none => { debug!{"(building reduced graph for impls in external \ module) no def ID for `%s`, skipping", self.module_to_str(module_)}; return; } - some(_) { + some(_) => { // Continue. } } @@ -1531,19 +1517,19 @@ class Resolver { // the appropriate flag. alt *subclass { - SingleImport(target, _) { + SingleImport(target, _) => { alt module_.import_resolutions.find(target) { - some(resolution) { + some(resolution) => { resolution.outstanding_references += 1u; } - none { + none => { let resolution = @ImportResolution(span); resolution.outstanding_references = 1u; module_.import_resolutions.insert(target, resolution); } } } - GlobImport { + GlobImport => { // Set the glob flag. This tells us that we don't know the // module's exports ahead of time. @@ -1603,10 +1589,10 @@ class Resolver { for module_.children.each |_name, child_node| { alt (*child_node).get_module_if_available() { - none { + none => { // Nothing to do. } - some(child_module) { + some(child_module) => { self.resolve_imports_for_module_subtree(child_module); } } @@ -1631,16 +1617,16 @@ class Resolver { let import_index = module_.resolved_import_count; let import_directive = module_.imports.get_elt(import_index); alt self.resolve_import_for_module(module_, import_directive) { - Failed { + Failed => { // We presumably emitted an error. Continue. self.session.span_err(import_directive.span, ~"failed to resolve import"); } - Indeterminate { + Indeterminate => { // Bail out. We'll come around next time. break; } - Success(()) { + Success(()) => { // Good. Continue. } } @@ -1682,25 +1668,25 @@ class Resolver { NoXray, import_directive.span) { - Failed { + Failed => { resolution_result = Failed; } - Indeterminate { + Indeterminate => { resolution_result = Indeterminate; } - Success(containing_module) { + Success(containing_module) => { // We found the module that the target is contained // within. Attempt to resolve the import within it. alt *import_directive.subclass { - SingleImport(target, source) { + SingleImport(target, source) => { resolution_result = self.resolve_single_import(module_, containing_module, target, source); } - GlobImport { + GlobImport => { let span = import_directive.span; resolution_result = self.resolve_glob_import(module_, @@ -1714,11 +1700,11 @@ class Resolver { // Decrement the count of unresolved imports. alt resolution_result { - Success(()) { + Success(()) => { assert self.unresolved_imports >= 1u; self.unresolved_imports -= 1u; } - _ { + _ => { // Nothing to do here; just return the error. } } @@ -1730,11 +1716,11 @@ class Resolver { if resolution_result != Indeterminate { alt *import_directive.subclass { - GlobImport { + GlobImport => { assert module_.glob_count >= 1u; module_.glob_count -= 1u; } - SingleImport(*) { + SingleImport(*) => { // Ignore. } } @@ -1772,10 +1758,10 @@ class Resolver { // Search for direct children of the containing module. alt containing_module.children.find(source) { - none { + none => { // Continue. } - some(child_name_bindings) { + some(child_name_bindings) => { if (*child_name_bindings).defined_in_namespace(ModuleNS) { module_result = BoundResult(containing_module, child_name_bindings); @@ -1802,10 +1788,10 @@ class Resolver { alt (module_result, value_result, type_result, impl_result) { (BoundResult(*), BoundResult(*), BoundResult(*), - BoundImplResult(*)) { + BoundImplResult(*)) => { // Continue. } - _ { + _ => { // If there is an unresolved glob at this point in the // containing module, bail out. We don't know enough to be // able to resolve this import. @@ -1820,7 +1806,7 @@ class Resolver { // module. alt containing_module.import_resolutions.find(source) { - none { + none => { // The containing module definitely doesn't have an // exported import with the name in question. We can // therefore accurately report that the names are @@ -1841,7 +1827,7 @@ class Resolver { } some(import_resolution) if import_resolution.outstanding_references - == 0u { + == 0u => { fn get_binding(import_resolution: @ImportResolution, namespace: Namespace) @@ -1849,10 +1835,10 @@ class Resolver { alt (*import_resolution). target_for_namespace(namespace) { - none { + none => { return UnboundResult; } - some(target) { + some(target) => { import_resolution.used = true; return BoundResult(target.target_module, target.bindings); @@ -1892,7 +1878,7 @@ class Resolver { get_import_binding(import_resolution); } } - some(_) { + some(_) => { // The import is unresolved. Bail out. debug!{"(resolving single import) unresolved import; \ bailing out"}; @@ -1907,47 +1893,47 @@ class Resolver { let import_resolution = module_.import_resolutions.get(target); alt module_result { - BoundResult(target_module, name_bindings) { + BoundResult(target_module, name_bindings) => { debug!{"(resolving single import) found module binding"}; import_resolution.module_target = some(Target(target_module, name_bindings)); } - UnboundResult { + UnboundResult => { debug!{"(resolving single import) didn't find module \ binding"}; } - UnknownResult { + UnknownResult => { fail ~"module result should be known at this point"; } } alt value_result { - BoundResult(target_module, name_bindings) { + BoundResult(target_module, name_bindings) => { import_resolution.value_target = some(Target(target_module, name_bindings)); } - UnboundResult { /* Continue. */ } - UnknownResult { + UnboundResult => { /* Continue. */ } + UnknownResult => { fail ~"value result should be known at this point"; } } alt type_result { - BoundResult(target_module, name_bindings) { + BoundResult(target_module, name_bindings) => { import_resolution.type_target = some(Target(target_module, name_bindings)); } - UnboundResult { /* Continue. */ } - UnknownResult { + UnboundResult => { /* Continue. */ } + UnknownResult => { fail ~"type result should be known at this point"; } } alt impl_result { - BoundImplResult(targets) { + BoundImplResult(targets) => { for (*targets).each |target| { (*import_resolution.impl_target).push(target); } } - UnboundImplResult { /* Continue. */ } - UnknownImplResult { + UnboundImplResult => { /* Continue. */ } + UnknownImplResult => { fail ~"impl result should be known at this point"; } } @@ -1958,8 +1944,8 @@ class Resolver { If this name wasn't found in any of the four namespaces, it's definitely unresolved */ - (none, none, none, v) if v.len() == 0 { return Failed; } - _ {} + (none, none, none, v) if v.len() == 0 => { return Failed; } + _ => {} } assert import_resolution.outstanding_references >= 1u; @@ -2011,7 +1997,7 @@ class Resolver { // Here we merge two import resolutions. alt module_.import_resolutions.find(atom) { - none { + none => { // Simple: just copy the old import resolution. let new_import_resolution = @ImportResolution(target_import_resolution.span); @@ -2027,33 +2013,33 @@ class Resolver { module_.import_resolutions.insert (atom, new_import_resolution); } - some(dest_import_resolution) { + some(dest_import_resolution) => { // Merge the two import resolutions at a finer-grained // level. alt copy target_import_resolution.module_target { - none { + none => { // Continue. } - some(module_target) { + some(module_target) => { dest_import_resolution.module_target = some(copy module_target); } } alt copy target_import_resolution.value_target { - none { + none => { // Continue. } - some(value_target) { + some(value_target) => { dest_import_resolution.value_target = some(copy value_target); } } alt copy target_import_resolution.type_target { - none { + none => { // Continue. } - some(type_target) { + some(type_target) => { dest_import_resolution.type_target = some(copy type_target); } @@ -2083,13 +2069,13 @@ class Resolver { let mut dest_import_resolution; alt module_.import_resolutions.find(atom) { - none { + none => { // Create a new import resolution from this child. dest_import_resolution = @ImportResolution(span); module_.import_resolutions.insert (atom, dest_import_resolution); } - some(existing_import_resolution) { + some(existing_import_resolution) => { dest_import_resolution = existing_import_resolution; } } @@ -2148,19 +2134,19 @@ class Resolver { alt self.resolve_name_in_module(search_module, name, ModuleNS, xray) { - Failed { + Failed => { self.session.span_err(span, ~"unresolved name"); return Failed; } - Indeterminate { + Indeterminate => { debug!{"(resolving module path for import) module \ resolution is indeterminate: %s", *(*self.atom_table).atom_to_str(name)}; return Indeterminate; } - Success(target) { + Success(target) => { alt target.bindings.module_def { - NoModuleDef { + NoModuleDef => { // Not a module. self.session.span_err(span, fmt!{"not a module: %s", @@ -2168,7 +2154,7 @@ class Resolver { atom_to_str(name)}); return Failed; } - ModuleDef(module_) { + ModuleDef(module_) => { search_module = module_; } } @@ -2205,16 +2191,16 @@ class Resolver { let first_element = (*module_path).get_elt(0u); let mut search_module; alt self.resolve_module_in_lexical_scope(module_, first_element) { - Failed { + Failed => { self.session.span_err(span, ~"unresolved name"); return Failed; } - Indeterminate { + Indeterminate => { debug!{"(resolving module path for import) indeterminate; \ bailing"}; return Indeterminate; } - Success(resulting_module) { + Success(resulting_module) => { search_module = resulting_module; } } @@ -2242,11 +2228,11 @@ class Resolver { alt module_.children.find(name) { some(name_bindings) - if (*name_bindings).defined_in_namespace(namespace) { + if (*name_bindings).defined_in_namespace(namespace) => { return Success(Target(module_, name_bindings)); } - some(_) | none { /* Not found; continue. */ } + some(_) | none => { /* Not found; continue. */ } } // Now check for its import directives. We don't have to have resolved @@ -2255,18 +2241,18 @@ class Resolver { // current scope. alt module_.import_resolutions.find(name) { - none { + none => { // Not found; continue. } - some(import_resolution) { + some(import_resolution) => { alt (*import_resolution).target_for_namespace(namespace) { - none { + none => { // Not found; continue. debug!{"(resolving item in lexical scope) found \ import resolution, but not in namespace %?", namespace}; } - some(target) { + some(target) => { import_resolution.used = true; return Success(copy target); } @@ -2279,14 +2265,14 @@ class Resolver { loop { // Go to the next parent. alt search_module.parent_link { - NoParentLink { + NoParentLink => { // No more parents. This module was unresolved. debug!{"(resolving item in lexical scope) unresolved \ module"}; return Failed; } ModuleParentLink(parent_module_node, _) | - BlockParentLink(parent_module_node, _) { + BlockParentLink(parent_module_node, _) => { search_module = parent_module_node; } } @@ -2294,10 +2280,10 @@ class Resolver { // Resolve the name in the parent module. alt self.resolve_name_in_module(search_module, name, namespace, Xray) { - Failed { + Failed => { // Continue up the search chain. } - Indeterminate { + Indeterminate => { // We couldn't see through the higher scope because of an // unresolved import higher up. Bail. @@ -2305,7 +2291,7 @@ class Resolver { higher scope; bailing"}; return Indeterminate; } - Success(target) { + Success(target) => { // We found the module. return Success(copy target); } @@ -2317,24 +2303,24 @@ class Resolver { -> ResolveResult<@Module> { alt self.resolve_item_in_lexical_scope(module_, name, ModuleNS) { - Success(target) { + Success(target) => { alt target.bindings.module_def { - NoModuleDef { + NoModuleDef => { error!{"!!! (resolving module in lexical scope) module wasn't actually a module!"}; return Failed; } - ModuleDef(module_) { + ModuleDef(module_) => { return Success(module_); } } } - Indeterminate { + Indeterminate => { debug!{"(resolving module in lexical scope) indeterminate; \ bailing"}; return Indeterminate; } - Failed { + Failed => { debug!{"(resolving module in lexical scope) failed to \ resolve"}; return Failed; @@ -2371,12 +2357,12 @@ class Resolver { // First, check the direct children of the module. alt module_.children.find(name) { some(name_bindings) - if (*name_bindings).defined_in_namespace(namespace) { + if (*name_bindings).defined_in_namespace(namespace) => { debug!{"(resolving name in module) found node as child"}; return Success(Target(module_, name_bindings)); } - some(_) | none { + some(_) | none => { // Continue. } } @@ -2391,7 +2377,7 @@ class Resolver { // Otherwise, we check the list of resolved imports. alt module_.import_resolutions.find(name) { - some(import_resolution) { + some(import_resolution) => { if import_resolution.outstanding_references != 0u { debug!{"(resolving name in module) import unresolved; \ bailing out"}; @@ -2399,12 +2385,12 @@ class Resolver { } alt (*import_resolution).target_for_namespace(namespace) { - none { + none => { debug!{"(resolving name in module) name found, but \ not in namespace %?", namespace}; } - some(target) { + some(target) => { debug!{"(resolving name in module) resolved to \ import"}; import_resolution.used = true; @@ -2412,7 +2398,7 @@ class Resolver { } } } - none { + none => { // Continue. } } @@ -2435,11 +2421,11 @@ class Resolver { let mut target_name; let mut source_name; alt *import_directive.subclass { - SingleImport(target, source) { + SingleImport(target, source) => { target_name = target; source_name = source; } - GlobImport { + GlobImport => { fail ~"found `import *`, which is invalid"; } } @@ -2460,17 +2446,17 @@ class Resolver { source_name, ModuleNS) { - Failed { + Failed => { debug!{"(resolving one-level renaming import) didn't find \ module result"}; module_result = none; } - Indeterminate { + Indeterminate => { debug!{"(resolving one-level renaming import) module result \ is indeterminate; bailing"}; return Indeterminate; } - Success(name_bindings) { + Success(name_bindings) => { debug!{"(resolving one-level renaming import) module result \ found"}; module_result = some(copy name_bindings); @@ -2483,17 +2469,17 @@ class Resolver { source_name, ValueNS) { - Failed { + Failed => { debug!{"(resolving one-level renaming import) didn't find \ value result"}; value_result = none; } - Indeterminate { + Indeterminate => { debug!{"(resolving one-level renaming import) value result \ is indeterminate; bailing"}; return Indeterminate; } - Success(name_bindings) { + Success(name_bindings) => { debug!{"(resolving one-level renaming import) value result \ found"}; value_result = some(copy name_bindings); @@ -2506,17 +2492,17 @@ class Resolver { source_name, TypeNS) { - Failed { + Failed => { debug!{"(resolving one-level renaming import) didn't find \ type result"}; type_result = none; } - Indeterminate { + Indeterminate => { debug!{"(resolving one-level renaming import) type result is \ indeterminate; bailing"}; return Indeterminate; } - Success(name_bindings) { + Success(name_bindings) => { debug!{"(resolving one-level renaming import) type result \ found"}; type_result = some(copy name_bindings); @@ -2546,17 +2532,17 @@ class Resolver { source_name, ImplNS) { - Failed { + Failed => { debug!{"(resolving one-level renaming import) didn't find \ impl result"}; impl_result = none; } - Indeterminate { + Indeterminate => { debug!{"(resolving one-level renaming import) impl result is \ indeterminate; bailing"}; return Indeterminate; } - Success(name_bindings) { + Success(name_bindings) => { debug!{"(resolving one-level renaming import) impl result \ found"}; impl_result = some(@copy name_bindings); @@ -2574,12 +2560,12 @@ class Resolver { // Otherwise, proceed and write in the bindings. alt module_.import_resolutions.find(target_name) { - none { + none => { fail ~"(resolving one-level renaming import) reduced graph \ construction or glob importing should have created the \ import resolution name by now"; } - some(import_resolution) { + some(import_resolution) => { debug!{"(resolving one-level renaming import) writing module \ result %? for `%s` into `%s`", is_none(module_result), @@ -2591,10 +2577,10 @@ class Resolver { import_resolution.type_target = type_result; alt impl_result { - none { + none => { // Nothing to do. } - some(impl_result) { + some(impl_result) => { (*import_resolution.impl_target).push(impl_result); } } @@ -2619,10 +2605,10 @@ class Resolver { // Descend into children and anonymous children. for module_.children.each |_name, child_node| { alt (*child_node).get_module_if_available() { - none { + none => { // Continue. } - some(child_module) { + some(child_module) => { self.report_unresolved_imports(child_module); } } @@ -2652,13 +2638,13 @@ class Resolver { // exports for local crates. alt module_.def_id { - some(def_id) if def_id.crate == local_crate { + some(def_id) if def_id.crate == local_crate => { // OK. Continue. } - none { + none => { // Record exports for the root module. } - some(_) { + some(_) => { // Bail out. debug!{"(recording exports for module subtree) not recording \ exports for `%s`", @@ -2671,10 +2657,10 @@ class Resolver { for module_.children.each |_atom, child_name_bindings| { alt (*child_name_bindings).get_module_if_available() { - none { + none => { // Nothing to do. } - some(child_module) { + some(child_module) => { self.record_exports_for_module_subtree(child_module); } } @@ -2700,16 +2686,16 @@ class Resolver { name, namespace, Xray) { - NoNameDefinition { + NoNameDefinition => { // Nothing to do. } - ChildNameDefinition(target_def) { + ChildNameDefinition(target_def) => { vec::push(exports, { reexp: false, id: def_id_of_def(target_def) }); } - ImportNameDefinition(target_def) { + ImportNameDefinition(target_def) => { vec::push(exports, { reexp: true, id: def_id_of_def(target_def) @@ -2738,13 +2724,13 @@ class Resolver { // resolve implementations for external crates. alt module_.def_id { - some(def_id) if def_id.crate == local_crate { + some(def_id) if def_id.crate == local_crate => { // OK. Continue. } - none { + none => { // Resolve implementation scopes for the root module. } - some(_) { + some(_) => { // Bail out. debug!{"(building impl scopes for module subtree) not \ resolving implementations for `%s`", @@ -2757,10 +2743,10 @@ class Resolver { for module_.children.each |_atom, child_name_bindings| { alt (*child_name_bindings).get_module_if_available() { - none { + none => { // Nothing to do. } - some(child_module) { + some(child_module) => { self.build_impl_scopes_for_module_subtree(child_module); } } @@ -2803,11 +2789,11 @@ class Resolver { // Determine the parent's implementation scope. let mut parent_impl_scopes; alt module_.parent_link { - NoParentLink { + NoParentLink => { parent_impl_scopes = @nil; } ModuleParentLink(parent_module_node, _) | - BlockParentLink(parent_module_node, _) { + BlockParentLink(parent_module_node, _) => { parent_impl_scopes = parent_module_node.impl_scopes; } } @@ -2845,25 +2831,25 @@ class Resolver { // Move down in the graph. alt name { - none { + none => { // Nothing to do. } - some(name) { + some(name) => { alt orig_module.children.find(name) { - none { + none => { debug!{"!!! (with scope) didn't find `%s` in `%s`", *(*self.atom_table).atom_to_str(name), self.module_to_str(orig_module)}; } - some(name_bindings) { + some(name_bindings) => { alt (*name_bindings).get_module_if_available() { - none { + none => { debug!{"!!! (with scope) didn't find module \ for `%s` in `%s`", *(*self.atom_table).atom_to_str(name), self.module_to_str(orig_module)}; } - some(module_) { + some(module_) => { self.current_module = module_; } } @@ -2889,20 +2875,20 @@ class Resolver { alt def_like { dl_def(d @ def_local(*)) | dl_def(d @ def_upvar(*)) | - dl_def(d @ def_arg(*)) | dl_def(d @ def_binding(*)) { + dl_def(d @ def_arg(*)) | dl_def(d @ def_binding(*)) => { def = d; is_ty_param = false; } - dl_def(d @ def_ty_param(*)) { + dl_def(d @ def_ty_param(*)) => { def = d; is_ty_param = true; } dl_def(d @ def_self(*)) - if allow_capturing_self == DontAllowCapturingSelf { + if allow_capturing_self == DontAllowCapturingSelf => { def = d; is_ty_param = false; } - _ { + _ => { return some(def_like); } } @@ -2911,25 +2897,25 @@ class Resolver { while rib_index < (*ribs).len() { let rib = (*ribs).get_elt(rib_index); alt rib.kind { - NormalRibKind { + NormalRibKind => { // Nothing to do. Continue. } - FunctionRibKind(function_id) { + FunctionRibKind(function_id) => { if !is_ty_param { def = def_upvar(def_id_of_def(def).node, @def, function_id); } } - MethodRibKind(item_id, method_id) { + MethodRibKind(item_id, method_id) => { // If the def is a ty param, and came from the parent // item, it's ok alt def { def_ty_param(did, _) if self.def_map.find(copy(did.node)) - == some(def_typaram_binder(item_id)) { + == some(def_typaram_binder(item_id)) => { // ok } - _ { + _ => { if !is_ty_param { // This was an attempt to access an upvar inside a // named function item. This is not allowed, so we @@ -2951,7 +2937,7 @@ class Resolver { } } } - OpaqueFunctionRibKind { + OpaqueFunctionRibKind => { if !is_ty_param { // This was an attempt to access an upvar inside a // named function item. This is not allowed, so we @@ -2991,11 +2977,11 @@ class Resolver { i -= 1u; let rib = (*ribs).get_elt(i); alt rib.bindings.find(name) { - some(def_like) { + some(def_like) => { return self.upvarify(ribs, i, def_like, span, allow_capturing_self); } - none { + none => { // Continue. } } @@ -3044,7 +3030,7 @@ class Resolver { alt item.node { item_enum(_, type_parameters) | - item_ty(_, type_parameters) { + item_ty(_, type_parameters) => { do self.with_type_parameter_rib (HasTypeParameters(&type_parameters, item.id, 0u, NormalRibKind)) @@ -3055,7 +3041,7 @@ class Resolver { } item_impl(type_parameters, implemented_traits, self_type, - methods) { + methods) => { self.resolve_implementation(item.id, item.span, type_parameters, @@ -3063,7 +3049,7 @@ class Resolver { self_type, methods, visitor); } - item_trait(type_parameters, traits, methods) { + item_trait(type_parameters, traits, methods) => { // Create a new rib for the self type. let self_type_rib = @Rib(NormalRibKind); (*self.type_ribs).push(self_type_rib); @@ -3105,7 +3091,7 @@ class Resolver { // XXX: Do we need a node ID here? alt method { - required(ty_m) { + required(ty_m) => { do self.with_type_parameter_rib (HasTypeParameters(&ty_m.tps, item.id, @@ -3124,7 +3110,7 @@ class Resolver { self.resolve_type(ty_m.decl.output, visitor); } } - provided(m) { + provided(m) => { self.resolve_method(MethodRibKind(item.id, Provided(m.id)), m, @@ -3139,7 +3125,7 @@ class Resolver { } item_class(ty_params, traits, class_members, - optional_constructor, optional_destructor) { + optional_constructor, optional_destructor) => { self.resolve_class(item.id, @copy ty_params, @@ -3150,7 +3136,7 @@ class Resolver { visitor); } - item_mod(module_) { + item_mod(module_) => { let atom = (*self.atom_table).intern(item.ident); do self.with_scope(some(atom)) { self.resolve_module(module_, item.span, item.ident, @@ -3158,12 +3144,12 @@ class Resolver { } } - item_foreign_mod(foreign_module) { + item_foreign_mod(foreign_module) => { let atom = (*self.atom_table).intern(item.ident); do self.with_scope(some(atom)) { for foreign_module.items.each |foreign_item| { alt foreign_item.node { - foreign_item_fn(_, type_parameters) { + foreign_item_fn(_, type_parameters) => { do self.with_type_parameter_rib (HasTypeParameters(&type_parameters, foreign_item.id, @@ -3180,7 +3166,7 @@ class Resolver { } } - item_fn(fn_decl, ty_params, block) { + item_fn(fn_decl, ty_params, block) => { // If this is the main function, we must record it in the // session. // @@ -3207,11 +3193,11 @@ class Resolver { visitor); } - item_const(*) { + item_const(*) => { visit_item(item, (), visitor); } - item_mac(*) { + item_mac(*) => { fail ~"item macros unimplemented" } } @@ -3222,7 +3208,7 @@ class Resolver { fn with_type_parameter_rib(type_parameters: TypeParameters, f: fn()) { alt type_parameters { HasTypeParameters(type_parameters, node_id, initial_index, - rib_kind) { + rib_kind) => { let function_type_rib = @Rib(rib_kind); (*self.type_ribs).push(function_type_rib); @@ -3243,7 +3229,7 @@ class Resolver { } } - NoTypeParameters { + NoTypeParameters => { // Nothing to do. } } @@ -3251,11 +3237,11 @@ class Resolver { f(); alt type_parameters { - HasTypeParameters(type_parameters, _, _, _) { + HasTypeParameters(type_parameters, _, _, _) => { (*self.type_ribs).pop(); } - NoTypeParameters { + NoTypeParameters =>{ // Nothing to do. } } @@ -3271,22 +3257,22 @@ class Resolver { // Check each element of the capture clause. alt capture_clause { - NoCaptureClause { + NoCaptureClause => { // Nothing to do. } - HasCaptureClause(capture_clause) { + HasCaptureClause(capture_clause) => { // Resolve each captured item. for (*capture_clause).each |capture_item| { alt self.resolve_identifier(capture_item.name, ValueNS, true, capture_item.span) { - none { + none => { self.session.span_err(capture_item.span, ~"unresolved name in \ capture clause"); } - some(def) { + some(def) => { self.record_def(capture_item.id, def); } } @@ -3302,20 +3288,20 @@ class Resolver { do self.with_type_parameter_rib(type_parameters) { // Resolve the type parameters. alt type_parameters { - NoTypeParameters { + NoTypeParameters => { // Continue. } - HasTypeParameters(type_parameters, _, _, _) { + HasTypeParameters(type_parameters, _, _, _) => { self.resolve_type_parameters(*type_parameters, visitor); } } // Add self to the rib, if necessary. alt self_binding { - NoSelfBinding { + NoSelfBinding => { // Nothing to do. } - HasSelfBinding(self_node_id) { + HasSelfBinding(self_node_id) => { let def_like = dl_def(def_self(self_node_id)); (*function_value_rib).bindings.insert(self.self_atom, def_like); @@ -3324,10 +3310,10 @@ class Resolver { // Add each argument to the rib. alt optional_declaration { - none { + none => { // Nothing to do. } - some(declaration) { + some(declaration) => { for declaration.inputs.each |argument| { let name = (*self.atom_table).intern(argument.ident); let def_like = dl_def(def_arg(argument.id, @@ -3359,10 +3345,10 @@ class Resolver { for type_parameters.each |type_parameter| { for (*type_parameter.bounds).each |bound| { alt bound { - bound_copy | bound_send | bound_const | bound_owned { + bound_copy | bound_send | bound_const | bound_owned => { // Nothing to do. } - bound_trait(trait_type) { + bound_trait(trait_type) => { self.resolve_type(trait_type, visitor); } } @@ -3394,12 +3380,12 @@ class Resolver { // Resolve implemented traits. for traits.each |trt| { alt self.resolve_path(trt.path, TypeNS, true, visitor) { - none { + none => { self.session.span_err(trt.path.span, ~"attempt to implement a \ nonexistent trait"); } - some(def) { + some(def) => { // Write a mapping from the trait ID to the // definition of the trait into the definition // map. @@ -3419,14 +3405,14 @@ class Resolver { // Resolve methods. for class_members.each |class_member| { alt class_member.node { - class_method(method) { + class_method(method) => { self.resolve_method(MethodRibKind(id, Provided(method.id)), method, outer_type_parameter_count, visitor); } - instance_var(_, field_type, _, _, _) { + instance_var(_, field_type, _, _, _) => { self.resolve_type(field_type, visitor); } } @@ -3451,10 +3437,10 @@ class Resolver { // Resolve the destructor, if applicable. alt optional_destructor { - none { + none => { // Nothing to do. } - some(destructor) { + some(destructor) => { self.resolve_function(NormalRibKind, none, NoTypeParameters, @@ -3514,12 +3500,12 @@ class Resolver { for trait_references.each |trait_reference| { alt self.resolve_path(trait_reference.path, TypeNS, true, visitor) { - none { + none => { self.session.span_err(span, ~"attempt to implement an \ unknown trait"); } - some(def) { + some(def) => { self.record_def(trait_reference.ref_id, def); // Record the current trait reference. @@ -3581,10 +3567,10 @@ class Resolver { // Resolve the initializer, if necessary. alt local.node.init { - none { + none => { // Nothing to do. } - some(initializer) { + some(initializer) => { self.resolve_expr(initializer.expr, visitor); } } @@ -3654,8 +3640,8 @@ class Resolver { // Move down in the graph, if there's an anonymous module rooted here. let orig_module = self.current_module; alt self.current_module.anonymous_children.find(block.node.id) { - none { /* Nothing to do. */ } - some(anonymous_module) { + none => { /* Nothing to do. */ } + some(anonymous_module) => { debug!{"(resolving block) found anonymous module, moving \ down"}; self.current_module = anonymous_module; @@ -3677,27 +3663,27 @@ class Resolver { // Like path expressions, the interpretation of path types depends // on whether the path has multiple elements in it or not. - ty_path(path, path_id) { + ty_path(path, path_id) => { // This is a path in the type namespace. Walk through scopes // scopes looking for it. let mut result_def; alt self.resolve_path(path, TypeNS, true, visitor) { - some(def) { + some(def) => { debug!{"(resolving type) resolved `%s` to type", *path.idents.last()}; result_def = some(def); } - none { + none => { result_def = none; } } alt result_def { - some(_) { + some(_) => { // Continue. } - none { + none => { // Check to see whether the name is a primitive type. if path.idents.len() == 1u { let name = @@ -3707,11 +3693,11 @@ class Resolver { .primitive_types .find(name) { - some(primitive_type) { + some(primitive_type) => { result_def = some(def_prim_ty(primitive_type)); } - none { + none => { // Continue. } } @@ -3720,7 +3706,7 @@ class Resolver { } alt copy result_def { - some(def) { + some(def) => { // Write the result into the def map. debug!{"(resolving type) writing resolution for `%s` \ (id %d)", @@ -3728,7 +3714,7 @@ class Resolver { path_id}; self.record_def(path_id, def); } - none { + none => { self.session.span_err (ty.span, fmt!{"use of undeclared type name `%s`", connect(path.idents.map(|x| *x), @@ -3737,7 +3723,7 @@ class Resolver { } } - _ { + _ => { // Just resolve embedded types. visit_ty(ty, (), visitor); } @@ -3798,13 +3784,13 @@ class Resolver { let is_mutable = mutability == Mutable; let def = alt mode { - RefutableMode { + RefutableMode => { // For pattern arms, we must use // `def_binding` definitions. def_binding(pattern.id, binding_mode) } - IrrefutableMode { + IrrefutableMode => { // But for locals, we use `def_local`. def_local(pattern.id, is_mutable) } @@ -3824,13 +3810,13 @@ class Resolver { alt bindings_list { some(bindings_list) - if !bindings_list.contains_key(atom) { + if !bindings_list.contains_key(atom) => { let last_rib = (*self.value_ribs).last(); last_rib.bindings.insert(atom, dl_def(def)); bindings_list.insert(atom, pat_id); } - some(b) { + some(b) => { if b.find(atom) == some(pat_id) { // Then this is a duplicate variable // in the same disjunct, which is an @@ -3842,7 +3828,7 @@ class Resolver { } // Not bound in the same pattern: do nothing } - none { + none => { let last_rib = (*self.value_ribs).last(); last_rib.bindings.insert(atom, dl_def(def)); @@ -3860,16 +3846,16 @@ class Resolver { pat_ident(_, path, _) | pat_enum(path, _) => { // These two must be enum variants. alt self.resolve_path(path, ValueNS, false, visitor) { - some(def @ def_variant(*)) { + some(def @ def_variant(*)) => { self.record_def(pattern.id, def); } - some(_) { + some(_) => { self.session.span_err(path.span, fmt!{"not an enum \ variant: %s", *path.idents.last()}); } - none { + none => { self.session.span_err(path.span, ~"unresolved enum variant"); } @@ -3904,29 +3890,29 @@ class Resolver { name, ValueNS) { - Success(target) { + Success(target) => { alt target.bindings.value_def { - none { + none => { fail ~"resolved name in the value namespace to a set \ of name bindings with no def?!"; } - some(def @ def_variant(*)) { + some(def @ def_variant(*)) => { return FoundEnumVariant(def); } - some(def_const(*)) { + some(def_const(*)) => { return FoundConst; } - some(_) { + some(_) => { return EnumVariantOrConstNotFound; } } } - Indeterminate { + Indeterminate => { fail ~"unexpected indeterminate result"; } - Failed { + Failed => { return EnumVariantOrConstNotFound; } } @@ -3973,10 +3959,10 @@ class Resolver { alt self.resolve_identifier_in_local_ribs(identifier, namespace, span) { - some(def) { + some(def) => { return some(def); } - none { + none => { // Continue. } } @@ -4002,34 +3988,34 @@ class Resolver { // First, search children. alt containing_module.children.find(name) { - some(child_name_bindings) { + some(child_name_bindings) => { alt (*child_name_bindings).def_for_namespace(namespace) { - some(def) { + some(def) => { // Found it. Stop the search here. return ChildNameDefinition(def); } - none { + none => { // Continue. } } } - none { + none => { // Continue. } } // Next, search import resolutions. alt containing_module.import_resolutions.find(name) { - some(import_resolution) { + some(import_resolution) => { alt (*import_resolution).target_for_namespace(namespace) { - some(target) { + some(target) => { alt (*target.bindings).def_for_namespace(namespace) { - some(def) { + some(def) => { // Found it. import_resolution.used = true; return ImportNameDefinition(def); } - none { + none => { // This can happen with external impls, due to // the imperfect way we read the metadata. @@ -4037,12 +4023,12 @@ class Resolver { } } } - none { + none => { return NoNameDefinition; } } } - none { + none => { return NoNameDefinition; } } @@ -4074,7 +4060,7 @@ class Resolver { xray, path.span) { - Failed { + Failed => { self.session.span_err(path.span, fmt!{"use of undeclared module `%s`", *(*self.atom_table).atoms_to_str @@ -4082,11 +4068,11 @@ class Resolver { return none; } - Indeterminate { + Indeterminate => { fail ~"indeterminate unexpected"; } - Success(resulting_module) { + Success(resulting_module) => { containing_module = resulting_module; } } @@ -4096,7 +4082,7 @@ class Resolver { name, namespace, xray) { - NoNameDefinition { + NoNameDefinition => { // We failed to resolve the name. Report an error. self.session.span_err(path.span, fmt!{"unresolved name: %s::%s", @@ -4106,7 +4092,7 @@ class Resolver { (name)}); return none; } - ChildNameDefinition(def) | ImportNameDefinition(def) { + ChildNameDefinition(def) | ImportNameDefinition(def) => { return some(def); } } @@ -4128,7 +4114,7 @@ class Resolver { xray, path.span) { - Failed { + Failed => { self.session.span_err(path.span, fmt!{"use of undeclared module `::%s`", *(*self.atom_table).atoms_to_str @@ -4136,11 +4122,11 @@ class Resolver { return none; } - Indeterminate { + Indeterminate => { fail ~"indeterminate unexpected"; } - Success(resulting_module) { + Success(resulting_module) => { containing_module = resulting_module; } } @@ -4150,7 +4136,7 @@ class Resolver { name, namespace, xray) { - NoNameDefinition { + NoNameDefinition => { // We failed to resolve the name. Report an error. self.session.span_err(path.span, fmt!{"unresolved name: %s::%s", @@ -4160,7 +4146,7 @@ class Resolver { (name)}); return none; } - ChildNameDefinition(def) | ImportNameDefinition(def) { + ChildNameDefinition(def) | ImportNameDefinition(def) => { return some(def); } } @@ -4176,28 +4162,28 @@ class Resolver { // Check the local set of ribs. let mut search_result; alt namespace { - ValueNS { + ValueNS => { search_result = self.search_ribs(self.value_ribs, name, span, DontAllowCapturingSelf); } - TypeNS { + TypeNS => { search_result = self.search_ribs(self.type_ribs, name, span, AllowCapturingSelf); } - ModuleNS | ImplNS { + ModuleNS | ImplNS => { fail ~"module or impl namespaces do not have local ribs"; } } alt copy search_result { - some(dl_def(def)) { + some(dl_def(def)) => { debug!{"(resolving path in local ribs) resolved `%s` to \ local: %?", *(*self.atom_table).atom_to_str(name), def}; return some(def); } - some(dl_field) | some(dl_impl(_)) | none { + some(dl_field) | some(dl_impl(_)) | none => { return none; } } @@ -4214,13 +4200,13 @@ class Resolver { name, namespace) { - Success(target) { + Success(target) => { alt (*target.bindings).def_for_namespace(namespace) { - none { + none => { fail ~"resolved name in a namespace to a set of name \ bindings with no def for that namespace?!"; } - some(def) { + some(def) => { debug!{"(resolving item path in lexical scope) \ resolved `%s` to item", *(*self.atom_table).atom_to_str(name)}; @@ -4228,10 +4214,10 @@ class Resolver { } } } - Indeterminate { + Indeterminate => { fail ~"unexpected indeterminate result"; } - Failed { + Failed => { return none; } } @@ -4253,18 +4239,18 @@ class Resolver { // The interpretation of paths depends on whether the path has // multiple elements in it or not. - expr_path(path) { + expr_path(path) => { // This is a local path in the value namespace. Walk through // scopes looking for it. alt self.resolve_path(path, ValueNS, true, visitor) { - some(def) { + some(def) => { // Write the result into the def map. debug!{"(resolving expr) resolved `%s`", connect(path.idents.map(|x| *x), ~"::")}; self.record_def(expr.id, def); } - none { + none => { self.session.span_err(expr.span, fmt!{"unresolved name: %s", connect(path.idents.map(|x| *x), @@ -4276,7 +4262,7 @@ class Resolver { } expr_fn(_, fn_decl, block, capture_clause) | - expr_fn_block(fn_decl, block, capture_clause) { + expr_fn_block(fn_decl, block, capture_clause) => { self.resolve_function(FunctionRibKind(expr.id), some(@fn_decl), NoTypeParameters, @@ -4286,7 +4272,7 @@ class Resolver { visitor); } - expr_struct(path, _) { + expr_struct(path, _) => { // Resolve the path to the structure it goes to. // // XXX: We might want to support explicit type parameters in @@ -4304,13 +4290,13 @@ class Resolver { alt self.resolve_path(path, TypeNS, false, visitor) { some(definition @ def_ty(class_id)) - if self.structs.contains_key(class_id) { + if self.structs.contains_key(class_id) => { let has_constructor = self.structs.get(class_id); let class_def = def_class(class_id, has_constructor); self.record_def(expr.id, class_def); } - _ { + _ => { self.session.span_err(path.span, fmt!{"`%s` does not name a \ structure", @@ -4323,7 +4309,7 @@ class Resolver { visit_expr(expr, (), visitor); } - _ { + _ => { visit_expr(expr, (), visitor); } } @@ -4332,11 +4318,11 @@ class Resolver { fn record_impls_for_expr_if_necessary(expr: @expr) { alt expr.node { expr_field(*) | expr_path(*) | expr_cast(*) | expr_binary(*) | - expr_unary(*) | expr_assign_op(*) | expr_index(*) { + expr_unary(*) | expr_assign_op(*) | expr_index(*) => { self.impl_map.insert(expr.id, self.current_module.impl_scopes); } - _ { + _ => { // Nothing to do. } } @@ -4393,7 +4379,7 @@ class Resolver { self.add_fixed_trait_for_expr(expr.id, self.lang_items.neg_trait); } - expr_index(*) { + expr_index(*) => { self.add_fixed_trait_for_expr(expr.id, self.lang_items.index_trait); } @@ -4409,13 +4395,13 @@ class Resolver { loop { // Look for the current trait. alt copy self.current_trait_refs { - some(trait_def_ids) { + some(trait_def_ids) => { for trait_def_ids.each |trait_def_id| { self.add_trait_info_if_containing_method (found_traits, trait_def_id, name); } } - none { + none => { // Nothing to do. } } @@ -4423,12 +4409,12 @@ class Resolver { // Look for trait children. for search_module.children.each |_name, child_name_bindings| { alt child_name_bindings.def_for_namespace(TypeNS) { - some(def_ty(trait_def_id)) { + some(def_ty(trait_def_id)) => { self.add_trait_info_if_containing_method(found_traits, trait_def_id, name); } - some(_) | none { + some(_) | none => { // Continue. } } @@ -4439,16 +4425,16 @@ class Resolver { |_atom, import_resolution| { alt import_resolution.target_for_namespace(TypeNS) { - none { + none => { // Continue. } - some(target) { + some(target) => { alt target.bindings.def_for_namespace(TypeNS) { - some(def_ty(trait_def_id)) { + some(def_ty(trait_def_id)) => { self.add_trait_info_if_containing_method (found_traits, trait_def_id, name); } - some(_) | none { + some(_) | none => { // Continue. } } @@ -4458,12 +4444,12 @@ class Resolver { // Move to the next parent. alt search_module.parent_link { - NoParentLink { + NoParentLink => { // Done. break; } ModuleParentLink(parent_module, _) | - BlockParentLink(parent_module, _) { + BlockParentLink(parent_module, _) => { search_module = parent_module; } } @@ -4477,7 +4463,7 @@ class Resolver { name: Atom) { alt self.trait_info.find(trait_def_id) { - some(trait_info) if trait_info.contains_key(name) { + some(trait_info) if trait_info.contains_key(name) => { debug!{"(adding trait info if containing method) found trait \ %d:%d for method '%s'", trait_def_id.crate, @@ -4485,7 +4471,7 @@ class Resolver { *(*self.atom_table).atom_to_str(name)}; (*found_traits).push(trait_def_id); } - some(_) | none { + some(_) | none => { // Continue. } } @@ -4523,13 +4509,13 @@ class Resolver { // for unused imports in external crates. alt module_.def_id { - some(def_id) if def_id.crate == local_crate { + some(def_id) if def_id.crate == local_crate => { // OK. Continue. } - none { + none => { // Check for unused imports in the root module. } - some(_) { + some(_) => { // Bail out. debug!{"(checking for unused imports in module subtree) not \ checking for unused imports for `%s`", @@ -4542,10 +4528,10 @@ class Resolver { for module_.children.each |_atom, child_name_bindings| { alt (*child_name_bindings).get_module_if_available() { - none { + none => { // Nothing to do. } - some(child_module) { + some(child_module) => { self.check_for_unused_imports_in_module_subtree (child_module); } @@ -4561,15 +4547,15 @@ class Resolver { for module_.import_resolutions.each |_impl_name, import_resolution| { if !import_resolution.used { alt self.unused_import_lint_level { - warn { + warn => { self.session.span_warn(import_resolution.span, ~"unused import"); } - deny | forbid { + deny | forbid => { self.session.span_err(import_resolution.span, ~"unused import"); } - allow { + allow => { self.session.span_bug(import_resolution.span, ~"shouldn't be here if lint \ is allowed"); @@ -4592,14 +4578,14 @@ class Resolver { let mut current_module = module_; loop { alt current_module.parent_link { - NoParentLink { + NoParentLink => { break; } - ModuleParentLink(module_, name) { + ModuleParentLink(module_, name) => { atoms.push(name); current_module = module_; } - BlockParentLink(module_, node_id) { + BlockParentLink(module_, node_id) => { atoms.push((*self.atom_table).intern(@~"<opaque>")); current_module = module_; } @@ -4639,8 +4625,8 @@ class Resolver { for module_.import_resolutions.each |name, import_resolution| { let mut module_repr; alt (*import_resolution).target_for_namespace(ModuleNS) { - none { module_repr = ~""; } - some(target) { + none => { module_repr = ~""; } + some(target) => { module_repr = ~" module:?"; // XXX } @@ -4648,8 +4634,8 @@ class Resolver { let mut value_repr; alt (*import_resolution).target_for_namespace(ValueNS) { - none { value_repr = ~""; } - some(target) { + none => { value_repr = ~""; } + some(target) => { value_repr = ~" value:?"; // XXX } @@ -4657,8 +4643,8 @@ class Resolver { let mut type_repr; alt (*import_resolution).target_for_namespace(TypeNS) { - none { type_repr = ~""; } - some(target) { + none => { type_repr = ~""; } + some(target) => { type_repr = ~" type:?"; // XXX } @@ -4666,8 +4652,8 @@ class Resolver { let mut impl_repr; alt (*import_resolution).target_for_namespace(ImplNS) { - none { impl_repr = ~""; } - some(target) { + none => { impl_repr = ~""; } + some(target) => { impl_repr = ~" impl:?"; // XXX } @@ -4686,7 +4672,7 @@ class Resolver { let mut impl_scopes = impl_scopes; loop { alt *impl_scopes { - cons(impl_scope, rest_impl_scopes) { + cons(impl_scope, rest_impl_scopes) => { debug!{"Impl scope %u:", i}; for (*impl_scope).each |implementation| { @@ -4696,7 +4682,7 @@ class Resolver { i += 1u; impl_scopes = rest_impl_scopes; } - nil { + nil => { break; } } diff --git a/src/rustc/middle/trans/alt.rs b/src/rustc/middle/trans/alt.rs index 539ec5d7e11..e3103cfefc6 100644 --- a/src/rustc/middle/trans/alt.rs +++ b/src/rustc/middle/trans/alt.rs @@ -26,13 +26,13 @@ enum opt { } fn opt_eq(tcx: ty::ctxt, a: opt, b: opt) -> bool { alt (a, b) { - (lit(a), lit(b)) { const_eval::compare_lit_exprs(tcx, a, b) == 0 } - (range(a1, a2), range(b1, b2)) { + (lit(a), lit(b)) => const_eval::compare_lit_exprs(tcx, a, b) == 0, + (range(a1, a2), range(b1, b2)) => { const_eval::compare_lit_exprs(tcx, a1, b1) == 0 && const_eval::compare_lit_exprs(tcx, a2, b2) == 0 } - (var(a, _), var(b, _)) { a == b } - _ { false } + (var(a, _), var(b, _)) => a == b, + _ => false } } @@ -45,11 +45,11 @@ fn trans_opt(bcx: block, o: opt) -> opt_result { let ccx = bcx.ccx(); let mut bcx = bcx; alt o { - lit(l) { + lit(l) => { alt l.node { ast::expr_vstore(@{node: ast::expr_lit( @{node: ast::lit_str(s), _}), _}, - ast::vstore_uniq) { + ast::vstore_uniq) => { let strty = ty::mk_estr(bcx.tcx(), ty::vstore_uniq); let cell = empty_dest_cell(); bcx = tvec::trans_estr(bcx, s, some(ast::vstore_uniq), @@ -57,16 +57,16 @@ fn trans_opt(bcx: block, o: opt) -> opt_result { add_clean_temp(bcx, *cell, strty); return single_result(rslt(bcx, *cell)); } - _ { + _ => { return single_result( rslt(bcx, consts::const_expr(ccx, l))); } } } - var(disr_val, _) { + var(disr_val, _) => { return single_result(rslt(bcx, C_int(ccx, disr_val))); } - range(l1, l2) { + range(l1, l2) => { return range_result(rslt(bcx, consts::const_expr(ccx, l1)), rslt(bcx, consts::const_expr(ccx, l2))); } @@ -113,8 +113,8 @@ type match_ = ~[match_branch]; fn has_nested_bindings(m: match_, col: uint) -> bool { for vec::each(m) |br| { alt br.pats[col].node { - ast::pat_ident(_, _, some(_)) { return true; } - _ {} + ast::pat_ident(_, _, some(_)) => return true, + _ => () } } return false; @@ -126,7 +126,7 @@ fn expand_nested_bindings(bcx: block, m: match_, col: uint, val: ValueRef) let mut result = ~[]; for vec::each(m) |br| { alt br.pats[col].node { - ast::pat_ident(mode, name, some(inner)) { + ast::pat_ident(mode, name, some(inner)) => { let pats = vec::append( vec::slice(br.pats, 0u, col), vec::append(~[inner], @@ -143,7 +143,7 @@ fn expand_nested_bindings(bcx: block, m: match_, col: uint, val: ValueRef) }}]) with *br}); } - _ { vec::push(result, br); } + _ => vec::push(result, br) } } result @@ -156,13 +156,14 @@ fn enter_match(bcx: block, dm: DefMap, m: match_, col: uint, val: ValueRef, let mut result = ~[]; for vec::each(m) |br| { alt e(br.pats[col]) { - some(sub) { + some(sub) => { let pats = vec::append( vec::append(sub, vec::view(br.pats, 0u, col)), vec::view(br.pats, col + 1u, br.pats.len())); let self = br.pats[col]; let bound = alt self.node { - ast::pat_ident(mode, name, none) if !pat_is_variant(dm, self) { + ast::pat_ident(mode, name, none) + if !pat_is_variant(dm, self) => { vec::append(br.bound, ~[{ident: path_to_ident(name), binding: binding { @@ -171,11 +172,11 @@ fn enter_match(bcx: block, dm: DefMap, m: match_, col: uint, val: ValueRef, ty: node_id_type(bcx, br.pats[col].id) }}]) } - _ { br.bound } + _ => br.bound }; vec::push(result, @{pats: pats, bound: bound with *br}); } - none { } + none => () } } return result; @@ -186,11 +187,9 @@ fn enter_default(bcx: block, dm: DefMap, m: match_, col: uint, val: ValueRef) do enter_match(bcx, dm, m, col, val) |p| { alt p.node { - ast::pat_wild | ast::pat_rec(_, _) | ast::pat_tup(_) { some(~[]) } - ast::pat_ident(_, _, none) if !pat_is_variant(dm, p) { - some(~[]) - } - _ { none } + ast::pat_wild | ast::pat_rec(_, _) | ast::pat_tup(_) => some(~[]), + ast::pat_ident(_, _, none) if !pat_is_variant(dm, p) => some(~[]), + _ => none } } } @@ -201,23 +200,23 @@ fn enter_opt(bcx: block, m: match_, opt: opt, col: uint, let dummy = @{id: 0, node: ast::pat_wild, span: dummy_sp()}; do enter_match(bcx, tcx.def_map, m, col, val) |p| { alt p.node { - ast::pat_enum(_, subpats) { + ast::pat_enum(_, subpats) => { if opt_eq(tcx, variant_opt(tcx, p.id), opt) { some(option::get_default(subpats, vec::from_elem(variant_size, dummy))) } else { none } } - ast::pat_ident(_, _, none) if pat_is_variant(tcx.def_map, p) { + ast::pat_ident(_, _, none) if pat_is_variant(tcx.def_map, p) => { if opt_eq(tcx, variant_opt(tcx, p.id), opt) { some(~[]) } else { none } } - ast::pat_lit(l) { + ast::pat_lit(l) => { if opt_eq(tcx, lit(l), opt) { some(~[]) } else { none } } - ast::pat_range(l1, l2) { + ast::pat_range(l1, l2) => { if opt_eq(tcx, range(l1, l2), opt) { some(~[]) } else { none } } - _ { some(vec::from_elem(variant_size, dummy)) } + _ => some(vec::from_elem(variant_size, dummy)) } } } @@ -227,7 +226,7 @@ fn enter_rec(bcx: block, dm: DefMap, m: match_, col: uint, let dummy = @{id: 0, node: ast::pat_wild, span: dummy_sp()}; do enter_match(bcx, dm, m, col, val) |p| { alt p.node { - ast::pat_rec(fpats, _) { + ast::pat_rec(fpats, _) => { let mut pats = ~[]; for vec::each(fields) |fname| { let mut pat = dummy; @@ -238,7 +237,7 @@ fn enter_rec(bcx: block, dm: DefMap, m: match_, col: uint, } some(pats) } - _ { some(vec::from_elem(fields.len(), dummy)) } + _ => some(vec::from_elem(fields.len(), dummy)) } } } @@ -248,8 +247,8 @@ fn enter_tup(bcx: block, dm: DefMap, m: match_, col: uint, val: ValueRef, let dummy = @{id: 0, node: ast::pat_wild, span: dummy_sp()}; do enter_match(bcx, dm, m, col, val) |p| { alt p.node { - ast::pat_tup(elts) { some(elts) } - _ { some(vec::from_elem(n_elts, dummy)) } + ast::pat_tup(elts) => some(elts), + _ => some(vec::from_elem(n_elts, dummy)) } } } @@ -259,8 +258,8 @@ fn enter_box(bcx: block, dm: DefMap, m: match_, col: uint, val: ValueRef) let dummy = @{id: 0, node: ast::pat_wild, span: dummy_sp()}; do enter_match(bcx, dm, m, col, val) |p| { alt p.node { - ast::pat_box(sub) { some(~[sub]) } - _ { some(~[dummy]) } + ast::pat_box(sub) => some(~[sub]), + _ => some(~[dummy]) } } } @@ -270,8 +269,8 @@ fn enter_uniq(bcx: block, dm: DefMap, m: match_, col: uint, val: ValueRef) let dummy = @{id: 0, node: ast::pat_wild, span: dummy_sp()}; do enter_match(bcx, dm, m, col, val) |p| { alt p.node { - ast::pat_uniq(sub) { some(~[sub]) } - _ { some(~[dummy]) } + ast::pat_uniq(sub) => some(~[sub]), + _ => some(~[dummy]) } } } @@ -289,11 +288,11 @@ fn get_options(ccx: @crate_ctxt, m: match_, col: uint) -> ~[opt] { add_to_set(ccx.tcx, found, variant_opt(ccx.tcx, br.pats[col].id)); } else { alt cur.node { - ast::pat_lit(l) { add_to_set(ccx.tcx, found, lit(l)); } - ast::pat_range(l1, l2) { + ast::pat_lit(l) => add_to_set(ccx.tcx, found, lit(l)), + ast::pat_range(l1, l2) => { add_to_set(ccx.tcx, found, range(l1, l2)); } - _ {} + _ => () } } } @@ -306,7 +305,7 @@ fn extract_variant_args(bcx: block, pat_id: ast::node_id, let _icx = bcx.insn_ctxt(~"alt::extract_variant_args"); let ccx = bcx.fcx.ccx; let enum_ty_substs = alt check ty::get(node_id_type(bcx, pat_id)).struct { - ty::ty_enum(id, substs) { assert id == vdefs.enm; substs.tps } + ty::ty_enum(id, substs) => { assert id == vdefs.enm; substs.tps } }; let mut blobptr = val; let variants = ty::enum_variants(ccx.tcx, vdefs.enm); @@ -330,14 +329,14 @@ fn collect_record_fields(m: match_, col: uint) -> ~[ast::ident] { let mut fields: ~[ast::ident] = ~[]; for vec::each(m) |br| { alt br.pats[col].node { - ast::pat_rec(fs, _) { + ast::pat_rec(fs, _) => { for vec::each(fs) |f| { if !vec::any(fields, |x| str::eq(f.ident, x)) { vec::push(fields, f.ident); } } } - _ { } + _ => () } } return fields; @@ -348,8 +347,8 @@ fn root_pats_as_necessary(bcx: block, m: match_, col: uint, val: ValueRef) { let pat_id = br.pats[col].id; alt bcx.ccx().maps.root_map.find({id:pat_id, derefs:0u}) { - none {} - some(scope_id) { + none => (), + some(scope_id) => { // Note: the scope_id will always be the id of the alt. See the // extended comment in rustc::middle::borrowck::preserve() for // details (look for the case covering cat_discr). @@ -365,21 +364,30 @@ fn root_pats_as_necessary(bcx: block, m: match_, col: uint, val: ValueRef) { fn any_box_pat(m: match_, col: uint) -> bool { for vec::each(m) |br| { - alt br.pats[col].node { ast::pat_box(_) { return true; } _ { } } + alt br.pats[col].node { + ast::pat_box(_) => return true, + _ => () + } } return false; } fn any_uniq_pat(m: match_, col: uint) -> bool { for vec::each(m) |br| { - alt br.pats[col].node { ast::pat_uniq(_) { return true; } _ { } } + alt br.pats[col].node { + ast::pat_uniq(_) => return true, + _ => () + } } return false; } fn any_tup_pat(m: match_, col: uint) -> bool { for vec::each(m) |br| { - alt br.pats[col].node { ast::pat_tup(_) { return true; } _ { } } + alt br.pats[col].node { + ast::pat_tup(_) => return true, + _ => () + } } return false; } @@ -390,9 +398,9 @@ type mk_fail = fn@() -> BasicBlockRef; fn pick_col(m: match_) -> uint { fn score(p: @ast::pat) -> uint { alt p.node { - ast::pat_lit(_) | ast::pat_enum(_, _) | ast::pat_range(_, _) { 1u } - ast::pat_ident(_, _, some(p)) { score(p) } - _ { 0u } + ast::pat_lit(_) | ast::pat_enum(_, _) | ast::pat_range(_, _) => 1u, + ast::pat_ident(_, _, some(p)) => score(p), + _ => 0u } } let scores = vec::to_mut(vec::from_elem(m[0].pats.len(), 0u)); @@ -428,7 +436,7 @@ fn compile_submatch(bcx: block, m: match_, vals: ~[ValueRef], if m[0].pats.len() == 0u { let data = m[0].data; alt data.guard { - some(e) { + some(e) => { // Temporarily set bindings. They'll be rewritten to PHI nodes // for the actual arm block. // @@ -460,7 +468,7 @@ fn compile_submatch(bcx: block, m: match_, vals: ~[ValueRef], bcx }; } - _ { } + _ => () } if !bcx.unreachable { vec::push(exits, {bound: m[0].bound, from: bcx.llbb, @@ -505,8 +513,8 @@ fn compile_submatch(bcx: block, m: match_, vals: ~[ValueRef], if any_tup_pat(m, col) { let tup_ty = node_id_type(bcx, pat_id); let n_tup_elts = alt ty::get(tup_ty).struct { - ty::ty_tup(elts) { elts.len() } - _ { ccx.sess.bug(~"non-tuple type in tuple pattern"); } + ty::ty_tup(elts) => elts.len(), + _ => ccx.sess.bug(~"non-tuple type in tuple pattern") }; let mut tup_vals = ~[], i = 0u; while i < n_tup_elts { @@ -546,7 +554,7 @@ fn compile_submatch(bcx: block, m: match_, vals: ~[ValueRef], let mut test_val = val; if opts.len() > 0u { alt opts[0] { - var(_, vdef) { + var(_, vdef) => { if (*ty::enum_variants(tcx, vdef.enm)).len() == 1u { kind = single; } else { @@ -557,13 +565,13 @@ fn compile_submatch(bcx: block, m: match_, vals: ~[ValueRef], kind = switch; } } - lit(l) { + lit(l) => { test_val = Load(bcx, val); let pty = node_id_type(bcx, pat_id); kind = if ty::type_is_integral(pty) { switch } else { compare }; } - range(_, _) { + range(_, _) => { test_val = Load(bcx, val); kind = compare; } @@ -571,13 +579,13 @@ fn compile_submatch(bcx: block, m: match_, vals: ~[ValueRef], } for vec::each(opts) |o| { alt o { - range(_, _) { kind = compare; break; } - _ { } + range(_, _) => { kind = compare; break } + _ => () } } let else_cx = alt kind { - no_branch | single { bcx } - _ { sub_block(bcx, ~"match_else") } + no_branch | single => bcx, + _ => sub_block(bcx, ~"match_else") }; let sw = if kind == switch { Switch(bcx, test_val, else_cx.llbb, opts.len()) @@ -594,24 +602,25 @@ fn compile_submatch(bcx: block, m: match_, vals: ~[ValueRef], if !exhaustive || i < len { opt_cx = sub_block(bcx, ~"match_case"); alt kind { - single { Br(bcx, opt_cx.llbb); } - switch { + single => Br(bcx, opt_cx.llbb), + switch => { alt check trans_opt(bcx, opt) { - single_result(r) { + single_result(r) => { llvm::LLVMAddCase(sw, r.val, opt_cx.llbb); bcx = r.bcx; } } } - compare { + compare => { let t = node_id_type(bcx, pat_id); let {bcx: after_cx, val: matches} = { do with_scope_result(bcx, none, ~"compare_scope") |bcx| { alt trans_opt(bcx, opt) { - single_result({bcx, val}) { + single_result({bcx, val}) => { trans_compare(bcx, ast::eq, test_val, t, val, t) } - range_result({val: vbegin, _}, {bcx, val: vend}) { + range_result( + {val: vbegin, _}, {bcx, val: vend}) => { let {bcx, val: llge} = trans_compare( bcx, ast::ge, test_val, t, vbegin, t); let {bcx, val: llle} = trans_compare( @@ -624,19 +633,19 @@ fn compile_submatch(bcx: block, m: match_, vals: ~[ValueRef], bcx = sub_block(after_cx, ~"compare_next"); CondBr(after_cx, matches, opt_cx.llbb, bcx.llbb); } - _ { } + _ => () } } else if kind == compare { Br(bcx, else_cx.llbb); } let mut size = 0u; let mut unpacked = ~[]; alt opt { - var(_, vdef) { + var(_, vdef) => { let args = extract_variant_args(opt_cx, pat_id, vdef, val); size = args.vals.len(); unpacked = args.vals; opt_cx = args.bcx; } - lit(_) | range(_, _) { } + lit(_) | range(_, _) => () } compile_submatch(opt_cx, enter_opt(bcx, m, opt, col, size, val), vec::append(unpacked, vals_left), chk, exits); @@ -663,11 +672,11 @@ fn make_phi_bindings(bcx: block, map: ~[exit_node], for vec::each(map) |ex| { if ex.to as uint == our_block { alt assoc(name, ex.bound) { - some(binding) { + some(binding) => { vec::push(llbbs, ex.from); vec::push(vals, binding.val); } - none { } + none => () } } } @@ -765,7 +774,7 @@ fn trans_alt_inner(scope_cx: block, expr: @ast::expr, arms: ~[ast::arm], fn mk_fail(bcx: block, sp: span, msg: ~str, done: @mut option<BasicBlockRef>) -> BasicBlockRef { - alt *done { some(bb) { return bb; } _ { } } + alt *done { some(bb) => return bb, _ => () } let fail_cx = sub_block(bcx, ~"case_fallthrough"); trans_fail(fail_cx, some(sp), msg); *done = some(fail_cx.llbb); @@ -773,13 +782,13 @@ fn trans_alt_inner(scope_cx: block, expr: @ast::expr, arms: ~[ast::arm], } let t = node_id_type(bcx, expr.id); let mk_fail = alt mode { - ast::alt_check { + ast::alt_check => { let fail_cx = @mut none; // Cached fail-on-fallthrough block some(|| mk_fail(scope_cx, expr.span, ~"non-exhaustive match failure", fail_cx)) } - ast::alt_exhaustive { + ast::alt_exhaustive => { let fail_cx = @mut none; // special case for uninhabited type if ty::type_is_empty(tcx, t) { @@ -821,7 +830,7 @@ fn bind_irrefutable_pat(bcx: block, pat: @ast::pat, val: ValueRef, // Necessary since bind_irrefutable_pat is called outside trans_alt alt pat.node { - ast::pat_ident(_, _,inner) { + ast::pat_ident(_, _,inner) => { if pat_is_variant(bcx.tcx().def_map, pat) { return bcx; } if make_copy { let ty = node_id_type(bcx, pat.id); @@ -833,11 +842,11 @@ fn bind_irrefutable_pat(bcx: block, pat: @ast::pat, val: ValueRef, add_clean(bcx, alloc, ty); } else { bcx.fcx.lllocals.insert(pat.id, local_mem(val)); } alt inner { - some(pat) { bcx = bind_irrefutable_pat(bcx, pat, val, true); } - _ {} + some(pat) => { bcx = bind_irrefutable_pat(bcx, pat, val, true); } + _ => () } } - ast::pat_enum(_, sub) { + ast::pat_enum(_, sub) => { let vdefs = ast_util::variant_def_ids(ccx.tcx.def_map.get(pat.id)); let args = extract_variant_args(bcx, pat.id, vdefs, val); let mut i = 0; @@ -846,7 +855,7 @@ fn bind_irrefutable_pat(bcx: block, pat: @ast::pat, val: ValueRef, i += 1; }} } - ast::pat_rec(fields, _) { + ast::pat_rec(fields, _) => { let rec_fields = ty::get_fields(node_id_type(bcx, pat.id)); for vec::each(fields) |f| { let ix = option::get(ty::field_idx(f.ident, rec_fields)); @@ -854,7 +863,7 @@ fn bind_irrefutable_pat(bcx: block, pat: @ast::pat, val: ValueRef, bcx = bind_irrefutable_pat(bcx, f.pat, fldptr, make_copy); } } - ast::pat_tup(elems) { + ast::pat_tup(elems) => { let mut i = 0u; for vec::each(elems) |elem| { let fldptr = GEPi(bcx, val, ~[0u, i]); @@ -862,19 +871,19 @@ fn bind_irrefutable_pat(bcx: block, pat: @ast::pat, val: ValueRef, i += 1u; } } - ast::pat_box(inner) { + ast::pat_box(inner) => { let llbox = Load(bcx, val); let unboxed = GEPi(bcx, llbox, ~[0u, abi::box_field_body]); bcx = bind_irrefutable_pat(bcx, inner, unboxed, true); } - ast::pat_uniq(inner) { + ast::pat_uniq(inner) => { let llbox = Load(bcx, val); let unboxed = GEPi(bcx, llbox, ~[0u, abi::box_field_body]); bcx = bind_irrefutable_pat(bcx, inner, unboxed, true); } - ast::pat_wild | ast::pat_lit(_) | ast::pat_range(_, _) { } + ast::pat_wild | ast::pat_lit(_) | ast::pat_range(_, _) => () } return bcx; } diff --git a/src/rustc/middle/trans/base.rs b/src/rustc/middle/trans/base.rs index 13f3cf72f5f..6df45f75adb 100644 --- a/src/rustc/middle/trans/base.rs +++ b/src/rustc/middle/trans/base.rs @@ -67,9 +67,9 @@ enum dest { fn dest_str(ccx: @crate_ctxt, d: dest) -> ~str { alt d { - by_val(v) { fmt!{"by_val(%s)", val_str(ccx.tn, *v)} } - save_in(v) { fmt!{"save_in(%s)", val_str(ccx.tn, v)} } - ignore { ~"ignore" } + by_val(v) => fmt!{"by_val(%s)", val_str(ccx.tn, *v)}, + save_in(v) => fmt!{"save_in(%s)", val_str(ccx.tn, v)}, + ignore => ~"ignore" } } @@ -79,8 +79,8 @@ fn empty_dest_cell() -> @mut ValueRef { fn dup_for_join(dest: dest) -> dest { alt dest { - by_val(_) { by_val(empty_dest_cell()) } - _ { dest } + by_val(_) => by_val(empty_dest_cell()), + _ => dest } } @@ -129,13 +129,13 @@ fn join_returns(parent_cx: block, in_cxs: ~[block], Br(cx, out.llbb); reachable = true; alt in_ds[i] { - by_val(cell) { + by_val(cell) => { if option::is_none(phi) { phi = some(EmptyPhi(out, val_ty(*cell))); } AddIncomingToPhi(option::get(phi), *cell, cx.llbb); } - _ {} + _ => () } } i += 1u; @@ -144,8 +144,8 @@ fn join_returns(parent_cx: block, in_cxs: ~[block], Unreachable(out); } else { alt out_dest { - by_val(cell) { *cell = option::get(phi); } - _ {} + by_val(cell) => *cell = option::get(phi), + _ => () } } return out; @@ -154,17 +154,17 @@ fn join_returns(parent_cx: block, in_cxs: ~[block], // Used to put an immediate value in a dest. fn store_in_dest(bcx: block, val: ValueRef, dest: dest) -> block { alt dest { - ignore {} - by_val(cell) { *cell = val; } - save_in(addr) { Store(bcx, val, addr); } + ignore => (), + by_val(cell) => *cell = val, + save_in(addr) => Store(bcx, val, addr) } return bcx; } fn get_dest_addr(dest: dest) -> ValueRef { alt dest { - save_in(a) { a } - _ { fail ~"get_dest_addr: not a save_in"; } + save_in(a) => a, + _ => fail ~"get_dest_addr: not a save_in" } } @@ -360,8 +360,8 @@ fn malloc_raw_dyn(bcx: block, t: ty::t, heap: heap, let ccx = bcx.ccx(); let (mk_fn, rtcall) = alt heap { - heap_shared { (ty::mk_imm_box, ~"malloc") } - heap_exchange { (ty::mk_imm_uniq, ~"exchange_malloc") } + heap_shared => (ty::mk_imm_box, ~"malloc"), + heap_exchange => (ty::mk_imm_uniq, ~"exchange_malloc") }; // Grab the TypeRef type of box_ptr_ty. @@ -420,8 +420,8 @@ fn get_tydesc_simple(ccx: @crate_ctxt, t: ty::t) -> ValueRef { fn get_tydesc(ccx: @crate_ctxt, t: ty::t) -> @tydesc_info { alt ccx.tydescs.find(t) { - some(inf) { inf } - _ { + some(inf) => inf, + _ => { ccx.stats.n_static_tydescs += 1u; let inf = declare_tydesc(ccx, t); ccx.tydescs.insert(t, inf); @@ -455,10 +455,10 @@ fn set_inline_hint(f: ValueRef) { fn set_inline_hint_if_appr(attrs: ~[ast::attribute], llfn: ValueRef) { alt attr::find_inline_attr(attrs) { - attr::ia_hint { set_inline_hint(llfn); } - attr::ia_always { set_always_inline(llfn); } - attr::ia_never { set_no_inline(llfn); } - attr::ia_none { /* fallthrough */ } + attr::ia_hint => set_inline_hint(llfn), + attr::ia_always => set_always_inline(llfn), + attr::ia_never => set_no_inline(llfn), + attr::ia_none => { /* fallthrough */ } } } @@ -578,23 +578,23 @@ fn emit_tydescs(ccx: @crate_ctxt) { let ti = val; let take_glue = alt copy ti.take_glue { - none { ccx.stats.n_null_glues += 1u; C_null(glue_fn_ty) } - some(v) { ccx.stats.n_real_glues += 1u; v } + none => { ccx.stats.n_null_glues += 1u; C_null(glue_fn_ty) } + some(v) => { ccx.stats.n_real_glues += 1u; v } }; let drop_glue = alt copy ti.drop_glue { - none { ccx.stats.n_null_glues += 1u; C_null(glue_fn_ty) } - some(v) { ccx.stats.n_real_glues += 1u; v } + none => { ccx.stats.n_null_glues += 1u; C_null(glue_fn_ty) } + some(v) => { ccx.stats.n_real_glues += 1u; v } }; let free_glue = alt copy ti.free_glue { - none { ccx.stats.n_null_glues += 1u; C_null(glue_fn_ty) } - some(v) { ccx.stats.n_real_glues += 1u; v } + none => { ccx.stats.n_null_glues += 1u; C_null(glue_fn_ty) } + some(v) => { ccx.stats.n_real_glues += 1u; v } }; let visit_glue = alt copy ti.visit_glue { - none { ccx.stats.n_null_glues += 1u; C_null(glue_fn_ty) } - some(v) { ccx.stats.n_real_glues += 1u; v } + none => { ccx.stats.n_null_glues += 1u; C_null(glue_fn_ty) } + some(v) => { ccx.stats.n_real_glues += 1u; v } }; let shape = shape_of(ccx, key); @@ -625,37 +625,38 @@ fn make_take_glue(bcx: block, v: ValueRef, t: ty::t) { // NB: v is a *pointer* to type t here, not a direct value. let bcx = alt ty::get(t).struct { ty::ty_box(_) | ty::ty_opaque_box | - ty::ty_evec(_, ty::vstore_box) | ty::ty_estr(ty::vstore_box) { + ty::ty_evec(_, ty::vstore_box) | ty::ty_estr(ty::vstore_box) => { incr_refcnt_of_boxed(bcx, Load(bcx, v)); bcx } - ty::ty_uniq(_) { + ty::ty_uniq(_) => { let {bcx, val} = uniq::duplicate(bcx, Load(bcx, v), t); Store(bcx, val, v); bcx } - ty::ty_evec(_, ty::vstore_uniq) | ty::ty_estr(ty::vstore_uniq) { + ty::ty_evec(_, ty::vstore_uniq) | ty::ty_estr(ty::vstore_uniq) => { let {bcx, val} = tvec::duplicate_uniq(bcx, Load(bcx, v), t); Store(bcx, val, v); bcx } - ty::ty_evec(_, ty::vstore_slice(_)) | ty::ty_estr(ty::vstore_slice(_)) { + ty::ty_evec(_, ty::vstore_slice(_)) + | ty::ty_estr(ty::vstore_slice(_)) => { bcx } - ty::ty_fn(_) { + ty::ty_fn(_) => { closure::make_fn_glue(bcx, v, t, take_ty) } - ty::ty_trait(_, _) { + ty::ty_trait(_, _) => { let llbox = Load(bcx, GEPi(bcx, v, ~[0u, 1u])); incr_refcnt_of_boxed(bcx, llbox); bcx } - ty::ty_opaque_closure_ptr(ck) { + ty::ty_opaque_closure_ptr(ck) => { closure::make_opaque_cbox_take_glue(bcx, ck, v) } - _ if ty::type_is_structural(t) { + _ if ty::type_is_structural(t) => { iter_structural_ty(bcx, v, t, take_ty) } - _ { bcx } + _ => bcx }; build_return(bcx); @@ -689,13 +690,13 @@ fn make_free_glue(bcx: block, v: ValueRef, t: ty::t) { let _icx = bcx.insn_ctxt(~"make_free_glue"); let ccx = bcx.ccx(); let bcx = alt ty::get(t).struct { - ty::ty_box(body_mt) { + ty::ty_box(body_mt) => { let v = PointerCast(bcx, v, type_of(ccx, t)); let body = GEPi(bcx, v, ~[0u, abi::box_field_body]); let bcx = drop_ty(bcx, body, body_mt.ty); trans_free(bcx, v) } - ty::ty_opaque_box { + ty::ty_opaque_box => { let v = PointerCast(bcx, v, type_of(ccx, t)); let td = Load(bcx, GEPi(bcx, v, ~[0u, abi::box_field_tydesc])); let valptr = GEPi(bcx, v, ~[0u, abi::box_field_body]); @@ -705,29 +706,29 @@ fn make_free_glue(bcx: block, v: ValueRef, t: ty::t) { none); trans_free(bcx, v) } - ty::ty_uniq(content_mt) { + ty::ty_uniq(content_mt) => { let v = PointerCast(bcx, v, type_of(ccx, t)); uniq::make_free_glue(bcx, v, t) } ty::ty_evec(_, ty::vstore_uniq) | ty::ty_estr(ty::vstore_uniq) | - ty::ty_evec(_, ty::vstore_box) | ty::ty_estr(ty::vstore_box) { + ty::ty_evec(_, ty::vstore_box) | ty::ty_estr(ty::vstore_box) => { make_free_glue(bcx, v, tvec::expand_boxed_vec_ty(bcx.tcx(), t)); return; } - ty::ty_fn(_) { + ty::ty_fn(_) => { closure::make_fn_glue(bcx, v, t, free_ty) } - ty::ty_opaque_closure_ptr(ck) { + ty::ty_opaque_closure_ptr(ck) => { closure::make_opaque_cbox_free_glue(bcx, ck, v) } - ty::ty_class(did,substs) { + ty::ty_class(did,substs) => { // Call the dtor if there is one do option::map_default(ty::ty_dtor(bcx.tcx(), did), bcx) |dt_id| { trans_class_drop(bcx, v, dt_id, did, substs) } } - _ { bcx } + _ => bcx }; build_return(bcx); } @@ -771,39 +772,39 @@ fn make_drop_glue(bcx: block, v0: ValueRef, t: ty::t) { let ccx = bcx.ccx(); let bcx = alt ty::get(t).struct { ty::ty_box(_) | ty::ty_opaque_box | - ty::ty_estr(ty::vstore_box) | ty::ty_evec(_, ty::vstore_box) { + ty::ty_estr(ty::vstore_box) | ty::ty_evec(_, ty::vstore_box) => { decr_refcnt_maybe_free(bcx, Load(bcx, v0), t) } ty::ty_uniq(_) | - ty::ty_evec(_, ty::vstore_uniq) | ty::ty_estr(ty::vstore_uniq) { + ty::ty_evec(_, ty::vstore_uniq) | ty::ty_estr(ty::vstore_uniq) => { free_ty(bcx, Load(bcx, v0), t) } - ty::ty_unboxed_vec(_) { + ty::ty_unboxed_vec(_) => { tvec::make_drop_glue_unboxed(bcx, v0, t) } - ty::ty_class(did, substs) { + ty::ty_class(did, substs) => { let tcx = bcx.tcx(); alt ty::ty_dtor(tcx, did) { - some(dtor) { + some(dtor) => { trans_class_drop(bcx, v0, dtor, did, substs) } - none { + none => { // No dtor? Just the default case iter_structural_ty(bcx, v0, t, drop_ty) } } } - ty::ty_fn(_) { + ty::ty_fn(_) => { closure::make_fn_glue(bcx, v0, t, drop_ty) } - ty::ty_trait(_, _) { + ty::ty_trait(_, _) => { let llbox = Load(bcx, GEPi(bcx, v0, ~[0u, 1u])); decr_refcnt_maybe_free(bcx, llbox, ty::mk_opaque_box(ccx.tcx)) } - ty::ty_opaque_closure_ptr(ck) { + ty::ty_opaque_closure_ptr(ck) => { closure::make_opaque_cbox_drop_glue(bcx, ck, v0) } - _ { + _ => { if ty::type_needs_drop(ccx.tcx, t) && ty::type_is_structural(t) { iter_structural_ty(bcx, v0, t, drop_ty) @@ -880,17 +881,17 @@ fn compare_scalar_types(cx: block, lhs: ValueRef, rhs: ValueRef, let f = |a| compare_scalar_values(cx, lhs, rhs, a, op); alt ty::get(t).struct { - ty::ty_nil { return rslt(cx, f(nil_type)); } - ty::ty_bool | ty::ty_ptr(_) { return rslt(cx, f(unsigned_int)); } - ty::ty_int(_) { return rslt(cx, f(signed_int)); } - ty::ty_uint(_) { return rslt(cx, f(unsigned_int)); } - ty::ty_float(_) { return rslt(cx, f(floating_point)); } - ty::ty_type { + ty::ty_nil => return rslt(cx, f(nil_type)), + ty::ty_bool | ty::ty_ptr(_) => return rslt(cx, f(unsigned_int)), + ty::ty_int(_) => return rslt(cx, f(signed_int)), + ty::ty_uint(_) => return rslt(cx, f(unsigned_int)), + ty::ty_float(_) => return rslt(cx, f(floating_point)), + ty::ty_type => { return rslt(trans_fail(cx, none, ~"attempt to compare values of type type"), C_nil()); } - _ { + _ => { // Should never get here, because t is scalar. cx.sess().bug(~"non-scalar type passed to \ compare_scalar_types"); @@ -909,49 +910,49 @@ fn compare_scalar_values(cx: block, lhs: ValueRef, rhs: ValueRef, } let die = fn@() -> ! { die_(cx) }; alt nt { - nil_type { + nil_type => { // We don't need to do actual comparisons for nil. // () == () holds but () < () does not. alt op { - ast::eq | ast::le | ast::ge { return C_bool(true); } - ast::ne | ast::lt | ast::gt { return C_bool(false); } + ast::eq | ast::le | ast::ge => return C_bool(true), + ast::ne | ast::lt | ast::gt => return C_bool(false), // refinements would be nice - _ { die(); } + _ => die() } } - floating_point { + floating_point => { let cmp = alt op { - ast::eq { lib::llvm::RealOEQ } - ast::ne { lib::llvm::RealUNE } - ast::lt { lib::llvm::RealOLT } - ast::le { lib::llvm::RealOLE } - ast::gt { lib::llvm::RealOGT } - ast::ge { lib::llvm::RealOGE } - _ { die(); } + ast::eq => lib::llvm::RealOEQ, + ast::ne => lib::llvm::RealUNE, + ast::lt => lib::llvm::RealOLT, + ast::le => lib::llvm::RealOLE, + ast::gt => lib::llvm::RealOGT, + ast::ge => lib::llvm::RealOGE, + _ => die() }; return FCmp(cx, cmp, lhs, rhs); } - signed_int { + signed_int => { let cmp = alt op { - ast::eq { lib::llvm::IntEQ } - ast::ne { lib::llvm::IntNE } - ast::lt { lib::llvm::IntSLT } - ast::le { lib::llvm::IntSLE } - ast::gt { lib::llvm::IntSGT } - ast::ge { lib::llvm::IntSGE } - _ { die(); } + ast::eq => lib::llvm::IntEQ, + ast::ne => lib::llvm::IntNE, + ast::lt => lib::llvm::IntSLT, + ast::le => lib::llvm::IntSLE, + ast::gt => lib::llvm::IntSGT, + ast::ge => lib::llvm::IntSGE, + _ => die() }; return ICmp(cx, cmp, lhs, rhs); } - unsigned_int { + unsigned_int => { let cmp = alt op { - ast::eq { lib::llvm::IntEQ } - ast::ne { lib::llvm::IntNE } - ast::lt { lib::llvm::IntULT } - ast::le { lib::llvm::IntULE } - ast::gt { lib::llvm::IntUGT } - ast::ge { lib::llvm::IntUGE } - _ { die(); } + ast::eq => lib::llvm::IntEQ, + ast::ne => lib::llvm::IntNE, + ast::lt => lib::llvm::IntULT, + ast::le => lib::llvm::IntULE, + ast::gt => lib::llvm::IntUGT, + ast::ge => lib::llvm::IntUGE, + _ => die() }; return ICmp(cx, cmp, lhs, rhs); } @@ -985,7 +986,7 @@ fn iter_structural_ty(cx: block, av: ValueRef, t: ty::t, let ccx = cx.ccx(); let mut cx = cx; alt ty::get(fn_ty).struct { - ty::ty_fn({inputs: args, _}) { + ty::ty_fn({inputs: args, _}) => { let mut j = 0u; let v_id = variant.id; for vec::each(args) |a| { @@ -995,7 +996,7 @@ fn iter_structural_ty(cx: block, av: ValueRef, t: ty::t, j += 1u; } } - _ { cx.tcx().sess.bug(~"iter_variant: not a function type"); } + _ => cx.tcx().sess.bug(~"iter_variant: not a function type") } return cx; } @@ -1005,24 +1006,24 @@ fn iter_structural_ty(cx: block, av: ValueRef, t: ty::t, */ let mut cx = cx; alt ty::get(t).struct { - ty::ty_rec(fields) { + ty::ty_rec(fields) => { for vec::eachi(fields) |i, fld| { let llfld_a = GEPi(cx, av, ~[0u, i]); cx = f(cx, llfld_a, fld.mt.ty); } } ty::ty_estr(ty::vstore_fixed(n)) | - ty::ty_evec(_, ty::vstore_fixed(n)) { + ty::ty_evec(_, ty::vstore_fixed(n)) => { let (base, len) = tvec::get_base_and_len(cx, av, t); cx = tvec::iter_vec_raw(cx, base, t, len, f); } - ty::ty_tup(args) { + ty::ty_tup(args) => { for vec::eachi(args) |i, arg| { let llfld_a = GEPi(cx, av, ~[0u, i]); cx = f(cx, llfld_a, arg); } } - ty::ty_enum(tid, substs) { + ty::ty_enum(tid, substs) => { let variants = ty::enum_variants(cx.tcx(), tid); let n_variants = (*variants).len(); @@ -1059,7 +1060,7 @@ fn iter_structural_ty(cx: block, av: ValueRef, t: ty::t, } return next_cx; } - ty::ty_class(did, substs) { + ty::ty_class(did, substs) => { // Take the drop bit into account let classptr = if is_some(ty::ty_dtor(cx.tcx(), did)) { GEPi(cx, av, ~[0u, 1u]) @@ -1072,7 +1073,7 @@ fn iter_structural_ty(cx: block, av: ValueRef, t: ty::t, cx = f(cx, llfld_a, fld.mt.ty); } } - _ { cx.sess().unimpl(~"type in iter_structural_ty"); } + _ => cx.sess().unimpl(~"type in iter_structural_ty") } return cx; } @@ -1090,8 +1091,8 @@ fn lazily_emit_tydesc_glue(ccx: @crate_ctxt, field: uint, let _icx = ccx.insn_ctxt(~"lazily_emit_tydesc_glue"); if field == abi::tydesc_field_take_glue { alt ti.take_glue { - some(_) { } - none { + some(_) => (), + none => { debug!{"+++ lazily_emit_tydesc_glue TAKE %s", ppaux::ty_to_str(ccx.tcx, ti.ty)}; let glue_fn = declare_generic_glue @@ -1105,8 +1106,8 @@ fn lazily_emit_tydesc_glue(ccx: @crate_ctxt, field: uint, } } else if field == abi::tydesc_field_drop_glue { alt ti.drop_glue { - some(_) { } - none { + some(_) => (), + none => { debug!{"+++ lazily_emit_tydesc_glue DROP %s", ppaux::ty_to_str(ccx.tcx, ti.ty)}; let glue_fn = @@ -1120,8 +1121,8 @@ fn lazily_emit_tydesc_glue(ccx: @crate_ctxt, field: uint, } } else if field == abi::tydesc_field_free_glue { alt ti.free_glue { - some(_) { } - none { + some(_) => (), + none => { debug!{"+++ lazily_emit_tydesc_glue FREE %s", ppaux::ty_to_str(ccx.tcx, ti.ty)}; let glue_fn = @@ -1135,8 +1136,8 @@ fn lazily_emit_tydesc_glue(ccx: @crate_ctxt, field: uint, } } else if field == abi::tydesc_field_visit_glue { alt ti.visit_glue { - some(_) { } - none { + some(_) => (), + none => { debug!{"+++ lazily_emit_tydesc_glue VISIT %s", ppaux::ty_to_str(ccx.tcx, ti.ty)}; let glue_fn = @@ -1159,8 +1160,8 @@ fn call_tydesc_glue_full(++cx: block, v: ValueRef, tydesc: ValueRef, let mut static_glue_fn = none; alt static_ti { - none {/* no-op */ } - some(sti) { + none => {/* no-op */ } + some(sti) => { lazily_emit_tydesc_glue(cx.ccx(), field, sti); if field == abi::tydesc_field_take_glue { static_glue_fn = sti.take_glue; @@ -1178,12 +1179,12 @@ fn call_tydesc_glue_full(++cx: block, v: ValueRef, tydesc: ValueRef, let llfn = { alt static_glue_fn { - none { + none => { // Select out the glue function to call from the tydesc let llfnptr = GEPi(cx, tydesc, ~[0u, field]); Load(cx, llfnptr) } - some(sgf) { sgf } + some(sgf) => sgf } }; @@ -1242,15 +1243,15 @@ fn drop_ty_immediate(bcx: block, v: ValueRef, t: ty::t) -> block { alt ty::get(t).struct { ty::ty_uniq(_) | ty::ty_evec(_, ty::vstore_uniq) | - ty::ty_estr(ty::vstore_uniq) { + ty::ty_estr(ty::vstore_uniq) => { free_ty(bcx, v, t) } ty::ty_box(_) | ty::ty_opaque_box | ty::ty_evec(_, ty::vstore_box) | - ty::ty_estr(ty::vstore_box) { + ty::ty_estr(ty::vstore_box) => { decr_refcnt_maybe_free(bcx, v, t) } - _ { bcx.tcx().sess.bug(~"drop_ty_immediate: non-box ty"); } + _ => bcx.tcx().sess.bug(~"drop_ty_immediate: non-box ty") } } @@ -1259,18 +1260,18 @@ fn take_ty_immediate(bcx: block, v: ValueRef, t: ty::t) -> result { alt ty::get(t).struct { ty::ty_box(_) | ty::ty_opaque_box | ty::ty_evec(_, ty::vstore_box) | - ty::ty_estr(ty::vstore_box) { + ty::ty_estr(ty::vstore_box) => { incr_refcnt_of_boxed(bcx, v); rslt(bcx, v) } - ty::ty_uniq(_) { + ty::ty_uniq(_) => { uniq::duplicate(bcx, v, t) } ty::ty_evec(_, ty::vstore_uniq) | - ty::ty_estr(ty::vstore_uniq) { + ty::ty_estr(ty::vstore_uniq) => { tvec::duplicate_uniq(bcx, v, t) } - _ { rslt(bcx, v) } + _ => rslt(bcx, v) } } @@ -1291,8 +1292,8 @@ fn call_memmove(cx: block, dst: ValueRef, src: ValueRef, let _icx = cx.insn_ctxt(~"call_memmove"); let ccx = cx.ccx(); let key = alt ccx.sess.targ_cfg.arch { - session::arch_x86 | session::arch_arm { ~"llvm.memmove.p0i8.p0i8.i32" } - session::arch_x86_64 { ~"llvm.memmove.p0i8.p0i8.i64" } + session::arch_x86 | session::arch_arm => ~"llvm.memmove.p0i8.p0i8.i32", + session::arch_x86_64 => ~"llvm.memmove.p0i8.p0i8.i64" }; let memmove = ccx.intrinsics.get(key); let src_ptr = PointerCast(cx, src, T_ptr(T_i8())); @@ -1320,8 +1321,8 @@ enum copy_action { INIT, DROP_EXISTING, } fn type_is_structural_or_param(t: ty::t) -> bool { if ty::type_is_structural(t) { return true; } alt ty::get(t).struct { - ty::ty_param(*) { return true; } - _ { return false; } + ty::ty_param(*) => return true, + _ => return false } } @@ -1446,7 +1447,7 @@ fn trans_unary(bcx: block, op: ast::unop, e: @ast::expr, let _icx = bcx.insn_ctxt(~"trans_unary"); // Check for user-defined method call alt bcx.ccx().maps.method_map.find(un_expr.id) { - some(mentry) { + some(mentry) => { let fty = node_id_type(bcx, un_expr.callee_id); return trans_call_inner( bcx, un_expr.info(), fty, @@ -1455,30 +1456,30 @@ fn trans_unary(bcx: block, op: ast::unop, e: @ast::expr, mentry), arg_exprs(~[]), dest); } - _ {} + _ => () } if dest == ignore { return trans_expr(bcx, e, ignore); } let e_ty = expr_ty(bcx, e); alt op { - ast::not { + ast::not => { let {bcx, val} = trans_temp_expr(bcx, e); store_in_dest(bcx, Not(bcx, val), dest) } - ast::neg { + ast::neg => { let {bcx, val} = trans_temp_expr(bcx, e); let llneg = if ty::type_is_fp(e_ty) { FNeg(bcx, val) } else { Neg(bcx, val) }; store_in_dest(bcx, llneg, dest) } - ast::box(_) { + ast::box(_) => { trans_boxed_expr(bcx, e, e_ty, heap_shared, dest) } - ast::uniq(_) { + ast::uniq(_) => { trans_boxed_expr(bcx, e, e_ty, heap_exchange, dest) } - ast::deref { + ast::deref => { bcx.sess().bug(~"deref expressions should have been \ translated using trans_lval(), not \ trans_unary()") @@ -1508,10 +1509,10 @@ fn trans_compare(cx: block, op: ast::binop, lhs: ValueRef, // Determine the operation we need. let llop = { alt op { - ast::eq | ast::ne { C_u8(abi::cmp_glue_op_eq) } - ast::lt | ast::ge { C_u8(abi::cmp_glue_op_lt) } - ast::le | ast::gt { C_u8(abi::cmp_glue_op_le) } - _ { cx.tcx().sess.bug(~"trans_compare got non-comparison-op"); } + ast::eq | ast::ne => C_u8(abi::cmp_glue_op_eq), + ast::lt | ast::ge => C_u8(abi::cmp_glue_op_lt), + ast::le | ast::gt => C_u8(abi::cmp_glue_op_le), + _ => cx.tcx().sess.bug(~"trans_compare got non-comparison-op") } }; @@ -1519,9 +1520,9 @@ fn trans_compare(cx: block, op: ast::binop, lhs: ValueRef, // Invert the result if necessary. alt op { - ast::eq | ast::lt | ast::le { rslt(cx, cmpval) } - ast::ne | ast::ge | ast::gt { rslt(cx, Not(cx, cmpval)) } - _ { cx.tcx().sess.bug(~"trans_compare got non-comparison-op"); } + ast::eq | ast::lt | ast::le => rslt(cx, cmpval), + ast::ne | ast::ge | ast::gt => rslt(cx, Not(cx, cmpval)), + _ => cx.tcx().sess.bug(~"trans_compare got non-comparison-op") } } @@ -1571,15 +1572,15 @@ fn fail_if_zero(cx: block, span: span, divmod: ast::binop, ~"modulo zero" }; let is_zero = alt ty::get(rhs_t).struct { - ty::ty_int(t) { + ty::ty_int(t) => { let zero = C_integral(T_int_ty(cx.ccx(), t), 0u64, False); ICmp(cx, lib::llvm::IntEQ, rhs, zero) } - ty::ty_uint(t) { + ty::ty_uint(t) => { let zero = C_integral(T_uint_ty(cx.ccx(), t), 0u64, False); ICmp(cx, lib::llvm::IntEQ, rhs, zero) } - _ { + _ => { cx.tcx().sess.bug(~"fail-if-zero on unexpected type: " + ty_to_str(cx.ccx().tcx, rhs_t)); } @@ -1607,19 +1608,19 @@ fn trans_eager_binop(cx: block, span: span, op: ast::binop, lhs: ValueRef, let mut cx = cx; let val = alt op { - ast::add { + ast::add => { if is_float { FAdd(cx, lhs, rhs) } else { Add(cx, lhs, rhs) } } - ast::subtract { + ast::subtract => { if is_float { FSub(cx, lhs, rhs) } else { Sub(cx, lhs, rhs) } } - ast::mul { + ast::mul => { if is_float { FMul(cx, lhs, rhs) } else { Mul(cx, lhs, rhs) } } - ast::div { + ast::div => { if is_float { FDiv(cx, lhs, rhs) } else { @@ -1632,7 +1633,7 @@ fn trans_eager_binop(cx: block, span: span, op: ast::binop, lhs: ValueRef, } } } - ast::rem { + ast::rem => { if is_float { FRem(cx, lhs, rhs) } else { @@ -1645,16 +1646,16 @@ fn trans_eager_binop(cx: block, span: span, op: ast::binop, lhs: ValueRef, } } } - ast::bitor { Or(cx, lhs, rhs) } - ast::bitand { And(cx, lhs, rhs) } - ast::bitxor { Xor(cx, lhs, rhs) } - ast::shl { Shl(cx, lhs, rhs) } - ast::shr { + ast::bitor => Or(cx, lhs, rhs), + ast::bitand => And(cx, lhs, rhs), + ast::bitxor => Xor(cx, lhs, rhs), + ast::shl => Shl(cx, lhs, rhs), + ast::shr => { if ty::type_is_signed(intype) { AShr(cx, lhs, rhs) } else { LShr(cx, lhs, rhs) } } - _ { + _ => { let cmpr = trans_compare(cx, op, lhs, lhs_t, rhs, rhs_t); cx = cmpr.bcx; cmpr.val @@ -1673,7 +1674,7 @@ fn trans_assign_op(bcx: block, ex: @ast::expr, op: ast::binop, // A user-defined operator method alt bcx.ccx().maps.method_map.find(ex.id) { - some(origin) { + some(origin) => { let bcx = lhs_res.bcx; debug!{"user-defined method callee_id: %s", ast_map::node_id_to_str(bcx.tcx().items, ex.callee_id)}; @@ -1696,7 +1697,7 @@ fn trans_assign_op(bcx: block, ex: @ast::expr, op: ast::binop, {bcx: bcx, val: target, kind: lv_owned}, dty); } - _ {} + _ => () } let {bcx, val: rhs_val} = trans_temp_expr(lhs_res.bcx, src); @@ -1738,14 +1739,14 @@ fn autoderef(cx: block, e_id: ast::node_id, // root the autoderef'd value, if necessary: derefs += 1u; alt ccx.maps.root_map.find({id:e_id, derefs:derefs}) { - none { } - some(scope_id) { + none => (), + some(scope_id) => { root_value(cx, v1, t1, scope_id); } } alt ty::get(t1).struct { - ty::ty_box(mt) { + ty::ty_box(mt) => { let body = GEPi(cx, v1, ~[0u, abi::box_field_body]); t1 = mt.ty; @@ -1756,16 +1757,16 @@ fn autoderef(cx: block, e_id: ast::node_id, let llty = type_of(ccx, t1); v1 = PointerCast(cx, body, T_ptr(llty)); } - ty::ty_uniq(_) { + ty::ty_uniq(_) => { let derefed = uniq::autoderef(cx, v1, t1); t1 = derefed.t; v1 = derefed.v; } - ty::ty_rptr(_, mt) { + ty::ty_rptr(_, mt) => { t1 = mt.ty; v1 = v; } - ty::ty_enum(did, substs) { + ty::ty_enum(did, substs) => { let variants = ty::enum_variants(ccx.tcx, did); if (*variants).len() != 1u || variants[0].args.len() != 1u { break; @@ -1773,7 +1774,7 @@ fn autoderef(cx: block, e_id: ast::node_id, t1 = ty::subst(ccx.tcx, substs, variants[0].args[0]); v1 = PointerCast(cx, v1, T_ptr(type_of(ccx, t1))); } - _ { break; } + _ => break } v1 = load_if_immediate(cx, v1, t1); } @@ -1800,8 +1801,8 @@ fn trans_lazy_binop(bcx: block, op: lazy_binop_ty, a: @ast::expr, let join = sub_block(bcx, ~"join"), before_rhs = sub_block(bcx, ~"rhs"); alt op { - lazy_and { CondBr(past_lhs, lhs, before_rhs.llbb, join.llbb); } - lazy_or { CondBr(past_lhs, lhs, join.llbb, before_rhs.llbb); } + lazy_and => CondBr(past_lhs, lhs, before_rhs.llbb, join.llbb), + lazy_or => CondBr(past_lhs, lhs, join.llbb, before_rhs.llbb) } let {bcx: past_rhs, val: rhs} = { do with_scope_result(before_rhs, b.info(), ~"rhs") |bcx| { @@ -1821,7 +1822,7 @@ fn trans_binary(bcx: block, op: ast::binop, lhs: @ast::expr, let _icx = bcx.insn_ctxt(~"trans_binary"); // User-defined operators alt bcx.ccx().maps.method_map.find(ex.id) { - some(origin) { + some(origin) => { let fty = node_id_type(bcx, ex.callee_id); return trans_call_inner( bcx, ex.info(), fty, @@ -1831,18 +1832,18 @@ fn trans_binary(bcx: block, op: ast::binop, lhs: @ast::expr, }, arg_exprs(~[rhs]), dest); } - _ {} + _ => () } // First couple cases are lazy: alt op { - ast::and { + ast::and => { return trans_lazy_binop(bcx, lazy_and, lhs, rhs, dest); } - ast::or { + ast::or => { return trans_lazy_binop(bcx, lazy_or, lhs, rhs, dest); } - _ { + _ => { // Remaining cases are eager: let lhs_res = trans_temp_expr(bcx, lhs); let rhs_res = trans_temp_expr(lhs_res.bcx, rhs); @@ -1872,20 +1873,20 @@ fn trans_if(cx: block, cond: @ast::expr, thn: ast::blk, // context for the block, but we've already got the // 'else' context let else_bcx = alt els { - some(elexpr) { + some(elexpr) => { alt elexpr.node { - ast::expr_if(_, _, _) { + ast::expr_if(_, _, _) => { let elseif_blk = ast_util::block_from_expr(elexpr); trans_block(else_cx, elseif_blk, else_dest) } - ast::expr_block(blk) { + ast::expr_block(blk) => { trans_block(else_cx, blk, else_dest) } // would be nice to have a constraint on ifs - _ { cx.tcx().sess.bug(~"strange alternative in if"); } + _ => cx.tcx().sess.bug(~"strange alternative in if") } } - _ { else_cx } + _ => else_cx }; let else_bcx = trans_block_cleanups(else_bcx, else_cx); return join_returns(cx, @@ -1960,12 +1961,12 @@ fn trans_external_path(ccx: @crate_ctxt, did: ast::def_id, t: ty::t) -> ValueRef { let name = csearch::get_symbol(ccx.sess.cstore, did); alt ty::get(t).struct { - ty::ty_fn(_) { + ty::ty_fn(_) => { let llty = type_of_fn_from_ty(ccx, t); return get_extern_fn(ccx.externs, ccx.llmod, name, lib::llvm::CCallConv, llty); } - _ { + _ => { let llty = type_of(ccx, t); return get_extern_const(ccx.externs, ccx.llmod, name, llty); } @@ -1975,25 +1976,25 @@ fn trans_external_path(ccx: @crate_ctxt, did: ast::def_id, t: ty::t) fn normalize_for_monomorphization(tcx: ty::ctxt, ty: ty::t) -> option<ty::t> { // FIXME[mono] could do this recursively. is that worthwhile? (#2529) alt ty::get(ty).struct { - ty::ty_box(mt) { + ty::ty_box(mt) => { some(ty::mk_opaque_box(tcx)) } - ty::ty_fn(fty) { + ty::ty_fn(fty) => { some(ty::mk_fn(tcx, {purity: ast::impure_fn, proto: fty.proto, inputs: ~[], output: ty::mk_nil(tcx), ret_style: ast::return_val})) } - ty::ty_trait(_, _) { + ty::ty_trait(_, _) => { some(ty::mk_fn(tcx, {purity: ast::impure_fn, proto: ast::proto_box, inputs: ~[], output: ty::mk_nil(tcx), ret_style: ast::return_val})) } - ty::ty_ptr(_) { some(ty::mk_uint(tcx)) } - _ { none } + ty::ty_ptr(_) => some(ty::mk_uint(tcx)), + _ => none } } @@ -2001,33 +2002,33 @@ fn make_mono_id(ccx: @crate_ctxt, item: ast::def_id, substs: ~[ty::t], vtables: option<typeck::vtable_res>, param_uses: option<~[type_use::type_uses]>) -> mono_id { let precise_param_ids = alt vtables { - some(vts) { + some(vts) => { let bounds = ty::lookup_item_type(ccx.tcx, item).bounds; let mut i = 0u; vec::map2(*bounds, substs, |bounds, subst| { let mut v = ~[]; for vec::each(*bounds) |bound| { alt bound { - ty::bound_trait(_) { + ty::bound_trait(_) => { vec::push(v, impl::vtable_id(ccx, vts[i])); i += 1u; } - _ {} + _ => () } } mono_precise(subst, if v.len() > 0u { some(v) } else { none }) }) } - none { + none => { vec::map(substs, |subst| mono_precise(subst, none)) } }; let param_ids = alt param_uses { - some(uses) { + some(uses) => { vec::map2(precise_param_ids, uses, |id, uses| { alt check id { - mono_precise(_, some(_)) { id } - mono_precise(subst, none) { + mono_precise(_, some(_)) => id, + mono_precise(subst, none) => { if uses == 0u { mono_any } else if uses == type_use::use_repr && !ty::type_needs_drop(ccx.tcx, subst) { @@ -2044,7 +2045,7 @@ fn make_mono_id(ccx: @crate_ctxt, item: ast::def_id, substs: ~[ty::t], } }) } - none { precise_param_ids } + none => precise_param_ids }; @{def: item, params: param_ids} } @@ -2058,8 +2059,8 @@ fn monomorphic_fn(ccx: @crate_ctxt, fn_id: ast::def_id, let mut must_cast = false; let substs = vec::map(real_substs, |t| { alt normalize_for_monomorphization(ccx.tcx, t) { - some(t) { must_cast = true; t } - none { t } + some(t) => { must_cast = true; t } + none => t } }); @@ -2068,7 +2069,7 @@ fn monomorphic_fn(ccx: @crate_ctxt, fn_id: ast::def_id, let param_uses = type_use::type_uses_for(ccx, fn_id, substs.len()); let hash_id = make_mono_id(ccx, fn_id, substs, vtables, some(param_uses)); if vec::any(hash_id.params, - |p| alt p { mono_precise(_, _) { false } _ { true } }) { + |p| alt p { mono_precise(_, _) => false, _ => true }) { must_cast = true; } @@ -2079,12 +2080,12 @@ fn monomorphic_fn(ccx: @crate_ctxt, fn_id: ast::def_id, substs.map(|s| ty_to_str(ccx.tcx, s)), hash_id]; alt ccx.monomorphized.find(hash_id) { - some(val) { + some(val) => { debug!{"leaving monomorphic fn %s", ty::item_path_str(ccx.tcx, fn_id)}; return {val: val, must_cast: must_cast}; } - none {} + none => () } let tpt = ty::lookup_item_type(ccx.tcx, fn_id); @@ -2096,32 +2097,32 @@ fn monomorphic_fn(ccx: @crate_ctxt, fn_id: ast::def_id, crate?)", fn_id}); // Get the path so that we can create a symbol let (pt, name, span) = alt map_node { - ast_map::node_item(i, pt) { (pt, i.ident, i.span) } - ast_map::node_variant(v, enm, pt) { (pt, v.node.name, enm.span) } - ast_map::node_method(m, _, pt) { (pt, m.ident, m.span) } + ast_map::node_item(i, pt) => (pt, i.ident, i.span), + ast_map::node_variant(v, enm, pt) => (pt, v.node.name, enm.span), + ast_map::node_method(m, _, pt) => (pt, m.ident, m.span), ast_map::node_foreign_item(i, ast::foreign_abi_rust_intrinsic, pt) - { (pt, i.ident, i.span) } - ast_map::node_foreign_item(_, abi, _) { + => (pt, i.ident, i.span), + ast_map::node_foreign_item(_, abi, _) => { // Foreign externs don't have to be monomorphized. return {val: get_item_val(ccx, fn_id.node), must_cast: true}; } - ast_map::node_ctor(nm, _, ct, _, pt) { (pt, nm, ct.span) } - ast_map::node_dtor(_, dtor, _, pt) {(pt, @~"drop", dtor.span)} - ast_map::node_trait_method(*) { + ast_map::node_ctor(nm, _, ct, _, pt) => (pt, nm, ct.span), + ast_map::node_dtor(_, dtor, _, pt) => (pt, @~"drop", dtor.span), + ast_map::node_trait_method(*) => { ccx.tcx.sess.bug(~"Can't monomorphize a trait method") } - ast_map::node_expr(*) { + ast_map::node_expr(*) => { ccx.tcx.sess.bug(~"Can't monomorphize an expr") } - ast_map::node_export(*) { + ast_map::node_export(*) => { ccx.tcx.sess.bug(~"Can't monomorphize an export") } - ast_map::node_arg(*) { ccx.tcx.sess.bug(~"Can't monomorphize an arg") } - ast_map::node_block(*) { + ast_map::node_arg(*) => ccx.tcx.sess.bug(~"Can't monomorphize an arg"), + ast_map::node_block(*) => { ccx.tcx.sess.bug(~"Can't monomorphize a block") } - ast_map::node_local(*) { + ast_map::node_local(*) => { ccx.tcx.sess.bug(~"Can't monomorphize a local") } }; @@ -2149,22 +2150,22 @@ fn monomorphic_fn(ccx: @crate_ctxt, fn_id: ast::def_id, let psubsts = some({tys: substs, vtables: vtables, bounds: tpt.bounds}); let lldecl = alt map_node { - ast_map::node_item(i@@{node: ast::item_fn(decl, _, body), _}, _) { + ast_map::node_item(i@@{node: ast::item_fn(decl, _, body), _}, _) => { let d = mk_lldecl(); set_inline_hint_if_appr(i.attrs, d); trans_fn(ccx, pt, decl, body, d, no_self, psubsts, fn_id.node); d } - ast_map::node_item(*) { + ast_map::node_item(*) => { ccx.tcx.sess.bug(~"Can't monomorphize this kind of item") } - ast_map::node_foreign_item(i, _, _) { + ast_map::node_foreign_item(i, _, _) => { let d = mk_lldecl(); foreign::trans_intrinsic(ccx, d, i, pt, option::get(psubsts), ref_id); d } - ast_map::node_variant(v, enum_item, _) { + ast_map::node_variant(v, enum_item, _) => { let tvs = ty::enum_variants(ccx.tcx, local_def(enum_item.id)); let this_tv = option::get(vec::find(*tvs, |tv| { tv.id.node == fn_id.node})); @@ -2174,7 +2175,7 @@ fn monomorphic_fn(ccx: @crate_ctxt, fn_id: ast::def_id, (*tvs).len() == 1u, psubsts, d); d } - ast_map::node_method(mth, impl_def_id, _) { + ast_map::node_method(mth, impl_def_id, _) => { let d = mk_lldecl(); set_inline_hint_if_appr(mth.attrs, d); let selfty = ty::node_id_to_type(ccx.tcx, mth.self_id); @@ -2183,7 +2184,7 @@ fn monomorphic_fn(ccx: @crate_ctxt, fn_id: ast::def_id, impl_self(selfty), psubsts, fn_id.node); d } - ast_map::node_ctor(nm, tps, ctor, parent_id, _) { + ast_map::node_ctor(nm, tps, ctor, parent_id, _) => { // ctors don't have attrs, at least not right now let d = mk_lldecl(); let tp_tys = ty::ty_params_to_tys(ccx.tcx, tps); @@ -2193,31 +2194,31 @@ fn monomorphic_fn(ccx: @crate_ctxt, fn_id: ast::def_id, fn_id.node, parent_id, ctor.span); d } - ast_map::node_dtor(_, dtor, _, pt) { + ast_map::node_dtor(_, dtor, _, pt) => { let parent_id = alt ty::ty_to_def_id(ty::node_id_to_type(ccx.tcx, dtor.node.self_id)) { - some(did) { did } - none { ccx.sess.span_bug(dtor.span, ~"Bad self ty in \ - dtor"); } + some(did) => did, + none => ccx.sess.span_bug(dtor.span, ~"Bad self ty in \ + dtor") }; trans_class_dtor(ccx, *pt, dtor.node.body, dtor.node.id, psubsts, some(hash_id), parent_id) } // Ugh -- but this ensures any new variants won't be forgotten - ast_map::node_expr(*) { + ast_map::node_expr(*) => { ccx.tcx.sess.bug(~"Can't monomorphize an expr") } - ast_map::node_trait_method(*) { + ast_map::node_trait_method(*) => { ccx.tcx.sess.bug(~"Can't monomorphize a trait method") } - ast_map::node_export(*) { + ast_map::node_export(*) => { ccx.tcx.sess.bug(~"Can't monomorphize an export") } - ast_map::node_arg(*) { ccx.tcx.sess.bug(~"Can't monomorphize an arg") } - ast_map::node_block(*) { + ast_map::node_arg(*) => ccx.tcx.sess.bug(~"Can't monomorphize an arg"), + ast_map::node_block(*) => { ccx.tcx.sess.bug(~"Can't monomorphize a block") } - ast_map::node_local(*) { + ast_map::node_local(*) => { ccx.tcx.sess.bug(~"Can't monomorphize a local") } }; @@ -2231,42 +2232,42 @@ fn maybe_instantiate_inline(ccx: @crate_ctxt, fn_id: ast::def_id) -> ast::def_id { let _icx = ccx.insn_ctxt(~"maybe_instantiate_inline"); alt ccx.external.find(fn_id) { - some(some(node_id)) { + some(some(node_id)) => { // Already inline debug!{"maybe_instantiate_inline(%s): already inline as node id %d", ty::item_path_str(ccx.tcx, fn_id), node_id}; local_def(node_id) } - some(none) { fn_id } // Not inlinable - none { // Not seen yet + some(none) => fn_id, // Not inlinable + none => { // Not seen yet alt csearch::maybe_get_item_ast( ccx.tcx, fn_id, |a,b,c,d| { astencode::decode_inlined_item(a, b, ccx.maps, c, d) }) { - csearch::not_found { + csearch::not_found => { ccx.external.insert(fn_id, none); fn_id } - csearch::found(ast::ii_item(item)) { + csearch::found(ast::ii_item(item)) => { ccx.external.insert(fn_id, some(item.id)); trans_item(ccx, *item); local_def(item.id) } - csearch::found(ast::ii_ctor(ctor, nm, tps, parent_id)) { + csearch::found(ast::ii_ctor(ctor, nm, tps, parent_id)) => { ccx.external.insert(fn_id, some(ctor.node.id)); local_def(ctor.node.id) } - csearch::found(ast::ii_foreign(item)) { + csearch::found(ast::ii_foreign(item)) => { ccx.external.insert(fn_id, some(item.id)); local_def(item.id) } - csearch::found_parent(parent_id, ast::ii_item(item)) { + csearch::found_parent(parent_id, ast::ii_item(item)) => { ccx.external.insert(parent_id, some(item.id)); let mut my_id = 0; alt check item.node { - ast::item_enum(_, _) { + ast::item_enum(_, _) => { let vs_here = ty::enum_variants(ccx.tcx, local_def(item.id)); let vs_there = ty::enum_variants(ccx.tcx, parent_id); do vec::iter2(*vs_here, *vs_there) |here, there| { @@ -2278,11 +2279,11 @@ fn maybe_instantiate_inline(ccx: @crate_ctxt, fn_id: ast::def_id) trans_item(ccx, *item); local_def(my_id) } - csearch::found_parent(_, _) { + csearch::found_parent(_, _) => { ccx.sess.bug(~"maybe_get_item_ast returned a found_parent \ with a non-item parent"); } - csearch::found(ast::ii_method(impl_did, mth)) { + csearch::found(ast::ii_method(impl_did, mth)) => { ccx.external.insert(fn_id, some(mth.id)); let {bounds: impl_bnds, rp: _, ty: impl_ty} = ty::lookup_item_type(ccx.tcx, impl_did); @@ -2296,7 +2297,7 @@ fn maybe_instantiate_inline(ccx: @crate_ctxt, fn_id: ast::def_id) } local_def(mth.id) } - csearch::found(ast::ii_dtor(dtor, nm, tps, parent_id)) { + csearch::found(ast::ii_dtor(dtor, nm, tps, parent_id)) => { ccx.external.insert(fn_id, some(dtor.node.id)); local_def(dtor.node.id) } @@ -2350,17 +2351,17 @@ fn lval_static_fn_inner(bcx: block, fn_id: ast::def_id, id: ast::node_id, } alt ty::get(tpt.ty).struct { - ty::ty_fn(fn_ty) { + ty::ty_fn(fn_ty) => { alt fn_ty.purity { - ast::extern_fn { + ast::extern_fn => { // Extern functions are just opaque pointers let val = PointerCast(bcx, val, T_ptr(T_i8())); return lval_no_env(bcx, val, lv_owned_imm); } - _ { /* fall through */ } + _ => { /* fall through */ } } } - _ { /* fall through */ } + _ => { /* fall through */ } } return {bcx: bcx, val: val, kind: lv_owned, env: null_env}; @@ -2369,7 +2370,7 @@ fn lval_static_fn_inner(bcx: block, fn_id: ast::def_id, id: ast::node_id, fn lookup_discriminant(ccx: @crate_ctxt, vid: ast::def_id) -> ValueRef { let _icx = ccx.insn_ctxt(~"lookup_discriminant"); alt ccx.discrims.find(vid) { - none { + none => { // It's an external discriminant that we haven't seen yet. assert (vid.crate != ast::local_crate); let sym = csearch::get_symbol(ccx.sess.cstore, vid); @@ -2381,7 +2382,7 @@ fn lookup_discriminant(ccx: @crate_ctxt, vid: ast::def_id) -> ValueRef { ccx.discrims.insert(vid, gvar); return gvar; } - some(llval) { return llval; } + some(llval) => return llval, } } @@ -2394,33 +2395,33 @@ fn trans_local_var(cx: block, def: ast::def) -> local_var_result { fn take_local(table: hashmap<ast::node_id, local_val>, id: ast::node_id) -> local_var_result { alt table.find(id) { - some(local_mem(v)) { {val: v, kind: lv_owned} } - some(local_imm(v)) { {val: v, kind: lv_owned_imm} } - r { fail(~"take_local: internal error"); } + some(local_mem(v)) => {val: v, kind: lv_owned}, + some(local_imm(v)) => {val: v, kind: lv_owned_imm}, + r => fail(~"take_local: internal error") } } alt def { - ast::def_upvar(nid, _, _) { + ast::def_upvar(nid, _, _) => { assert (cx.fcx.llupvars.contains_key(nid)); return { val: cx.fcx.llupvars.get(nid), kind: lv_owned }; } - ast::def_arg(nid, _) { + ast::def_arg(nid, _) => { assert (cx.fcx.llargs.contains_key(nid)); return take_local(cx.fcx.llargs, nid); } - ast::def_local(nid, _) | ast::def_binding(nid, _) { + ast::def_local(nid, _) | ast::def_binding(nid, _) => { assert (cx.fcx.lllocals.contains_key(nid)); return take_local(cx.fcx.lllocals, nid); } - ast::def_self(sid) { + ast::def_self(sid) => { let slf = alt copy cx.fcx.llself { - some(s) { cast_self(cx, s) } - none { cx.sess().bug(~"trans_local_var: reference to self \ - out of context"); } + some(s) => cast_self(cx, s), + none => cx.sess().bug(~"trans_local_var: reference to self \ + out of context") }; return {val: slf, kind: lv_owned}; } - _ { + _ => { cx.sess().unimpl(fmt!{"unsupported def type in trans_local_var: %?", def}); } @@ -2431,8 +2432,8 @@ fn trans_path(cx: block, id: ast::node_id) -> lval_maybe_callee { let _icx = cx.insn_ctxt(~"trans_path"); alt cx.tcx().def_map.find(id) { - none { cx.sess().bug(~"trans_path: unbound node ID"); } - some(df) { + none => cx.sess().bug(~"trans_path: unbound node ID"), + some(df) => { return trans_var(cx, df, id); } } @@ -2442,10 +2443,10 @@ fn trans_var(cx: block, def: ast::def, id: ast::node_id)-> lval_maybe_callee { let _icx = cx.insn_ctxt(~"trans_var"); let ccx = cx.ccx(); alt def { - ast::def_fn(did, _) { + ast::def_fn(did, _) => { return lval_static_fn(cx, did, id); } - ast::def_variant(tid, vid) { + ast::def_variant(tid, vid) => { if ty::enum_variant_with_id(ccx.tcx, tid, vid).args.len() > 0u { // N-ary variant. return lval_static_fn(cx, vid, id); @@ -2460,7 +2461,7 @@ fn trans_var(cx: block, def: ast::def, id: ast::node_id)-> lval_maybe_callee { return lval_no_env(cx, llenumptr, lv_temporary); } } - ast::def_const(did) { + ast::def_const(did) => { if did.crate == ast::local_crate { return lval_no_env(cx, get_item_val(ccx, did.node), lv_owned); } else { @@ -2470,7 +2471,7 @@ fn trans_var(cx: block, def: ast::def, id: ast::node_id)-> lval_maybe_callee { lv_owned_imm); } } - _ { + _ => { let loc = trans_local_var(cx, def); return lval_no_env(cx, loc.val, loc.kind); } @@ -2491,16 +2492,16 @@ fn trans_rec_field_inner(bcx: block, val: ValueRef, ty: ty::t, field: ast::ident, sp: span) -> lval_result { let mut llderef = false; let fields = alt ty::get(ty).struct { - ty::ty_rec(fs) { fs } - ty::ty_class(did, substs) { + ty::ty_rec(fs) => fs, + ty::ty_class(did, substs) => { if option::is_some(ty::ty_dtor(bcx.tcx(), did)) { llderef = true; } ty::class_items_as_mutable_fields(bcx.tcx(), did, substs) } // Constraint? - _ { bcx.tcx().sess.span_bug(sp, ~"trans_rec_field:\ - base expr has non-record type"); } + _ => bcx.tcx().sess.span_bug(sp, ~"trans_rec_field:\ + base expr has non-record type") }; // seems wrong? Doesn't take into account the field // sizes @@ -2583,21 +2584,21 @@ fn expr_is_lval(bcx: block, e: @ast::expr) -> bool { fn trans_callee(bcx: block, e: @ast::expr) -> lval_maybe_callee { let _icx = bcx.insn_ctxt(~"trans_callee"); alt e.node { - ast::expr_path(path) { return trans_path(bcx, e.id); } - ast::expr_field(base, _, _) { + ast::expr_path(path) => return trans_path(bcx, e.id), + ast::expr_field(base, _, _) => { // Lval means this is a record field, so not a method if !expr_is_lval(bcx, e) { alt bcx.ccx().maps.method_map.find(e.id) { - some(origin) { // An impl method + some(origin) => { // An impl method return impl::trans_method_callee(bcx, e.id, base, origin); } - _ { + _ => { bcx.ccx().sess.span_bug(e.span, ~"trans_callee: weird expr"); } } } } - _ {} + _ => () } let lv = trans_temp_lval(bcx, e); return lval_no_env(lv.bcx, lv.val, lv.kind); @@ -2610,11 +2611,11 @@ fn trans_callee(bcx: block, e: @ast::expr) -> lval_maybe_callee { fn trans_lval(cx: block, e: @ast::expr) -> lval_result { return alt cx.ccx().maps.root_map.find({id:e.id, derefs:0u}) { // No need to root this lvalue. - none { unrooted(cx, e) } + none => unrooted(cx, e), // Lvalue must remain rooted until exit of `scope_id`. See // add_root_cleanup() for comments on why this works the way it does. - some(scope_id) { + some(scope_id) => { let lv = unrooted(cx, e); if !cx.sess().no_asm_comments() { @@ -2634,39 +2635,39 @@ fn trans_lval(cx: block, e: @ast::expr) -> lval_result { fn unrooted(cx: block, e: @ast::expr) -> lval_result { let _icx = cx.insn_ctxt(~"trans_lval"); alt e.node { - ast::expr_path(_) { + ast::expr_path(_) => { let v = trans_path(cx, e.id); return lval_maybe_callee_to_lval(v, e.span); } - ast::expr_field(base, ident, _) { + ast::expr_field(base, ident, _) => { return trans_rec_field(cx, base, ident); } - ast::expr_index(base, idx) { + ast::expr_index(base, idx) => { return trans_index(cx, e, base, idx); } - ast::expr_unary(ast::deref, base) { + ast::expr_unary(ast::deref, base) => { let ccx = cx.ccx(); let sub = trans_temp_expr(cx, base); let t = expr_ty(cx, base); let val = alt check ty::get(t).struct { - ty::ty_box(_) { + ty::ty_box(_) => { let non_gc_val = non_gc_box_cast(sub.bcx, sub.val); GEPi(sub.bcx, non_gc_val, ~[0u, abi::box_field_body]) } - ty::ty_uniq(_) { + ty::ty_uniq(_) => { let non_gc_val = non_gc_box_cast(sub.bcx, sub.val); GEPi(sub.bcx, non_gc_val, ~[0u, abi::box_field_body]) } - ty::ty_enum(_, _) { + ty::ty_enum(_, _) => { let ety = expr_ty(cx, e); let ellty = T_ptr(type_of(ccx, ety)); PointerCast(sub.bcx, sub.val, ellty) } - ty::ty_ptr(_) | ty::ty_rptr(_,_) { sub.val } + ty::ty_ptr(_) | ty::ty_rptr(_,_) => sub.val }; return lval_owned(sub.bcx, val); } - _ { cx.sess().span_bug(e.span, ~"non-lval in trans_lval"); } + _ => cx.sess().span_bug(e.span, ~"non-lval in trans_lval") } } } @@ -2689,11 +2690,11 @@ fn non_gc_box_cast(cx: block, val: ValueRef) -> ValueRef { fn lval_maybe_callee_to_lval(c: lval_maybe_callee, sp: span) -> lval_result { alt c.env { - self_env(*) { + self_env(*) => { c.bcx.sess().span_bug(sp, ~"implicitly binding method call"); } - is_closure { {bcx: c.bcx, val: c.val, kind: c.kind} } - null_env { + is_closure => { {bcx: c.bcx, val: c.val, kind: c.kind} } + null_env => { let llfnty = llvm::LLVMGetElementType(val_ty(c.val)); let llfn = create_real_fn_pair(c.bcx, llfnty, c.val, null_env_ptr(c.bcx)); @@ -2732,14 +2733,14 @@ enum cast_kind { cast_pointer, cast_integral, cast_float, cast_enum, cast_other, } fn cast_type_kind(t: ty::t) -> cast_kind { alt ty::get(t).struct { - ty::ty_float(*) {cast_float} - ty::ty_ptr(*) {cast_pointer} - ty::ty_rptr(*) {cast_pointer} - ty::ty_int(*) {cast_integral} - ty::ty_uint(*) {cast_integral} - ty::ty_bool {cast_integral} - ty::ty_enum(*) {cast_enum} - _ {cast_other} + ty::ty_float(*) => cast_float, + ty::ty_ptr(*) => cast_pointer, + ty::ty_rptr(*) => cast_pointer, + ty::ty_int(*) => cast_integral, + ty::ty_uint(*) => cast_integral, + ty::ty_bool => cast_integral, + ty::ty_enum(*) => cast_enum, + _ => cast_other } } @@ -2750,8 +2751,8 @@ fn trans_cast(cx: block, e: @ast::expr, id: ast::node_id, let ccx = cx.ccx(); let t_out = node_id_type(cx, id); alt ty::get(t_out).struct { - ty::ty_trait(_, _) { return impl::trans_cast(cx, e, id, dest); } - _ {} + ty::ty_trait(_, _) => return impl::trans_cast(cx, e, id, dest), + _ => () } let e_res = trans_temp_expr(cx, e); let ll_t_in = val_ty(e_res.val); @@ -2764,46 +2765,47 @@ fn trans_cast(cx: block, e: @ast::expr, id: ast::node_id, let newval = alt {in: k_in, out: k_out} { - {in: cast_integral, out: cast_integral} { + {in: cast_integral, out: cast_integral} => { int_cast(e_res.bcx, ll_t_out, ll_t_in, e_res.val, s_in) } - {in: cast_float, out: cast_float} { + {in: cast_float, out: cast_float} => { float_cast(e_res.bcx, ll_t_out, ll_t_in, e_res.val) } - {in: cast_integral, out: cast_float} { + {in: cast_integral, out: cast_float} => { if s_in { SIToFP(e_res.bcx, e_res.val, ll_t_out) } else { UIToFP(e_res.bcx, e_res.val, ll_t_out) } } - {in: cast_float, out: cast_integral} { + {in: cast_float, out: cast_integral} => { if ty::type_is_signed(t_out) { FPToSI(e_res.bcx, e_res.val, ll_t_out) } else { FPToUI(e_res.bcx, e_res.val, ll_t_out) } } - {in: cast_integral, out: cast_pointer} { + {in: cast_integral, out: cast_pointer} => { IntToPtr(e_res.bcx, e_res.val, ll_t_out) } - {in: cast_pointer, out: cast_integral} { + {in: cast_pointer, out: cast_integral} => { PtrToInt(e_res.bcx, e_res.val, ll_t_out) } - {in: cast_pointer, out: cast_pointer} { + {in: cast_pointer, out: cast_pointer} => { PointerCast(e_res.bcx, e_res.val, ll_t_out) } {in: cast_enum, out: cast_integral} | - {in: cast_enum, out: cast_float} { + {in: cast_enum, out: cast_float} => { let cx = e_res.bcx; let llenumty = T_opaque_enum_ptr(ccx); let av_enum = PointerCast(cx, e_res.val, llenumty); let lldiscrim_a_ptr = GEPi(cx, av_enum, ~[0u, 0u]); let lldiscrim_a = Load(cx, lldiscrim_a_ptr); alt k_out { - cast_integral {int_cast(e_res.bcx, ll_t_out, - val_ty(lldiscrim_a), lldiscrim_a, true)} - cast_float {SIToFP(e_res.bcx, lldiscrim_a, ll_t_out)} - _ { ccx.sess.bug(~"translating unsupported cast.") } + cast_integral => int_cast(e_res.bcx, ll_t_out, + val_ty(lldiscrim_a), + lldiscrim_a, true), + cast_float => SIToFP(e_res.bcx, lldiscrim_a, ll_t_out), + _ => ccx.sess.bug(~"translating unsupported cast.") } } - _ { ccx.sess.bug(~"translating unsupported cast.") } + _ => ccx.sess.bug(~"translating unsupported cast.") }; return store_in_dest(e_res.bcx, newval, dest); } @@ -2811,9 +2813,12 @@ fn trans_cast(cx: block, e: @ast::expr, id: ast::node_id, fn trans_loop_body(bcx: block, e: @ast::expr, ret_flag: option<ValueRef>, dest: dest) -> block { alt check e.node { - ast::expr_loop_body(b@@{node: ast::expr_fn_block(decl, body, cap), _}) { + ast::expr_loop_body(b@@{ + node: ast::expr_fn_block(decl, body, cap), + _ + }) => { alt check ty::get(expr_ty(bcx, e)).struct { - ty::ty_fn({proto, _}) { + ty::ty_fn({proto, _}) => { closure::trans_expr_fn(bcx, proto, decl, body, b.id, cap, some(ret_flag), dest) @@ -2838,16 +2843,14 @@ fn trans_arg_expr(cx: block, arg: ty::arg, lldestty: TypeRef, e: @ast::expr, // translate the arg expr as an lvalue let lv = alt ret_flag { // If there is a ret_flag, this *must* be a loop body - some(ptr) { - alt check e.node { - ast::expr_loop_body(blk) { + some(ptr) => alt check e.node { + ast::expr_loop_body(blk) => { let scratch = alloc_ty(cx, expr_ty(cx, blk)); let bcx = trans_loop_body(cx, e, ret_flag, save_in(scratch)); {bcx: bcx, val: scratch, kind: lv_temporary} - } } } - none { + none => { trans_temp_lval(cx, e) } }; @@ -2882,21 +2885,21 @@ fn trans_arg_expr(cx: block, arg: ty::arg, lldestty: TypeRef, e: @ast::expr, val = llvm::LLVMGetUndef(lldestty); } else { alt arg_mode { - ast::by_ref | ast::by_mutbl_ref { + ast::by_ref | ast::by_mutbl_ref => { // Ensure that the value is spilled into memory: if lv.kind != lv_owned && ty::type_is_immediate(e_ty) { val = do_spill_noroot(bcx, val); } } - ast::by_val { + ast::by_val => { // Ensure that the value is not spilled into memory: if lv.kind == lv_owned || !ty::type_is_immediate(e_ty) { val = Load(bcx, val); } } - ast::by_copy | ast::by_move { + ast::by_copy | ast::by_move => { // Ensure that an owned copy of the value is in memory: let alloc = alloc_ty(bcx, arg.ty); let move_out = arg_mode == ast::by_move || @@ -2947,19 +2950,19 @@ fn adapt_borrowed_value(lv: lval_result, } alt ty::get(e_ty).struct { - ty::ty_uniq(mt) | ty::ty_box(mt) { + ty::ty_uniq(mt) | ty::ty_box(mt) => { let box_ptr = load_value_from_lval_result(lv, e_ty); let body_ptr = GEPi(bcx, box_ptr, ~[0u, abi::box_field_body]); let rptr_ty = ty::mk_rptr(bcx.tcx(), ty::re_static, mt); return {lv: lval_temp(bcx, body_ptr), ty: rptr_ty}; } - ty::ty_estr(_) | ty::ty_evec(_, _) { + ty::ty_estr(_) | ty::ty_evec(_, _) => { let ccx = bcx.ccx(); let val = alt lv.kind { - lv_temporary { lv.val } - lv_owned { load_if_immediate(bcx, lv.val, e_ty) } - lv_owned_imm { lv.val } + lv_temporary => lv.val, + lv_owned => load_if_immediate(bcx, lv.val, e_ty), + lv_owned_imm => lv.val }; let unit_ty = ty::sequence_element_type(ccx.tcx, e_ty); @@ -2984,7 +2987,7 @@ fn adapt_borrowed_value(lv: lval_result, return {lv: lval_temp(bcx, p), ty: slice_ty}; } - _ { + _ => { bcx.tcx().sess.span_bug( e.span, fmt!{"cannot borrow a value of type %s", ppaux::ty_to_str(bcx.tcx(), e_ty)}); @@ -3017,13 +3020,13 @@ fn trans_args(cx: block, llenv: ValueRef, args: call_args, fn_ty: ty::t, let retty = ty::ty_fn_ret(fn_ty); // Arg 0: Output pointer. let llretslot = alt dest { - ignore { + ignore => { if ty::type_is_nil(retty) { llvm::LLVMGetUndef(T_ptr(T_nil())) } else { alloc_ty(bcx, retty) } } - save_in(dst) { dst } - by_val(_) { alloc_ty(bcx, retty) } + save_in(dst) => dst, + by_val(_) => alloc_ty(bcx, retty) }; vec::push(llargs, llretslot); @@ -3037,7 +3040,7 @@ fn trans_args(cx: block, llenv: ValueRef, args: call_args, fn_ty: ty::t, // This will be needed if this is a generic call, because the callee has // to cast her view of the arguments to the caller's view. alt args { - arg_exprs(es) { + arg_exprs(es) => { let llarg_tys = type_of_explicit_args(ccx, arg_tys); let last = es.len() - 1u; do vec::iteri(es) |i, e| { @@ -3048,7 +3051,7 @@ fn trans_args(cx: block, llenv: ValueRef, args: call_args, fn_ty: ty::t, vec::push(llargs, r.val); } } - arg_vals(vs) { + arg_vals(vs) => { vec::push_all(llargs, vs); } } @@ -3081,8 +3084,8 @@ fn body_contains_ret(body: ast::blk) -> bool { visit_expr: |e: @ast::expr, cx: {mut found: bool}, v| { if !cx.found { alt e.node { - ast::expr_ret(_) { cx.found = true; } - _ { visit::visit_expr(e, cx, v); } + ast::expr_ret(_) => cx.found = true, + _ => visit::visit_expr(e, cx, v), } } } with *visit::default_visitor() @@ -3102,13 +3105,16 @@ fn trans_call_inner( do with_scope(in_cx, call_info, ~"call") |cx| { let ret_in_loop = alt args { - arg_exprs(args) { args.len() > 0u && alt vec::last(args).node { - ast::expr_loop_body(@{node: ast::expr_fn_block(_, body, _), _}) { - body_contains_ret(body) + arg_exprs(args) => { + args.len() > 0u && alt vec::last(args).node { + ast::expr_loop_body(@{ + node: ast::expr_fn_block(_, body, _), + _ + }) => body_contains_ret(body), + _ => false } - _ { false } - } } - _ { false } + } + _ => false }; let f_res = get_callee(cx); @@ -3122,13 +3128,13 @@ fn trans_call_inner( let mut faddr = f_res.val; let llenv = alt f_res.env { - null_env { + null_env => { llvm::LLVMGetUndef(T_opaque_box_ptr(ccx)) } - self_env(e, _, _) { + self_env(e, _, _) => { PointerCast(bcx, e, T_opaque_box_ptr(ccx)) } - is_closure { + is_closure => { // It's a closure. Have to fetch the elements if f_res.kind == lv_owned { faddr = load_if_immediate(bcx, faddr, fn_expr_ty); @@ -3155,13 +3161,13 @@ fn trans_call_inner( for the call itself is unreachable. */ bcx = invoke(bcx, faddr, llargs); alt dest { - ignore { + ignore => { if llvm::LLVMIsUndef(llretslot) != lib::llvm::True { bcx = drop_ty(bcx, llretslot, ret_ty); } } - save_in(_) { } // Already saved by callee - by_val(cell) { + save_in(_) => { } // Already saved by callee + by_val(cell) => { *cell = Load(bcx, llretslot); } } @@ -3215,10 +3221,10 @@ fn need_invoke(bcx: block) -> bool { let mut cur = bcx; loop { alt cur.kind { - block_scope(inf) { + block_scope(inf) => { for vec::each(inf.cleanups) |cleanup| { alt cleanup { - clean(_, cleanup_type) | clean_temp(_, _, cleanup_type) { + clean(_, cleanup_type) | clean_temp(_, _, cleanup_type) => { if cleanup_type == normal_exit_and_unwind { return true; } @@ -3226,11 +3232,11 @@ fn need_invoke(bcx: block) -> bool { } } } - _ { } + _ => () } cur = alt cur.parent { - some(next) { next } - none { return false; } + some(next) => next, + none => return false } } } @@ -3239,8 +3245,8 @@ fn have_cached_lpad(bcx: block) -> bool { let mut res = false; do in_lpad_scope_cx(bcx) |inf| { alt inf.landing_pad { - some(_) { res = true; } - none { res = false; } + some(_) => res = true, + none => res = false } } return res; @@ -3250,12 +3256,12 @@ fn in_lpad_scope_cx(bcx: block, f: fn(scope_info)) { let mut bcx = bcx; loop { alt bcx.kind { - block_scope(inf) { + block_scope(inf) => { if inf.cleanups.len() > 0u || is_none(bcx.parent) { f(inf); return; } } - _ {} + _ => () } bcx = block_parent(bcx); } @@ -3268,15 +3274,15 @@ fn get_landing_pad(bcx: block) -> BasicBlockRef { do in_lpad_scope_cx(bcx) |inf| { // If there is a valid landing pad still around, use it alt copy inf.landing_pad { - some(target) { cached = some(target); } - none { + some(target) => cached = some(target), + none => { pad_bcx = lpad_block(bcx, ~"unwind"); inf.landing_pad = some(pad_bcx.llbb); } } } // Can't return from block above - alt cached { some(b) { return b; } none {} } + alt cached { some(b) => return b, none => () } // The landing pad return type (the type being propagated). Not sure what // this represents but it's determined by the personality function and // this is what the EH proposal example uses. @@ -3298,8 +3304,8 @@ fn get_landing_pad(bcx: block) -> BasicBlockRef { // We store the retval in a function-central alloca, so that calls to // Resume can find it. alt copy bcx.fcx.personality { - some(addr) { Store(pad_bcx, llretval, addr); } - none { + some(addr) => Store(pad_bcx, llretval, addr), + none => { let addr = alloca(pad_bcx, val_ty(llretval)); bcx.fcx.personality = some(addr); Store(pad_bcx, llretval, addr); @@ -3315,12 +3321,12 @@ fn trans_tup(bcx: block, elts: ~[@ast::expr], dest: dest) -> block { let _icx = bcx.insn_ctxt(~"trans_tup"); let mut bcx = bcx; let addr = alt dest { - ignore { + ignore => { for vec::each(elts) |ex| { bcx = trans_expr(bcx, ex, ignore); } return bcx; } - save_in(pos) { pos } - _ { bcx.tcx().sess.bug(~"trans_tup: weird dest"); } + save_in(pos) => pos, + _ => bcx.tcx().sess.bug(~"trans_tup: weird dest") }; let mut temp_cleanups = ~[]; for vec::eachi(elts) |i, e| { @@ -3341,16 +3347,16 @@ fn trans_rec(bcx: block, fields: ~[ast::field], let t = node_id_type(bcx, id); let mut bcx = bcx; let addr = alt check dest { - ignore { + ignore => { for vec::each(fields) |fld| { bcx = trans_expr(bcx, fld.node.expr, ignore); } return bcx; } - save_in(pos) { pos } + save_in(pos) => pos }; - let ty_fields = alt check ty::get(t).struct { ty::ty_rec(f) { f } }; + let ty_fields = alt check ty::get(t).struct { ty::ty_rec(f) => f }; let mut temp_cleanups = ~[]; for fields.each |fld| { @@ -3363,7 +3369,7 @@ fn trans_rec(bcx: block, fields: ~[ast::field], vec::push(temp_cleanups, dst); } alt base { - some(bexp) { + some(bexp) => { let {bcx: cx, val: base_val} = trans_temp_expr(bcx, bexp); bcx = cx; // Copy over inherited fields @@ -3376,7 +3382,7 @@ fn trans_rec(bcx: block, fields: ~[ast::field], } } } - none {} + none => () }; // Now revoke the cleanups as we pass responsibility for the data @@ -3526,9 +3532,9 @@ fn trans_temp_expr(bcx: block, e: @ast::expr) -> result { fn load_value_from_lval_result(lv: lval_result, ty: ty::t) -> ValueRef { alt lv.kind { - lv_temporary { lv.val } - lv_owned { load_if_immediate(lv.bcx, lv.val, ty) } - lv_owned_imm { lv.val } + lv_temporary => lv.val, + lv_owned => load_if_immediate(lv.bcx, lv.val, ty), + lv_owned_imm => lv.val } } @@ -3561,14 +3567,14 @@ fn add_root_cleanup(bcx: block, scope_id: ast::node_id, let mut bcx_sid = bcx; loop { bcx_sid = alt bcx_sid.node_info { - some({id, _}) if id == scope_id { return bcx_sid; } - _ { + some({id, _}) if id == scope_id => { + return bcx_sid + } + _ => { alt bcx_sid.parent { - none { - bcx.tcx().sess.bug( - fmt!{"no enclosing scope with id %d", scope_id}); - } - some(bcx_par) { bcx_par } + none => bcx.tcx().sess.bug( + fmt!{"no enclosing scope with id %d", scope_id}), + some(bcx_par) => bcx_par } } } @@ -3589,8 +3595,8 @@ fn trans_expr(bcx: block, e: @ast::expr, dest: dest) -> block { } return alt bcx.ccx().maps.root_map.find({id:e.id, derefs:0u}) { - none { unrooted(bcx, e, dest) } - some(scope_id) { + none => unrooted(bcx, e, dest), + some(scope_id) => { debug!{"expression %d found in root map with scope %d", e.id, scope_id}; @@ -3613,52 +3619,52 @@ fn trans_expr(bcx: block, e: @ast::expr, dest: dest) -> block { fn unrooted(bcx: block, e: @ast::expr, dest: dest) -> block { let tcx = bcx.tcx(); alt e.node { - ast::expr_if(cond, thn, els) { + ast::expr_if(cond, thn, els) => { return trans_if(bcx, cond, thn, els, dest); } - ast::expr_alt(expr, arms, mode) { + ast::expr_alt(expr, arms, mode) => { return alt::trans_alt(bcx, e, expr, arms, mode, dest); } - ast::expr_block(blk) { + ast::expr_block(blk) => { return do with_scope(bcx, blk.info(), ~"block-expr body") |bcx| { trans_block(bcx, blk, dest) }; } - ast::expr_rec(args, base) { + ast::expr_rec(args, base) => { return trans_rec(bcx, args, base, e.id, dest); } - ast::expr_struct(_, fields) { + ast::expr_struct(_, fields) => { return trans_struct(bcx, e.span, fields, e.id, dest); } - ast::expr_tup(args) { return trans_tup(bcx, args, dest); } - ast::expr_vstore(e, v) { + ast::expr_tup(args) => { return trans_tup(bcx, args, dest); } + ast::expr_vstore(e, v) => { return tvec::trans_vstore(bcx, e, v, dest); } - ast::expr_lit(lit) { return trans_lit(bcx, e, *lit, dest); } - ast::expr_vec(args, _) { + ast::expr_lit(lit) => return trans_lit(bcx, e, *lit, dest), + ast::expr_vec(args, _) => { return tvec::trans_evec(bcx, tvec::individual_evec(args), ast::vstore_fixed(none), e.id, dest); } - ast::expr_repeat(element, count_expr, _) { + ast::expr_repeat(element, count_expr, _) => { let count = ty::eval_repeat_count(bcx.tcx(), count_expr, e.span); return tvec::trans_evec(bcx, tvec::repeating_evec(element, count), ast::vstore_fixed(none), e.id, dest); } - ast::expr_binary(op, lhs, rhs) { + ast::expr_binary(op, lhs, rhs) => { return trans_binary(bcx, op, lhs, rhs, dest, e); } - ast::expr_unary(op, x) { + ast::expr_unary(op, x) => { assert op != ast::deref; // lvals are handled above return trans_unary(bcx, op, x, e, dest); } - ast::expr_addr_of(_, x) { return trans_addr_of(bcx, x, dest); } - ast::expr_fn(proto, decl, body, cap_clause) { + ast::expr_addr_of(_, x) => { return trans_addr_of(bcx, x, dest); } + ast::expr_fn(proto, decl, body, cap_clause) => { return closure::trans_expr_fn(bcx, proto, decl, body, e.id, cap_clause, none, dest); } - ast::expr_fn_block(decl, body, cap_clause) { + ast::expr_fn_block(decl, body, cap_clause) => { alt check ty::get(expr_ty(bcx, e)).struct { - ty::ty_fn({proto, _}) { + ty::ty_fn({proto, _}) => { debug!{"translating fn_block %s with type %s", expr_to_str(e), ppaux::ty_to_str(tcx, expr_ty(bcx, e))}; @@ -3667,23 +3673,23 @@ fn trans_expr(bcx: block, e: @ast::expr, dest: dest) -> block { } } } - ast::expr_loop_body(blk) { + ast::expr_loop_body(blk) => { return trans_loop_body(bcx, e, none, dest); } - ast::expr_do_body(blk) { + ast::expr_do_body(blk) => { return trans_expr(bcx, blk, dest); } - ast::expr_copy(a) | ast::expr_unary_move(a) { + ast::expr_copy(a) | ast::expr_unary_move(a) => { if !expr_is_lval(bcx, a) { return trans_expr(bcx, a, dest); } else { return lval_to_dps(bcx, a, dest); } } - ast::expr_cast(val, _) { return trans_cast(bcx, val, e.id, dest); } - ast::expr_call(f, args, _) { + ast::expr_cast(val, _) => return trans_cast(bcx, val, e.id, dest), + ast::expr_call(f, args, _) => { return trans_call(bcx, e, f, arg_exprs(args), e.id, dest); } - ast::expr_field(base, _, _) { + ast::expr_field(base, _, _) => { if dest == ignore { return trans_expr(bcx, base, ignore); } let callee = trans_callee(bcx, e), ty = expr_ty(bcx, e); let lv = lval_maybe_callee_to_lval(callee, e.span); @@ -3691,7 +3697,7 @@ fn trans_expr(bcx: block, e: @ast::expr, dest: dest) -> block { memmove_ty(lv.bcx, get_dest_addr(dest), lv.val, ty); return lv.bcx; } - ast::expr_index(base, idx) { + ast::expr_index(base, idx) => { // If it is here, it's not an lval, so this is a user-defined // index op let origin = bcx.ccx().maps.method_map.get(e.id); @@ -3705,39 +3711,39 @@ fn trans_expr(bcx: block, e: @ast::expr, dest: dest) -> block { } // These return nothing - ast::expr_break { + ast::expr_break => { assert dest == ignore; return trans_break(bcx); } - ast::expr_again { + ast::expr_again => { assert dest == ignore; return trans_cont(bcx); } - ast::expr_ret(ex) { + ast::expr_ret(ex) => { assert dest == ignore; return trans_ret(bcx, ex); } - ast::expr_fail(expr) { + ast::expr_fail(expr) => { assert dest == ignore; return trans_fail_expr(bcx, some(e.span), expr); } - ast::expr_log(_, lvl, a) { + ast::expr_log(_, lvl, a) => { assert dest == ignore; return trans_log(e, lvl, bcx, a); } - ast::expr_assert(a) { + ast::expr_assert(a) => { assert dest == ignore; return trans_check_expr(bcx, e, a, ~"Assertion"); } - ast::expr_while(cond, body) { + ast::expr_while(cond, body) => { assert dest == ignore; return trans_while(bcx, cond, body); } - ast::expr_loop(body) { + ast::expr_loop(body) => { assert dest == ignore; return trans_loop(bcx, body); } - ast::expr_assign(dst, src) { + ast::expr_assign(dst, src) => { assert dest == ignore; let src_r = trans_temp_lval(bcx, src); let {bcx, val: addr, kind} = trans_lval(src_r.bcx, dst); @@ -3747,7 +3753,7 @@ fn trans_expr(bcx: block, e: @ast::expr, dest: dest) -> block { return store_temp_expr(bcx, DROP_EXISTING, addr, src_r, expr_ty(bcx, src), is_last_use); } - ast::expr_move(dst, src) { + ast::expr_move(dst, src) => { // FIXME: calculate copy init-ness in typestate. (#839) assert dest == ignore; let src_r = trans_temp_lval(bcx, src); @@ -3756,7 +3762,7 @@ fn trans_expr(bcx: block, e: @ast::expr, dest: dest) -> block { return move_val(bcx, DROP_EXISTING, addr, src_r, expr_ty(bcx, src)); } - ast::expr_swap(dst, src) { + ast::expr_swap(dst, src) => { assert dest == ignore; let lhs_res = trans_lval(bcx, dst); assert lhs_res.kind == lv_owned; @@ -3769,11 +3775,11 @@ fn trans_expr(bcx: block, e: @ast::expr, dest: dest) -> block { return move_val(bcx, INIT, rhs_res.val, lval_owned(bcx, tmp_alloc), t); } - ast::expr_assign_op(op, dst, src) { + ast::expr_assign_op(op, dst, src) => { assert dest == ignore; return trans_assign_op(bcx, e, op, dst, src); } - _ { + _ => { bcx.tcx().sess.span_bug(e.span, ~"trans_expr reached \ fall-through case"); } @@ -3796,7 +3802,7 @@ fn lval_result_to_dps(lv: lval_result, ty: ty::t, let mut {bcx, val, kind} = lv; let ccx = bcx.ccx(); alt dest { - by_val(cell) { + by_val(cell) => { if kind == lv_temporary { revoke_clean(bcx, val); *cell = val; @@ -3812,10 +3818,10 @@ fn lval_result_to_dps(lv: lval_result, ty: ty::t, bcx = cx; } } - save_in(loc) { + save_in(loc) => { bcx = store_temp_expr(bcx, INIT, loc, lv, ty, last_use); } - ignore {} + ignore => () } return bcx; } @@ -3863,7 +3869,7 @@ fn trans_log(log_ex: @ast::expr, lvl: @ast::expr, let modpath = vec::append( ~[path_mod(ccx.link_meta.name)], vec::filter(bcx.fcx.path, |e| - alt e { path_mod(_) { true } _ { false } } + alt e { path_mod(_) => true, _ => false } )); let modname = path_str(modpath); @@ -3922,7 +3928,7 @@ fn trans_fail_expr(bcx: block, sp_opt: option<span>, let _icx = bcx.insn_ctxt(~"trans_fail_expr"); let mut bcx = bcx; alt fail_expr { - some(expr) { + some(expr) => { let ccx = bcx.ccx(), tcx = ccx.tcx; let expr_res = trans_temp_expr(bcx, expr); let e_ty = expr_ty(bcx, expr); @@ -3940,7 +3946,7 @@ fn trans_fail_expr(bcx: block, sp_opt: option<span>, ppaux::ty_to_str(tcx, e_ty)); } } - _ { return trans_fail(bcx, sp_opt, ~"explicit failure"); } + _ => return trans_fail(bcx, sp_opt, ~"explicit failure") } } @@ -3950,13 +3956,13 @@ fn trans_trace(bcx: block, sp_opt: option<span>, trace_str: ~str) { add_comment(bcx, trace_str); let V_trace_str = C_cstr(bcx.ccx(), trace_str); let {V_filename, V_line} = alt sp_opt { - some(sp) { + some(sp) => { let sess = bcx.sess(); let loc = codemap::lookup_char_pos(sess.parse_sess.cm, sp.lo); {V_filename: C_cstr(bcx.ccx(), loc.file.name), V_line: loc.line as int} } - none { + none => { {V_filename: C_cstr(bcx.ccx(), ~"<runtime>"), V_line: 0} } @@ -3980,13 +3986,13 @@ fn trans_fail_value(bcx: block, sp_opt: option<span>, let _icx = bcx.insn_ctxt(~"trans_fail_value"); let ccx = bcx.ccx(); let {V_filename, V_line} = alt sp_opt { - some(sp) { + some(sp) => { let sess = bcx.sess(); let loc = codemap::lookup_char_pos(sess.parse_sess.cm, sp.lo); {V_filename: C_cstr(bcx.ccx(), loc.file.name), V_line: loc.line as int} } - none { + none => { {V_filename: C_cstr(bcx.ccx(), ~"<runtime>"), V_line: 0} } @@ -4022,7 +4028,7 @@ fn trans_break_cont(bcx: block, to_end: bool) let mut target; loop { alt unwind.kind { - block_scope({loop_break: some(brk), _}) { + block_scope({loop_break: some(brk), _}) => { target = if to_end { brk } else { @@ -4030,12 +4036,12 @@ fn trans_break_cont(bcx: block, to_end: bool) }; break; } - _ {} + _ => () } unwind = alt unwind.parent { - some(cx) { cx } + some(cx) => cx, // This is a return from a loop body block - none { + none => { Store(bcx, C_bool(!to_end), bcx.fcx.llretptr); cleanup_and_leave(bcx, none, some(bcx.fcx.llreturn)); Unreachable(bcx); @@ -4060,25 +4066,25 @@ fn trans_ret(bcx: block, e: option<@ast::expr>) -> block { let _icx = bcx.insn_ctxt(~"trans_ret"); let mut bcx = bcx; let retptr = alt copy bcx.fcx.loop_ret { - some({flagptr, retptr}) { + some({flagptr, retptr}) => { // This is a loop body return. Must set continue flag (our retptr) // to false, return flag to true, and then store the value in the // parent's retptr. Store(bcx, C_bool(true), flagptr); Store(bcx, C_bool(false), bcx.fcx.llretptr); alt e { - some(x) { PointerCast(bcx, retptr, - T_ptr(type_of(bcx.ccx(), expr_ty(bcx, x)))) } - none { retptr } + some(x) => PointerCast(bcx, retptr, + T_ptr(type_of(bcx.ccx(), expr_ty(bcx, x)))), + none => retptr } } - none { bcx.fcx.llretptr } + none => bcx.fcx.llretptr }; alt e { - some(x) { + some(x) => { bcx = trans_expr_save_in(bcx, x, retptr); } - _ {} + _ => () } cleanup_and_leave(bcx, none, some(bcx.fcx.llreturn)); Unreachable(bcx); @@ -4094,8 +4100,8 @@ fn init_local(bcx: block, local: @ast::local) -> block { let _icx = bcx.insn_ctxt(~"init_local"); let ty = node_id_type(bcx, local.node.id); let llptr = alt bcx.fcx.lllocals.find(local.node.id) { - some(local_mem(v)) { v } - _ { bcx.tcx().sess.span_bug(local.span, + some(local_mem(v)) => v, + _ => { bcx.tcx().sess.span_bug(local.span, ~"init_local: Someone forgot to document why it's\ safe to assume local.node.init must be local_mem!"); } @@ -4103,7 +4109,7 @@ fn init_local(bcx: block, local: @ast::local) -> block { let mut bcx = bcx; alt local.node.init { - some(init) { + some(init) => { if init.op == ast::init_assign || !expr_is_lval(bcx, init.expr) { bcx = trans_expr_save_in(bcx, init.expr, llptr); } else { // This is a move from an lval, must perform an actual move @@ -4111,7 +4117,7 @@ fn init_local(bcx: block, local: @ast::local) -> block { bcx = move_val(sub.bcx, INIT, llptr, sub, ty); } } - _ { bcx = zero_mem(bcx, llptr, ty); } + _ => bcx = zero_mem(bcx, llptr, ty), } // Make a note to drop this slot on the way out. add_clean(bcx, llptr, ty); @@ -4130,12 +4136,12 @@ fn trans_stmt(cx: block, s: ast::stmt) -> block { debuginfo::update_source_pos(cx, s.span); alt s.node { - ast::stmt_expr(e, _) | ast::stmt_semi(e, _) { + ast::stmt_expr(e, _) | ast::stmt_semi(e, _) => { bcx = trans_expr(cx, e, ignore); } - ast::stmt_decl(d, _) { + ast::stmt_decl(d, _) => { alt d.node { - ast::decl_local(locals) { + ast::decl_local(locals) => { for vec::each(locals) |local| { bcx = init_local(bcx, local); if cx.sess().opts.extra_debuginfo { @@ -4143,7 +4149,7 @@ fn trans_stmt(cx: block, s: ast::stmt) -> block { } } } - ast::decl_item(i) { trans_item(cx.fcx.ccx, *i); } + ast::decl_item(i) => trans_item(cx.fcx.ccx, *i) } } } @@ -4230,11 +4236,11 @@ fn trans_block_cleanups_(bcx: block, cleanup_cx: block, is_lpad: bool) -> if bcx.unreachable { return bcx; } let mut bcx = bcx; alt check cleanup_cx.kind { - block_scope({cleanups, _}) { + block_scope({cleanups, _}) => { let cleanups = copy cleanups; do vec::riter(cleanups) |cu| { alt cu { - clean(cfn, cleanup_type) | clean_temp(_, cfn, cleanup_type) { + clean(cfn, cleanup_type) | clean_temp(_, cfn, cleanup_type) => { // Some types don't need to be cleaned up during // landing pads because they can be freed en mass later if cleanup_type == normal_exit_and_unwind || !is_lpad { @@ -4266,7 +4272,7 @@ fn cleanup_and_leave(bcx: block, upto: option<BasicBlockRef>, } alt cur.kind { - block_scope(inf) if inf.cleanups.len() > 0u { + block_scope(inf) if inf.cleanups.len() > 0u => { for vec::find(inf.cleanup_paths, |cp| cp.target == leave).each |cp| { Br(bcx, cp.dest); @@ -4277,20 +4283,20 @@ fn cleanup_and_leave(bcx: block, upto: option<BasicBlockRef>, vec::push(inf.cleanup_paths, {target: leave, dest: sub_cx.llbb}); bcx = trans_block_cleanups_(sub_cx, cur, is_lpad); } - _ {} + _ => () } alt upto { - some(bb) { if cur.llbb == bb { break; } } - _ {} + some(bb) => { if cur.llbb == bb { break; } } + _ => () } cur = alt cur.parent { - some(next) { next } - none { assert is_none(upto); break; } + some(next) => next, + none => { assert is_none(upto); break; } }; } alt leave { - some(target) { Br(bcx, target); } - none { Resume(bcx, Load(bcx, option::get(bcx.fcx.personality))); } + some(target) => Br(bcx, target), + none => { Resume(bcx, Load(bcx, option::get(bcx.fcx.personality))); } } } @@ -4338,15 +4344,15 @@ fn with_cond(bcx: block, val: ValueRef, f: fn(block) -> block) -> block { fn block_locals(b: ast::blk, it: fn(@ast::local)) { for vec::each(b.node.stmts) |s| { alt s.node { - ast::stmt_decl(d, _) { + ast::stmt_decl(d, _) => { alt d.node { - ast::decl_local(locals) { + ast::decl_local(locals) => { for vec::each(locals) |local| { it(local); } } - _ {/* fall through */ } + _ => {/* fall through */ } } } - _ {/* fall through */ } + _ => {/* fall through */ } } } } @@ -4365,8 +4371,8 @@ fn alloc_local(cx: block, local: @ast::local) -> block { let _icx = cx.insn_ctxt(~"alloc_local"); let t = node_id_type(cx, local.node.id); let simple_name = alt local.node.pat.node { - ast::pat_ident(_, pth, none) { some(path_to_ident(pth)) } - _ { none } + ast::pat_ident(_, pth, none) => some(path_to_ident(pth)), + _ => none }; let val = alloc_ty(cx, t); if cx.sess().opts.debuginfo { @@ -4390,12 +4396,12 @@ fn trans_block(bcx: block, b: ast::blk, dest: dest) bcx = trans_stmt(bcx, *s); } alt b.node.expr { - some(e) { + some(e) => { let bt = ty::type_is_bot(expr_ty(bcx, e)); debuginfo::update_source_pos(bcx, e.span); bcx = trans_expr(bcx, e, if bt { ignore } else { dest }); } - _ { assert dest == ignore || bcx.unreachable; } + _ => assert dest == ignore || bcx.unreachable } return bcx; } @@ -4468,10 +4474,10 @@ fn create_llargs_for_fn_args(cx: fn_ctxt, // Skip the implicit arguments 0, and 1. let mut arg_n = first_real_arg; alt ty_self { - impl_self(tt) { + impl_self(tt) => { cx.llself = some({v: cx.llenv, t: tt}); } - no_self {} + no_self => () } // Populate the llargs field of the function context with the ValueRefs @@ -4498,12 +4504,14 @@ fn copy_args_to_allocas(fcx: fn_ctxt, bcx: block, args: ~[ast::arg], }; for vec::each(arg_tys) |arg| { let id = args[arg_n].id; - let argval = alt fcx.llargs.get(id) { local_mem(v) { v } - _ { epic_fail() } }; + let argval = alt fcx.llargs.get(id) { + local_mem(v) => v, + _ => epic_fail() + }; alt ty::resolved_mode(tcx, arg.mode) { - ast::by_mutbl_ref { } - ast::by_move | ast::by_copy { add_clean(bcx, argval, arg.ty); } - ast::by_val { + ast::by_mutbl_ref => (), + ast::by_move | ast::by_copy => add_clean(bcx, argval, arg.ty), + ast::by_val => { if !ty::type_is_immediate(arg.ty) { let alloc = alloc_ty(bcx, arg.ty); Store(bcx, argval, alloc); @@ -4512,7 +4520,7 @@ fn copy_args_to_allocas(fcx: fn_ctxt, bcx: block, args: ~[ast::arg], fcx.llargs.insert(id, local_imm(argval)); } } - ast::by_ref {} + ast::by_ref => () } if fcx.ccx.sess.opts.extra_debuginfo { debuginfo::create_arg(bcx, args[arg_n], args[arg_n].ty.span); @@ -4635,8 +4643,8 @@ fn trans_enum_variant(ccx: @crate_ctxt, enum_id: ast::node_id, param_substs, none); create_llargs_for_fn_args(fcx, no_self, fn_args); let ty_param_substs = alt param_substs { - some(substs) { substs.tys } - none { ~[] } + some(substs) => substs.tys, + none => ~[] }; let bcx = top_scope_block(fcx, none), lltop = bcx.llbb; let arg_tys = ty::ty_fn_args(node_id_type(bcx, variant.node.id)); @@ -4661,7 +4669,7 @@ fn trans_enum_variant(ccx: @crate_ctxt, enum_id: ast::node_id, // this function as an opaque blob due to the way that type_of() // works. So we have to cast to the destination's view of the type. let llarg = alt check fcx.llargs.find(va.id) { - some(local_mem(x)) { x } + some(local_mem(x)) => x }; let arg_ty = arg_tys[i].ty; memmove_ty(bcx, lldestptr, llarg, arg_ty); @@ -4777,10 +4785,10 @@ fn trans_class_dtor(ccx: @crate_ctxt, path: path, fn trans_item(ccx: @crate_ctxt, item: ast::item) { let _icx = ccx.insn_ctxt(~"trans_item"); let path = alt check ccx.tcx.items.get(item.id) { - ast_map::node_item(_, p) { p } + ast_map::node_item(_, p) => p }; alt item.node { - ast::item_fn(decl, tps, body) { + ast::item_fn(decl, tps, body) => { if decl.purity == ast::extern_fn { let llfndecl = get_item_val(ccx, item.id); foreign::trans_foreign_fn(ccx, @@ -4796,21 +4804,21 @@ fn trans_item(ccx: @crate_ctxt, item: ast::item) { } else { for vec::each(body.node.stmts) |stmt| { alt stmt.node { - ast::stmt_decl(@{node: ast::decl_item(i), _}, _) { + ast::stmt_decl(@{node: ast::decl_item(i), _}, _) => { trans_item(ccx, *i); } - _ {} + _ => () } } } } - ast::item_impl(tps, _, _, ms) { + ast::item_impl(tps, _, _, ms) => { impl::trans_impl(ccx, *path, item.ident, ms, tps); } - ast::item_mod(m) { + ast::item_mod(m) => { trans_mod(ccx, m); } - ast::item_enum(variants, tps) { + ast::item_enum(variants, tps) => { if tps.len() == 0u { let degen = variants.len() == 1u; let vi = ty::enum_variants(ccx.tcx, local_def(item.id)); @@ -4826,15 +4834,15 @@ fn trans_item(ccx: @crate_ctxt, item: ast::item) { } } } - ast::item_const(_, expr) { consts::trans_const(ccx, expr, item.id); } - ast::item_foreign_mod(foreign_mod) { + ast::item_const(_, expr) => consts::trans_const(ccx, expr, item.id), + ast::item_foreign_mod(foreign_mod) => { let abi = alt attr::foreign_abi(item.attrs) { - either::right(abi_) { abi_ } - either::left(msg) { ccx.sess.span_fatal(item.span, msg) } + either::right(abi_) => abi_, + either::left(msg) => ccx.sess.span_fatal(item.span, msg) }; foreign::trans_foreign_mod(ccx, foreign_mod, abi); } - ast::item_class(tps, _traits, items, m_ctor, m_dtor) { + ast::item_class(tps, _traits, items, m_ctor, m_dtor) => { if tps.len() == 0u { let psubsts = {tys: ty::ty_params_to_tys(ccx.tcx, tps), vtables: none, @@ -4855,7 +4863,7 @@ fn trans_item(ccx: @crate_ctxt, item: ast::item) { let (_, ms) = ast_util::split_class_items(items); impl::trans_impl(ccx, *path, item.ident, ms, tps); } - _ {/* fall through */ } + _ => {/* fall through */ } } } @@ -4914,8 +4922,8 @@ fn create_main_wrapper(ccx: @crate_ctxt, sp: span, main_llfn: ValueRef, let main_takes_argv = // invariant! alt ty::get(main_node_type).struct { - ty::ty_fn({inputs, _}) { inputs.len() != 0u } - _ { ccx.sess.span_fatal(sp, ~"main has a non-function type"); } + ty::ty_fn({inputs, _}) => inputs.len() != 0u, + _ => ccx.sess.span_fatal(sp, ~"main has a non-function type") }; let llfn = create_main(ccx, main_llfn, main_takes_argv); @@ -5003,7 +5011,7 @@ fn fill_fn_pair(bcx: block, pair: ValueRef, llfn: ValueRef, fn item_path(ccx: @crate_ctxt, i: @ast::item) -> path { vec::append( *alt check ccx.tcx.items.get(i.id) { - ast_map::node_item(_, p) { p } + ast_map::node_item(_, p) => p }, ~[path_name(i.ident)]) } @@ -5014,8 +5022,8 @@ fn get_dtor_symbol(ccx: @crate_ctxt, path: path, id: ast::node_id, substs: option<param_substs>) -> ~str { let t = ty::node_id_to_type(ccx.tcx, id); alt ccx.item_symbols.find(id) { - some(s) { s } - none if is_none(substs) { + some(s) => s, + none if is_none(substs) => { let s = mangle_exported_name( ccx, vec::append(path, ~[path_name(@ccx.names(~"dtor"))]), @@ -5023,11 +5031,11 @@ fn get_dtor_symbol(ccx: @crate_ctxt, path: path, id: ast::node_id, ccx.item_symbols.insert(id, s); s } - none { + none => { // Monomorphizing, so just make a symbol, don't add // this to item_symbols alt substs { - some(ss) { + some(ss) => { let mono_ty = ty::subst_tps(ccx.tcx, ss.tys, t); mangle_exported_name( ccx, @@ -5035,7 +5043,7 @@ fn get_dtor_symbol(ccx: @crate_ctxt, path: path, id: ast::node_id, ~[path_name(@ccx.names(~"dtor"))]), mono_ty) } - none { + none => { ccx.sess.bug(fmt!{"get_dtor_symbol: not monomorphizing and \ couldn't find a symbol for dtor %?", path}); } @@ -5047,14 +5055,14 @@ fn get_dtor_symbol(ccx: @crate_ctxt, path: path, id: ast::node_id, fn get_item_val(ccx: @crate_ctxt, id: ast::node_id) -> ValueRef { let tcx = ccx.tcx; alt ccx.item_vals.find(id) { - some(v) { v } - none { + some(v) => v, + none => { let mut exprt = false; let val = alt check ccx.tcx.items.get(id) { - ast_map::node_item(i, pth) { + ast_map::node_item(i, pth) => { let my_path = vec::append(*pth, ~[path_name(i.ident)]); alt check i.node { - ast::item_const(_, _) { + ast::item_const(_, _) => { let typ = ty::node_id_to_type(ccx.tcx, i.id); let s = mangle_exported_name(ccx, my_path, typ); let g = str::as_c_str(s, |buf| { @@ -5063,7 +5071,7 @@ fn get_item_val(ccx: @crate_ctxt, id: ast::node_id) -> ValueRef { ccx.item_symbols.insert(i.id, s); g } - ast::item_fn(decl, _, _) { + ast::item_fn(decl, _, _) => { let llfn = if decl.purity != ast::extern_fn { register_fn(ccx, i.span, my_path, i.id) } else { @@ -5074,7 +5082,7 @@ fn get_item_val(ccx: @crate_ctxt, id: ast::node_id) -> ValueRef { } } } - ast_map::node_method(m, impl_id, pth) { + ast_map::node_method(m, impl_id, pth) => { exprt = true; let mty = ty::node_id_to_type(ccx.tcx, id); let pth = vec::append(*pth, ~[path_name(@ccx.names(~"meth")), @@ -5083,17 +5091,17 @@ fn get_item_val(ccx: @crate_ctxt, id: ast::node_id) -> ValueRef { set_inline_hint_if_appr(m.attrs, llfn); llfn } - ast_map::node_foreign_item(ni, _, pth) { + ast_map::node_foreign_item(ni, _, pth) => { exprt = true; register_fn(ccx, ni.span, vec::append(*pth, ~[path_name(ni.ident)]), ni.id) } - ast_map::node_ctor(nm, tps, ctor, _, pt) { + ast_map::node_ctor(nm, tps, ctor, _, pt) => { let my_path = vec::append(*pt, ~[path_name(nm)]); register_fn(ccx, ctor.span, my_path, ctor.node.id) } - ast_map::node_dtor(tps, dt, parent_id, pt) { + ast_map::node_dtor(tps, dt, parent_id, pt) => { /* Don't just call register_fn, since we don't want to add the implicit self argument automatically (we want to make sure @@ -5114,13 +5122,13 @@ fn get_item_val(ccx: @crate_ctxt, id: ast::node_id) -> ValueRef { llfn } - ast_map::node_variant(v, enm, pth) { + ast_map::node_variant(v, enm, pth) => { assert v.node.args.len() != 0u; let pth = vec::append(*pth, ~[path_name(enm.ident), path_name(v.node.name)]); let llfn = alt check enm.node { - ast::item_enum(_, _) { + ast::item_enum(_, _) => { register_fn(ccx, v.span, pth, id) } }; @@ -5141,7 +5149,7 @@ fn get_item_val(ccx: @crate_ctxt, id: ast::node_id) -> ValueRef { fn trans_constant(ccx: @crate_ctxt, it: @ast::item) { let _icx = ccx.insn_ctxt(~"trans_constant"); alt it.node { - ast::item_enum(variants, _) { + ast::item_enum(variants, _) => { let vi = ty::enum_variants(ccx.tcx, {crate: ast::local_crate, node: it.id}); let mut i = 0; @@ -5163,7 +5171,7 @@ fn trans_constant(ccx: @crate_ctxt, it: @ast::item) { i += 1; } } - _ { } + _ => () } } @@ -5247,8 +5255,8 @@ fn declare_dbg_intrinsics(llmod: ModuleRef, fn trap(bcx: block) { let v: ~[ValueRef] = ~[]; alt bcx.ccx().intrinsics.find(~"llvm.trap") { - some(x) { Call(bcx, x, v); } - _ { bcx.sess().bug(~"unbound llvm.trap in trap"); } + some(x) => { Call(bcx, x, v); }, + _ => bcx.sess().bug(~"unbound llvm.trap in trap") } } @@ -5262,21 +5270,21 @@ fn push_rtcall(ccx: @crate_ctxt, name: ~str, did: ast::def_id) { fn gather_local_rtcalls(ccx: @crate_ctxt, crate: @ast::crate) { visit::visit_crate(*crate, (), visit::mk_simple_visitor(@{ visit_item: |item| alt item.node { - ast::item_fn(decl, _, _) { + ast::item_fn(decl, _, _) => { let attr_metas = attr::attr_metas( attr::find_attrs_by_name(item.attrs, ~"rt")); do vec::iter(attr_metas) |attr_meta| { alt attr::get_meta_item_list(attr_meta) { - some(list) { + some(list) => { let name = *attr::get_meta_item_name(vec::head(list)); push_rtcall(ccx, name, {crate: ast::local_crate, node: item.id}); } - none {} + none => () } } } - _ {} + _ => () } with *visit::default_simple_visitor() })); @@ -5287,9 +5295,9 @@ fn gather_external_rtcalls(ccx: @crate_ctxt) { do decoder::each_path(cmeta) |path| { let pathname = path.path_string; alt path.def_like { - decoder::dl_def(d) { + decoder::dl_def(d) => { alt d { - ast::def_fn(did, _) { + ast::def_fn(did, _) => { // FIXME (#2861): This should really iterate attributes // like gather_local_rtcalls, but we'll need to // export attributes in metadata/encoder before we can do @@ -5302,10 +5310,10 @@ fn gather_external_rtcalls(ccx: @crate_ctxt) { push_rtcall(ccx, name, did); } } - _ {} + _ => () } } - _ {} + _ => () } true } @@ -5415,7 +5423,7 @@ fn crate_ctxt_to_encode_parms(cx: @crate_ctxt) for defs.each |def| { if !def.reexp { again; } let path = alt check cx.tcx.items.get(exp_id) { - ast_map::node_export(_, path) { + ast_map::node_export(_, path) => { ast_map::path_to_str(*path) } }; diff --git a/src/rustc/middle/trans/build.rs b/src/rustc/middle/trans/build.rs index d664d11d1e4..6e7c41e0fa9 100644 --- a/src/rustc/middle/trans/build.rs +++ b/src/rustc/middle/trans/build.rs @@ -49,7 +49,10 @@ fn count_insn(cx: block, category: ~str) { s += ~"/"; s += category; - let n = alt h.find(s) { some(n) { n } _ { 0u } }; + let n = alt h.find(s) { + some(n) => n, + _ => 0u + }; h.insert(s, n+1u); } } diff --git a/src/rustc/middle/trans/closure.rs b/src/rustc/middle/trans/closure.rs index 7204ba67380..1912c509693 100644 --- a/src/rustc/middle/trans/closure.rs +++ b/src/rustc/middle/trans/closure.rs @@ -102,12 +102,12 @@ enum environment_value { fn ev_to_str(ccx: @crate_ctxt, ev: environment_value) -> ~str { alt ev { - env_copy(v, t, lk) { fmt!{"copy(%s,%s)", val_str(ccx.tn, v), - ty_to_str(ccx.tcx, t)} } - env_move(v, t, lk) { fmt!{"move(%s,%s)", val_str(ccx.tn, v), - ty_to_str(ccx.tcx, t)} } - env_ref(v, t, lk) { fmt!{"ref(%s,%s)", val_str(ccx.tn, v), - ty_to_str(ccx.tcx, t)} } + env_copy(v, t, lk) => fmt!{"copy(%s,%s)", val_str(ccx.tn, v), + ty_to_str(ccx.tcx, t)}, + env_move(v, t, lk) => fmt!{"move(%s,%s)", val_str(ccx.tn, v), + ty_to_str(ccx.tcx, t)}, + env_ref(v, t, lk) => fmt!{"ref(%s,%s)", val_str(ccx.tn, v), + ty_to_str(ccx.tcx, t)} } } @@ -125,9 +125,9 @@ fn mk_closure_tys(tcx: ty::ctxt, // Compute the closed over data for vec::each(bound_values) |bv| { vec::push(bound_tys, alt bv { - env_copy(_, t, _) { t } - env_move(_, t, _) { t } - env_ref(_, t, _) { t } + env_copy(_, t, _) => t, + env_move(_, t, _) => t, + env_ref(_, t, _) => t }); } let cdata_ty = ty::mk_tup(tcx, bound_tys); @@ -154,13 +154,9 @@ fn allocate_cbox(bcx: block, // Allocate and initialize the box: let {bcx, val} = alt ck { - ty::ck_box { - malloc_raw(bcx, cdata_ty, heap_shared) - } - ty::ck_uniq { - malloc_raw(bcx, cdata_ty, heap_exchange) - } - ty::ck_block { + ty::ck_box => malloc_raw(bcx, cdata_ty, heap_shared), + ty::ck_uniq => malloc_raw(bcx, cdata_ty, heap_exchange), + ty::ck_block => { let cbox_ty = tuplify_box_ty(tcx, cdata_ty); let llbox = base::alloc_ty(bcx, cbox_ty); nuke_ref_count(bcx, llbox); @@ -216,31 +212,31 @@ fn store_environment(bcx: block, let bound_data = GEPi(bcx, llbox, ~[0u, abi::box_field_body, i]); alt bv { - env_copy(val, ty, lv_owned) { + env_copy(val, ty, lv_owned) => { let val1 = load_if_immediate(bcx, val, ty); bcx = base::copy_val(bcx, INIT, bound_data, val1, ty); } - env_copy(val, ty, lv_owned_imm) { + env_copy(val, ty, lv_owned_imm) => { bcx = base::copy_val(bcx, INIT, bound_data, val, ty); } - env_copy(_, _, lv_temporary) { + env_copy(_, _, lv_temporary) => { fail ~"cannot capture temporary upvar"; } - env_move(val, ty, kind) { + env_move(val, ty, kind) => { let src = {bcx:bcx, val:val, kind:kind}; bcx = move_val(bcx, INIT, bound_data, src, ty); } - env_ref(val, ty, lv_owned) { + env_ref(val, ty, lv_owned) => { debug!{"> storing %s into %s", val_str(bcx.ccx().tn, val), val_str(bcx.ccx().tn, bound_data)}; Store(bcx, val, bound_data); } - env_ref(val, ty, lv_owned_imm) { + env_ref(val, ty, lv_owned_imm) => { let addr = do_spill_noroot(bcx, val); Store(bcx, addr, bound_data); } - env_ref(_, _, lv_temporary) { + env_ref(_, _, lv_temporary) => { fail ~"cannot capture temporary upvar"; } } @@ -272,23 +268,23 @@ fn build_closure(bcx0: block, syntax::ast_map::node_id_to_str(bcx.ccx().tcx.items, nid)}; let mut ty = node_id_type(bcx, nid); alt cap_var.mode { - capture::cap_ref { + capture::cap_ref => { assert ck == ty::ck_block; ty = ty::mk_mut_ptr(tcx, ty); vec::push(env_vals, env_ref(lv.val, ty, lv.kind)); } - capture::cap_copy { + capture::cap_copy => { let mv = alt check ccx.maps.last_use_map.find(id) { - none { false } - some(vars) { (*vars).contains(nid) } + none => false, + some(vars) => (*vars).contains(nid) }; if mv { vec::push(env_vals, env_move(lv.val, ty, lv.kind)); } else { vec::push(env_vals, env_copy(lv.val, ty, lv.kind)); } } - capture::cap_move { + capture::cap_move => { vec::push(env_vals, env_move(lv.val, ty, lv.kind)); } - capture::cap_drop { + capture::cap_drop => { assert lv.kind == lv_owned; bcx = drop_ty(bcx, lv.val, ty); bcx = zero_mem(bcx, lv.val, ty); @@ -297,8 +293,8 @@ fn build_closure(bcx0: block, } do option::iter(include_ret_handle) |flagptr| { let our_ret = alt bcx.fcx.loop_ret { - some({retptr, _}) { retptr } - none { bcx.fcx.llretptr } + some({retptr, _}) => retptr, + none => bcx.fcx.llretptr }; let nil_ret = PointerCast(bcx, our_ret, T_ptr(T_nil())); vec::push(env_vals, @@ -328,13 +324,13 @@ fn load_environment(fcx: fn_ctxt, let mut i = 0u; do vec::iter(cap_vars) |cap_var| { alt cap_var.mode { - capture::cap_drop { /* ignore */ } - _ { + capture::cap_drop => { /* ignore */ } + _ => { let mut upvarptr = GEPi(bcx, llcdata, ~[0u, i]); alt ck { - ty::ck_block { upvarptr = Load(bcx, upvarptr); } - ty::ck_uniq | ty::ck_box { } + ty::ck_block => { upvarptr = Load(bcx, upvarptr); } + ty::ck_uniq | ty::ck_box => () } let def_id = ast_util::def_id_of_def(cap_var.def); fcx.llupvars.insert(def_id.node, upvarptr); @@ -372,7 +368,7 @@ fn trans_expr_fn(bcx: block, let trans_closure_env = fn@(ck: ty::closure_kind) -> result { let cap_vars = capture::compute_capture_vars( ccx.tcx, id, proto, cap_clause); - let ret_handle = alt is_loop_body { some(x) { x } none { none } }; + let ret_handle = alt is_loop_body { some(x) => x, none => none }; let {llbox, cdata_ty, bcx} = build_closure(bcx, cap_vars, ck, id, ret_handle); trans_closure(ccx, sub_path, decl, body, llfn, no_self, @@ -388,10 +384,10 @@ fn trans_expr_fn(bcx: block, }; let {bcx: bcx, val: closure} = alt proto { - ast::proto_block { trans_closure_env(ty::ck_block) } - ast::proto_box { trans_closure_env(ty::ck_box) } - ast::proto_uniq { trans_closure_env(ty::ck_uniq) } - ast::proto_bare { + ast::proto_block => trans_closure_env(ty::ck_block), + ast::proto_box => trans_closure_env(ty::ck_box), + ast::proto_uniq => trans_closure_env(ty::ck_uniq), + ast::proto_bare => { trans_closure(ccx, sub_path, decl, body, llfn, no_self, none, id, |_fcx| { }, |_bcx| { }); {bcx: bcx, val: C_null(T_opaque_box_ptr(ccx))} @@ -423,10 +419,10 @@ fn make_fn_glue( return alt ty::get(t).struct { ty::ty_fn({proto: ast::proto_bare, _}) | - ty::ty_fn({proto: ast::proto_block, _}) { bcx } - ty::ty_fn({proto: ast::proto_uniq, _}) { fn_env(ty::ck_uniq) } - ty::ty_fn({proto: ast::proto_box, _}) { fn_env(ty::ck_box) } - _ { fail ~"make_fn_glue invoked on non-function type" } + ty::ty_fn({proto: ast::proto_block, _}) => bcx, + ty::ty_fn({proto: ast::proto_uniq, _}) => fn_env(ty::ck_uniq), + ty::ty_fn({proto: ast::proto_box, _}) => fn_env(ty::ck_box), + _ => fail ~"make_fn_glue invoked on non-function type" }; } @@ -438,12 +434,12 @@ fn make_opaque_cbox_take_glue( // Easy cases: let _icx = bcx.insn_ctxt(~"closure::make_opaque_cbox_take_glue"); alt ck { - ty::ck_block { return bcx; } - ty::ck_box { + ty::ck_block => return bcx, + ty::ck_box => { incr_refcnt_of_boxed(bcx, Load(bcx, cboxptr)); return bcx; } - ty::ck_uniq { /* hard case: */ } + ty::ck_uniq => { /* hard case: */ } } // Hard case, a deep copy: @@ -490,12 +486,12 @@ fn make_opaque_cbox_drop_glue( -> block { let _icx = bcx.insn_ctxt(~"closure::make_opaque_cbox_drop_glue"); alt ck { - ty::ck_block { bcx } - ty::ck_box { + ty::ck_block => bcx, + ty::ck_box => { decr_refcnt_maybe_free(bcx, Load(bcx, cboxptr), ty::mk_opaque_closure_ptr(bcx.tcx(), ck)) } - ty::ck_uniq { + ty::ck_uniq => { free_ty(bcx, Load(bcx, cboxptr), ty::mk_opaque_closure_ptr(bcx.tcx(), ck)) } @@ -509,8 +505,8 @@ fn make_opaque_cbox_free_glue( -> block { let _icx = bcx.insn_ctxt(~"closure::make_opaque_cbox_free_glue"); alt ck { - ty::ck_block { return bcx; } - ty::ck_box | ty::ck_uniq { /* hard cases: */ } + ty::ck_block => return bcx, + ty::ck_box | ty::ck_uniq => { /* hard cases: */ } } let ccx = bcx.ccx(); @@ -529,13 +525,9 @@ fn make_opaque_cbox_free_glue( // Free the ty descr (if necc) and the box itself alt ck { - ty::ck_block { fail ~"Impossible"; } - ty::ck_box { - trans_free(bcx, cbox) - } - ty::ck_uniq { - trans_unique_free(bcx, cbox) - } + ty::ck_block => fail ~"Impossible", + ty::ck_box => trans_free(bcx, cbox), + ty::ck_uniq => trans_unique_free(bcx, cbox) } } } diff --git a/src/rustc/middle/trans/common.rs b/src/rustc/middle/trans/common.rs index df585bb757b..99fd0c8b7bc 100644 --- a/src/rustc/middle/trans/common.rs +++ b/src/rustc/middle/trans/common.rs @@ -293,8 +293,8 @@ fn add_clean_temp_mem(cx: block, val: ValueRef, ty: ty::t) { } fn add_clean_free(cx: block, ptr: ValueRef, heap: heap) { let free_fn = alt heap { - heap_shared { |a| base::trans_free(a, ptr) } - heap_exchange { |a| base::trans_unique_free(a, ptr) } + heap_shared => |a| base::trans_free(a, ptr), + heap_exchange => |a| base::trans_unique_free(a, ptr) }; do in_scope_cx(cx) |info| { vec::push(info.cleanups, clean_temp(ptr, free_fn, @@ -310,7 +310,10 @@ fn add_clean_free(cx: block, ptr: ValueRef, heap: heap) { fn revoke_clean(cx: block, val: ValueRef) { do in_scope_cx(cx) |info| { do option::iter(vec::position(info.cleanups, |cu| { - alt cu { clean_temp(v, _, _) if v == val { true } _ { false } } + alt cu { + clean_temp(v, _, _) if v == val => true, + _ => false + } })) |i| { info.cleanups = vec::append(vec::slice(info.cleanups, 0u, i), @@ -451,8 +454,8 @@ fn in_scope_cx(cx: block, f: fn(scope_info)) { let mut cur = cx; loop { alt cur.kind { - block_scope(inf) { f(inf); return; } - _ {} + block_scope(inf) => { f(inf); return; } + _ => () } cur = block_parent(cur); } @@ -460,9 +463,9 @@ fn in_scope_cx(cx: block, f: fn(scope_info)) { fn block_parent(cx: block) -> block { alt cx.parent { - some(b) { b } - none { cx.sess().bug(fmt!{"block_parent called on root block %?", - cx}); } + some(b) => b, + none => cx.sess().bug(fmt!{"block_parent called on root block %?", + cx}) } } @@ -481,10 +484,10 @@ impl bcx_cxs for block { } fn to_str() -> ~str { alt self.node_info { - some(node_info) { + some(node_info) => { fmt!{"[block %d]", node_info.id} } - none { + none => { fmt!{"[block %x]", ptr::addr_of(*self) as uint} } } @@ -533,46 +536,46 @@ fn T_bool() -> TypeRef { return T_i1(); } fn T_int(targ_cfg: @session::config) -> TypeRef { return alt targ_cfg.arch { - session::arch_x86 { T_i32() } - session::arch_x86_64 { T_i64() } - session::arch_arm { T_i32() } + session::arch_x86 => T_i32(), + session::arch_x86_64 => T_i64(), + session::arch_arm => T_i32() }; } fn T_int_ty(cx: @crate_ctxt, t: ast::int_ty) -> TypeRef { alt t { - ast::ty_i { cx.int_type } - ast::ty_char { T_char() } - ast::ty_i8 { T_i8() } - ast::ty_i16 { T_i16() } - ast::ty_i32 { T_i32() } - ast::ty_i64 { T_i64() } + ast::ty_i => cx.int_type, + ast::ty_char => T_char(), + ast::ty_i8 => T_i8(), + ast::ty_i16 => T_i16(), + ast::ty_i32 => T_i32(), + ast::ty_i64 => T_i64() } } fn T_uint_ty(cx: @crate_ctxt, t: ast::uint_ty) -> TypeRef { alt t { - ast::ty_u { cx.int_type } - ast::ty_u8 { T_i8() } - ast::ty_u16 { T_i16() } - ast::ty_u32 { T_i32() } - ast::ty_u64 { T_i64() } + ast::ty_u => cx.int_type, + ast::ty_u8 => T_i8(), + ast::ty_u16 => T_i16(), + ast::ty_u32 => T_i32(), + ast::ty_u64 => T_i64() } } fn T_float_ty(cx: @crate_ctxt, t: ast::float_ty) -> TypeRef { alt t { - ast::ty_f { cx.float_type } - ast::ty_f32 { T_f32() } - ast::ty_f64 { T_f64() } + ast::ty_f => cx.float_type, + ast::ty_f32 => T_f32(), + ast::ty_f64 => T_f64() } } fn T_float(targ_cfg: @session::config) -> TypeRef { return alt targ_cfg.arch { - session::arch_x86 { T_f64() } - session::arch_x86_64 { T_f64() } - session::arch_arm { T_f64() } + session::arch_x86 => T_f64(), + session::arch_x86_64 => T_f64(), + session::arch_arm => T_f64() }; } @@ -654,7 +657,10 @@ fn T_tydesc_field(cx: @crate_ctxt, field: uint) -> TypeRef unsafe { fn T_glue_fn(cx: @crate_ctxt) -> TypeRef { let s = ~"glue_fn"; - alt name_has_type(cx.tn, s) { some(t) { return t; } _ {} } + alt name_has_type(cx.tn, s) { + some(t) => return t, + _ => () + } let t = T_tydesc_field(cx, abi::tydesc_field_drop_glue); associate_type(cx.tn, s, t); return t; @@ -758,7 +764,10 @@ fn T_taskptr(cx: @crate_ctxt) -> TypeRef { return T_ptr(cx.task_type); } // This type must never be used directly; it must always be cast away. fn T_typaram(tn: type_names) -> TypeRef { let s = ~"typaram"; - alt name_has_type(tn, s) { some(t) { return t; } _ {} } + alt name_has_type(tn, s) { + some(t) => return t, + _ => () + } let t = T_i8(); associate_type(tn, s, t); return t; @@ -778,7 +787,10 @@ fn T_enum_discrim(cx: @crate_ctxt) -> TypeRef { fn T_opaque_enum(cx: @crate_ctxt) -> TypeRef { let s = ~"opaque_enum"; - alt name_has_type(cx.tn, s) { some(t) { return t; } _ {} } + alt name_has_type(cx.tn, s) { + some(t) => return t, + _ => () + } let t = T_struct(~[T_enum_discrim(cx), T_i8()]); associate_type(cx.tn, s, t); return t; @@ -845,8 +857,8 @@ fn C_u8(i: uint) -> ValueRef { return C_integral(T_i8(), i as u64, False); } // our boxed-and-length-annotated strings. fn C_cstr(cx: @crate_ctxt, s: ~str) -> ValueRef { alt cx.const_cstr_cache.find(s) { - some(llval) { return llval; } - none { } + some(llval) => return llval, + none => () } let sc = do str::as_c_str(s) |buf| { @@ -931,7 +943,7 @@ pure fn hash_mono_id(mi: &mono_id) -> uint { let mut h = syntax::ast_util::hash_def(&mi.def); for vec::each(mi.params) |param| { h = h * alt param { - mono_precise(ty, vts) { + mono_precise(ty, vts) => { let mut h = ty::type_id(ty); do option::iter(vts) |vts| { for vec::each(vts) |vt| { @@ -940,8 +952,8 @@ pure fn hash_mono_id(mi: &mono_id) -> uint { } h } - mono_any { 1u } - mono_repr(sz, align) { sz * (align + 2u) } + mono_any => 1u, + mono_repr(sz, align) => sz * (align + 2u) } } h @@ -966,7 +978,7 @@ fn align_to(cx: block, off: ValueRef, align: ValueRef) -> ValueRef { fn path_str(p: path) -> ~str { let mut r = ~"", first = true; for vec::each(p) |e| { - alt e { ast_map::path_name(s) | ast_map::path_mod(s) { + alt e { ast_map::path_name(s) | ast_map::path_mod(s) => { if first { first = false; } else { r += ~"::"; } r += *s; @@ -979,8 +991,8 @@ fn node_id_type(bcx: block, id: ast::node_id) -> ty::t { let tcx = bcx.tcx(); let t = ty::node_id_to_type(tcx, id); alt bcx.fcx.param_substs { - some(substs) { ty::subst_tps(tcx, substs.tys, t) } - _ { assert !ty::type_has_params(t); t } + some(substs) => ty::subst_tps(tcx, substs.tys, t), + _ => { assert !ty::type_has_params(t); t } } } fn expr_ty(bcx: block, ex: @ast::expr) -> ty::t { @@ -990,10 +1002,10 @@ fn node_id_type_params(bcx: block, id: ast::node_id) -> ~[ty::t] { let tcx = bcx.tcx(); let params = ty::node_id_to_type_params(tcx, id); alt bcx.fcx.param_substs { - some(substs) { + some(substs) => { vec::map(params, |t| ty::subst_tps(tcx, substs.tys, t)) } - _ { params } + _ => params } } @@ -1001,9 +1013,10 @@ fn field_idx_strict(cx: ty::ctxt, sp: span, ident: ast::ident, fields: ~[ty::field]) -> uint { alt ty::field_idx(ident, fields) { - none { cx.sess.span_bug(sp, fmt!{"base expr doesn't appear to \ - have a field named %s", *ident}); } - some(i) { i } + none => cx.sess.span_bug( + sp, fmt!{"base expr doesn't appear to \ + have a field named %s", *ident}), + some(i) => i } } diff --git a/src/rustc/middle/trans/consts.rs b/src/rustc/middle/trans/consts.rs index 03c0b303c09..d0a448da5b2 100644 --- a/src/rustc/middle/trans/consts.rs +++ b/src/rustc/middle/trans/consts.rs @@ -6,26 +6,25 @@ fn const_lit(cx: @crate_ctxt, e: @ast::expr, lit: ast::lit) -> ValueRef { let _icx = cx.insn_ctxt(~"trans_lit"); alt lit.node { - ast::lit_int(i, t) { C_integral(T_int_ty(cx, t), i as u64, True) } - ast::lit_uint(u, t) { C_integral(T_uint_ty(cx, t), u, False) } - ast::lit_int_unsuffixed(i) { + ast::lit_int(i, t) => C_integral(T_int_ty(cx, t), i as u64, True), + ast::lit_uint(u, t) => C_integral(T_uint_ty(cx, t), u, False), + ast::lit_int_unsuffixed(i) => { let lit_int_ty = ty::node_id_to_type(cx.tcx, e.id); alt ty::get(lit_int_ty).struct { - ty::ty_int(t) { + ty::ty_int(t) => { C_integral(T_int_ty(cx, t), i as u64, True) } - ty::ty_uint(t) { + ty::ty_uint(t) => { C_integral(T_uint_ty(cx, t), i as u64, False) } - _ { cx.sess.span_bug(lit.span, - ~"integer literal doesn't have a type"); - } + _ => cx.sess.span_bug(lit.span, + ~"integer literal doesn't have a type") } } - ast::lit_float(fs, t) { C_floating(*fs, T_float_ty(cx, t)) } - ast::lit_bool(b) { C_bool(b) } - ast::lit_nil { C_nil() } - ast::lit_str(s) { C_estr_slice(cx, *s) } + ast::lit_float(fs, t) => C_floating(*fs, T_float_ty(cx, t)), + ast::lit_bool(b) => C_bool(b), + ast::lit_nil => C_nil(), + ast::lit_str(s) => C_estr_slice(cx, *s) } } @@ -47,8 +46,8 @@ fn const_vec_and_sz(cx: @crate_ctxt, e: @ast::expr, es: &[@ast::expr]) fn const_expr(cx: @crate_ctxt, e: @ast::expr) -> ValueRef { let _icx = cx.insn_ctxt(~"const_expr"); alt e.node { - ast::expr_lit(lit) { consts::const_lit(cx, e, *lit) } - ast::expr_binary(b, e1, e2) { + ast::expr_lit(lit) => consts::const_lit(cx, e, *lit), + ast::expr_binary(b, e1, e2) => { let te1 = const_expr(cx, e1); let te2 = const_expr(cx, e2); @@ -60,35 +59,35 @@ fn const_expr(cx: @crate_ctxt, e: @ast::expr) -> ValueRef { let is_float = ty::type_is_fp(ty); let signed = ty::type_is_signed(ty); return alt b { - ast::add { + ast::add => { if is_float { llvm::LLVMConstFAdd(te1, te2) } else { llvm::LLVMConstAdd(te1, te2) } } - ast::subtract { + ast::subtract => { if is_float { llvm::LLVMConstFSub(te1, te2) } else { llvm::LLVMConstSub(te1, te2) } } - ast::mul { + ast::mul => { if is_float { llvm::LLVMConstFMul(te1, te2) } else { llvm::LLVMConstMul(te1, te2) } } - ast::div { + ast::div => { if is_float { llvm::LLVMConstFDiv(te1, te2) } else if signed { llvm::LLVMConstSDiv(te1, te2) } else { llvm::LLVMConstUDiv(te1, te2) } } - ast::rem { + ast::rem => { if is_float { llvm::LLVMConstFRem(te1, te2) } else if signed { llvm::LLVMConstSRem(te1, te2) } else { llvm::LLVMConstURem(te1, te2) } } ast::and | - ast::or { cx.sess.span_unimpl(e.span, ~"binop logic"); } - ast::bitxor { llvm::LLVMConstXor(te1, te2) } - ast::bitand { llvm::LLVMConstAnd(te1, te2) } - ast::bitor { llvm::LLVMConstOr(te1, te2) } - ast::shl { llvm::LLVMConstShl(te1, te2) } - ast::shr { + ast::or => cx.sess.span_unimpl(e.span, ~"binop logic"), + ast::bitxor => llvm::LLVMConstXor(te1, te2), + ast::bitand => llvm::LLVMConstAnd(te1, te2), + ast::bitor => llvm::LLVMConstOr(te1, te2), + ast::shl => llvm::LLVMConstShl(te1, te2), + ast::shr => { if signed { llvm::LLVMConstAShr(te1, te2) } else { llvm::LLVMConstLShr(te1, te2) } } @@ -97,48 +96,48 @@ fn const_expr(cx: @crate_ctxt, e: @ast::expr) -> ValueRef { ast::le | ast::ne | ast::ge | - ast::gt { cx.sess.span_unimpl(e.span, ~"binop comparator"); } + ast::gt => cx.sess.span_unimpl(e.span, ~"binop comparator") } } - ast::expr_unary(u, e) { + ast::expr_unary(u, e) => { let te = const_expr(cx, e); let ty = ty::expr_ty(cx.tcx, e); let is_float = ty::type_is_fp(ty); return alt u { ast::box(_) | ast::uniq(_) | - ast::deref { cx.sess.span_bug(e.span, - ~"bad unop type in const_expr"); } - ast::not { llvm::LLVMConstNot(te) } - ast::neg { + ast::deref => cx.sess.span_bug(e.span, + ~"bad unop type in const_expr"), + ast::not => llvm::LLVMConstNot(te), + ast::neg => { if is_float { llvm::LLVMConstFNeg(te) } else { llvm::LLVMConstNeg(te) } } } } - ast::expr_cast(base, tp) { + ast::expr_cast(base, tp) => { let ety = ty::expr_ty(cx.tcx, e), llty = type_of::type_of(cx, ety); let basety = ty::expr_ty(cx.tcx, base); let v = const_expr(cx, base); alt check (base::cast_type_kind(basety), base::cast_type_kind(ety)) { - (base::cast_integral, base::cast_integral) { + (base::cast_integral, base::cast_integral) => { let s = if ty::type_is_signed(basety) { True } else { False }; llvm::LLVMConstIntCast(v, llty, s) } - (base::cast_integral, base::cast_float) { + (base::cast_integral, base::cast_float) => { if ty::type_is_signed(basety) { llvm::LLVMConstSIToFP(v, llty) } else { llvm::LLVMConstUIToFP(v, llty) } } - (base::cast_float, base::cast_float) { + (base::cast_float, base::cast_float) => { llvm::LLVMConstFPCast(v, llty) } - (base::cast_float, base::cast_integral) { + (base::cast_float, base::cast_integral) => { if ty::type_is_signed(ety) { llvm::LLVMConstFPToSI(v, llty) } else { llvm::LLVMConstFPToUI(v, llty) } } } } - ast::expr_addr_of(ast::m_imm, sub) { + ast::expr_addr_of(ast::m_imm, sub) => { let cv = const_expr(cx, sub); let subty = ty::expr_ty(cx.tcx, sub), llty = type_of::type_of(cx, subty); @@ -149,22 +148,22 @@ fn const_expr(cx: @crate_ctxt, e: @ast::expr) -> ValueRef { llvm::LLVMSetGlobalConstant(gv, True); gv } - ast::expr_tup(es) { + ast::expr_tup(es) => { C_struct(es.map(|e| const_expr(cx, e))) } - ast::expr_rec(fs, none) { + ast::expr_rec(fs, none) => { C_struct(fs.map(|f| const_expr(cx, f.node.expr))) } - ast::expr_vec(es, m_imm) { + ast::expr_vec(es, m_imm) => { let (v, _) = const_vec_and_sz(cx, e, es); v } - ast::expr_vstore(e, ast::vstore_fixed(_)) { + ast::expr_vstore(e, ast::vstore_fixed(_)) => { const_expr(cx, e) } - ast::expr_vstore(sub, ast::vstore_slice(_)) { + ast::expr_vstore(sub, ast::vstore_slice(_)) => { alt sub.node { - ast::expr_lit(lit) { + ast::expr_lit(lit) => { alt lit.node { ast::lit_str(*) => { const_expr(cx, sub) } _ => { cx.sess.span_bug(e.span, @@ -186,30 +185,28 @@ fn const_expr(cx: @crate_ctxt, e: @ast::expr) -> ValueRef { ~"bad const-slice expr") } } - ast::expr_path(path) { + ast::expr_path(path) => { alt cx.tcx.def_map.find(e.id) { - some(ast::def_const(def_id)) { + some(ast::def_const(def_id)) => { // Don't know how to handle external consts assert ast_util::is_local(def_id); alt cx.tcx.items.get(def_id.node) { ast_map::node_item(@{ node: ast::item_const(_, subexpr), _ - }, _) { + }, _) => { // FIXME (#2530): Instead of recursing here to regenerate // the values for other constants, we should just look up // the already-defined value. const_expr(cx, subexpr) } - _ { - cx.sess.span_bug(e.span, ~"expected item"); - } + _ => cx.sess.span_bug(e.span, ~"expected item") } } - _ { cx.sess.span_bug(e.span, ~"expected to find a const def") } + _ => cx.sess.span_bug(e.span, ~"expected to find a const def") } } - _ { cx.sess.span_bug(e.span, - ~"bad constant expression type in consts::const_expr"); } + _ => cx.sess.span_bug(e.span, + ~"bad constant expression type in consts::const_expr") } } diff --git a/src/rustc/middle/trans/debuginfo.rs b/src/rustc/middle/trans/debuginfo.rs index 1f1da98b528..30300550c31 100644 --- a/src/rustc/middle/trans/debuginfo.rs +++ b/src/rustc/middle/trans/debuginfo.rs @@ -135,14 +135,14 @@ fn cast_safely<T: copy, U>(val: T) -> U unsafe { fn md_from_metadata<T>(val: debug_metadata) -> T unsafe { alt val { - file_metadata(md) { cast_safely(md) } - compile_unit_metadata(md) { cast_safely(md) } - subprogram_metadata(md) { cast_safely(md) } - local_var_metadata(md) { cast_safely(md) } - tydesc_metadata(md) { cast_safely(md) } - block_metadata(md) { cast_safely(md) } - argument_metadata(md) { cast_safely(md) } - retval_metadata(md) { cast_safely(md) } + file_metadata(md) => cast_safely(md), + compile_unit_metadata(md) => cast_safely(md), + subprogram_metadata(md) => cast_safely(md), + local_var_metadata(md) => cast_safely(md), + tydesc_metadata(md) => cast_safely(md), + block_metadata(md) => cast_safely(md), + argument_metadata(md) => cast_safely(md), + retval_metadata(md) => cast_safely(md) } } @@ -167,8 +167,8 @@ fn create_compile_unit(cx: @crate_ctxt) let tg = CompileUnitTag; alt cached_metadata::<@metadata<compile_unit_md>>(cache, tg, |md| md.data.name == crate_name) { - option::some(md) { return md; } - option::none {} + option::some(md) => return md, + option::none => () } let (_, work_dir) = get_file_path_and_dir(cx.sess.working_dir, @@ -210,8 +210,8 @@ fn create_file(cx: @crate_ctxt, full_path: ~str) -> @metadata<file_md> { let tg = FileDescriptorTag; alt cached_metadata::<@metadata<file_md>>( cache, tg, |md| md.data.path == full_path) { - option::some(md) { return md; } - option::none {} + option::some(md) => return md, + option::none => () } let (file_path, work_dir) = get_file_path_and_dir(cx.sess.working_dir, @@ -236,8 +236,8 @@ fn create_block(cx: block) -> @metadata<block_md> { let mut cx = cx; while option::is_none(cx.node_info) { alt cx.parent { - some(b) { cx = b; } - none { fail; } + some(b) => cx = b, + none => fail } } let sp = option::get(cx.node_info).span; @@ -254,13 +254,13 @@ fn create_block(cx: block) -> @metadata<block_md> { }*/ let parent = alt cx.parent { - none { create_function(cx.fcx).node } - some(bcx) { create_block(bcx).node } + none => create_function(cx.fcx).node, + some(bcx) => create_block(bcx).node }; let file_node = create_file(cx.ccx(), fname); let unique_id = alt cache.find(LexicalBlockTag) { - option::some(v) { vec::len(v) as int } - option::none { 0 } + option::some(v) => vec::len(v) as int, + option::none => 0 }; let lldata = ~[lltag(tg), parent, @@ -287,32 +287,32 @@ fn create_basic_type(cx: @crate_ctxt, t: ty::t, ty: ast::prim_ty, span: span) let tg = BasicTypeDescriptorTag; alt cached_metadata::<@metadata<tydesc_md>>( cache, tg, |md| ty::type_id(t) == md.data.hash) { - option::some(md) { return md; } - option::none {} + option::some(md) => return md, + option::none => () } let (name, encoding) = alt check ty { - ast::ty_bool {(~"bool", DW_ATE_boolean)} - ast::ty_int(m) { alt m { - ast::ty_char {(~"char", DW_ATE_unsigned)} - ast::ty_i {(~"int", DW_ATE_signed)} - ast::ty_i8 {(~"i8", DW_ATE_signed_char)} - ast::ty_i16 {(~"i16", DW_ATE_signed)} - ast::ty_i32 {(~"i32", DW_ATE_signed)} - ast::ty_i64 {(~"i64", DW_ATE_signed)} - }} - ast::ty_uint(m) { alt m { - ast::ty_u {(~"uint", DW_ATE_unsigned)} - ast::ty_u8 {(~"u8", DW_ATE_unsigned_char)} - ast::ty_u16 {(~"u16", DW_ATE_unsigned)} - ast::ty_u32 {(~"u32", DW_ATE_unsigned)} - ast::ty_u64 {(~"u64", DW_ATE_unsigned)} - }} - ast::ty_float(m) { alt m { - ast::ty_f {(~"float", DW_ATE_float)} - ast::ty_f32 {(~"f32", DW_ATE_float)} - ast::ty_f64 {(~"f64", DW_ATE_float)} - }} + ast::ty_bool => (~"bool", DW_ATE_boolean), + ast::ty_int(m) => alt m { + ast::ty_char => (~"char", DW_ATE_unsigned), + ast::ty_i => (~"int", DW_ATE_signed), + ast::ty_i8 => (~"i8", DW_ATE_signed_char), + ast::ty_i16 => (~"i16", DW_ATE_signed), + ast::ty_i32 => (~"i32", DW_ATE_signed), + ast::ty_i64 => (~"i64", DW_ATE_signed) + } + ast::ty_uint(m) => alt m { + ast::ty_u => (~"uint", DW_ATE_unsigned), + ast::ty_u8 => (~"u8", DW_ATE_unsigned_char), + ast::ty_u16 => (~"u16", DW_ATE_unsigned), + ast::ty_u32 => (~"u32", DW_ATE_unsigned), + ast::ty_u64 => (~"u64", DW_ATE_unsigned) + } + ast::ty_float(m) => alt m { + ast::ty_f => (~"float", DW_ATE_float), + ast::ty_f32 => (~"f32", DW_ATE_float), + ast::ty_f64 => (~"f64", DW_ATE_float) + } }; let fname = filename_from_span(cx, span); @@ -641,14 +641,14 @@ fn create_local_var(bcx: block, local: @ast::local) let tg = AutoVariableTag; alt cached_metadata::<@metadata<local_var_md>>( cache, tg, |md| md.data.id == local.node.id) { - option::some(md) { return md; } - option::none {} + option::some(md) => return md, + option::none => () } let name = alt local.node.pat.node { - ast::pat_ident(_, pth, _) { ast_util::path_to_ident(pth) } + ast::pat_ident(_, pth, _) => ast_util::path_to_ident(pth), // FIXME this should be handled (#2533) - _ { fail ~"no single variable name for local"; } + _ => fail ~"no single variable name for local" }; let loc = codemap::lookup_char_pos(cx.sess.codemap, local.span.lo); @@ -656,8 +656,8 @@ fn create_local_var(bcx: block, local: @ast::local) let tymd = create_ty(cx, ty, local.node.ty); let filemd = create_file(cx, loc.file.name); let context = alt bcx.parent { - none { create_function(bcx.fcx).node } - some(_) { create_block(bcx).node } + none => create_function(bcx.fcx).node, + some(_) => create_block(bcx).node }; let mdnode = create_var(tg, context, *name, filemd.node, loc.line as int, tymd.node); @@ -665,16 +665,16 @@ fn create_local_var(bcx: block, local: @ast::local) update_cache(cache, AutoVariableTag, local_var_metadata(mdval)); let llptr = alt bcx.fcx.lllocals.find(local.node.id) { - option::some(local_mem(v)) { v } - option::some(_) { + option::some(local_mem(v)) => v, + option::some(_) => { bcx.tcx().sess.span_bug(local.span, ~"local is bound to \ something weird"); } - option::none { + option::none => { alt bcx.fcx.lllocals.get(local.node.pat.id) { - local_imm(v) { v } - _ { bcx.tcx().sess.span_bug(local.span, ~"local is bound to \ - something weird"); } + local_imm(v) => v, + _ => bcx.tcx().sess.span_bug(local.span, ~"local is bound to \ + something weird") } } }; @@ -691,8 +691,8 @@ fn create_arg(bcx: block, arg: ast::arg, sp: span) let tg = ArgVariableTag; alt cached_metadata::<@metadata<argument_md>>( cache, ArgVariableTag, |md| md.data.id == arg.id) { - option::some(md) { return md; } - option::none {} + option::some(md) => return md, + option::none => () } let loc = codemap::lookup_char_pos(cx.sess.codemap, @@ -707,7 +707,7 @@ fn create_arg(bcx: block, arg: ast::arg, sp: span) update_cache(cache, tg, argument_metadata(mdval)); let llptr = alt fcx.llargs.get(arg.id) { - local_mem(v) | local_imm(v) { v } + local_mem(v) | local_imm(v) => v, }; let declargs = ~[llmdnode(~[llptr]), mdnode]; trans::build::Call(bcx, cx.intrinsics.get(~"llvm.dbg.declare"), @@ -741,36 +741,37 @@ fn create_function(fcx: fn_ctxt) -> @metadata<subprogram_md> { log(debug, codemap::span_to_str(sp, cx.sess.codemap)); let (ident, ret_ty, id) = alt cx.tcx.items.get(fcx.id) { - ast_map::node_item(item, _) { + ast_map::node_item(item, _) => { alt item.node { - ast::item_fn(decl, _, _) { + ast::item_fn(decl, _, _) => { (item.ident, decl.output, item.id) } - _ { fcx.ccx.sess.span_bug(item.span, ~"create_function: item \ - bound to non-function"); } + _ => fcx.ccx.sess.span_bug(item.span, ~"create_function: item \ + bound to non-function") } } - ast_map::node_method(method, _, _) { + ast_map::node_method(method, _, _) => { (method.ident, method.decl.output, method.id) } - ast_map::node_ctor(nm, _, ctor, _, _) { + ast_map::node_ctor(nm, _, ctor, _, _) => { // FIXME: output type may be wrong (#2194) (nm, ctor.node.dec.output, ctor.node.id) } - ast_map::node_expr(expr) { + ast_map::node_expr(expr) => { alt expr.node { - ast::expr_fn(_, decl, _, _) { + ast::expr_fn(_, decl, _, _) => { (@dbg_cx.names(~"fn"), decl.output, expr.id) } - ast::expr_fn_block(decl, _, _) { + ast::expr_fn_block(decl, _, _) => { (@dbg_cx.names(~"fn"), decl.output, expr.id) } - _ { fcx.ccx.sess.span_bug(expr.span, ~"create_function: \ - expected an expr_fn or fn_block here"); } + _ => fcx.ccx.sess.span_bug(expr.span, + ~"create_function: \ + expected an expr_fn or fn_block here") } } - _ { fcx.ccx.sess.bug(~"create_function: unexpected \ - sort of node"); } + _ => fcx.ccx.sess.bug(~"create_function: unexpected \ + sort of node") }; log(debug, ident); @@ -779,8 +780,8 @@ fn create_function(fcx: fn_ctxt) -> @metadata<subprogram_md> { let cache = get_cache(cx); alt cached_metadata::<@metadata<subprogram_md>>( cache, SubprogramTag, |md| md.data.id == id) { - option::some(md) { return md; } - option::none {} + option::some(md) => return md, + option::none => () } let loc = codemap::lookup_char_pos(cx.sess.codemap, @@ -788,8 +789,8 @@ fn create_function(fcx: fn_ctxt) -> @metadata<subprogram_md> { let file_node = create_file(cx, loc.file.name).node; let ty_node = if cx.sess.opts.extra_debuginfo { alt ret_ty.node { - ast::ty_nil { llnull() } - _ { create_ty(cx, ty::node_id_to_type(cx.tcx, id), ret_ty).node } + ast::ty_nil => llnull(), + _ => create_ty(cx, ty::node_id_to_type(cx.tcx, id), ret_ty).node } } else { llnull() diff --git a/src/rustc/middle/trans/foreign.rs b/src/rustc/middle/trans/foreign.rs index ceca9aa2ef4..56f8892ff37 100644 --- a/src/rustc/middle/trans/foreign.rs +++ b/src/rustc/middle/trans/foreign.rs @@ -40,8 +40,8 @@ enum x86_64_reg_class { fn is_sse(++c: x86_64_reg_class) -> bool { return alt c { sse_fs_class | sse_fv_class | - sse_ds_class | sse_dv_class { true } - _ { false } + sse_ds_class | sse_dv_class => true, + _ => false }; } @@ -74,49 +74,45 @@ fn classify_ty(ty: TypeRef) -> ~[x86_64_reg_class] { fn ty_align(ty: TypeRef) -> uint { return alt llvm::LLVMGetTypeKind(ty) as int { - 8 /* integer */ { + 8 /* integer */ => { ((llvm::LLVMGetIntTypeWidth(ty) as uint) + 7u) / 8u } - 12 /* pointer */ { 8u } - 2 /* float */ { 4u } - 3 /* double */ { 8u } - 10 /* struct */ { + 12 /* pointer */ => 8u, + 2 /* float */ => 4u, + 3 /* double */ => 8u, + 10 /* struct */ => { do vec::foldl(0u, struct_tys(ty)) |a, t| { uint::max(a, ty_align(t)) } } - 11 /* array */ { + 11 /* array */ => { let elt = llvm::LLVMGetElementType(ty); ty_align(elt) } - _ { - fail ~"ty_size: unhandled type" - } + _ => fail ~"ty_size: unhandled type" }; } fn ty_size(ty: TypeRef) -> uint { return alt llvm::LLVMGetTypeKind(ty) as int { - 8 /* integer */ { + 8 /* integer */ => { ((llvm::LLVMGetIntTypeWidth(ty) as uint) + 7u) / 8u } - 12 /* pointer */ { 8u } - 2 /* float */ { 4u } - 3 /* double */ { 8u } - 10 /* struct */ { + 12 /* pointer */ => 8u, + 2 /* float */ => 4u, + 3 /* double */ => 8u, + 10 /* struct */ => { do vec::foldl(0u, struct_tys(ty)) |s, t| { s + ty_size(t) } } - 11 /* array */ { + 11 /* array */ => { let len = llvm::LLVMGetArrayLength(ty) as uint; let elt = llvm::LLVMGetElementType(ty); let eltsz = ty_size(elt); len * eltsz } - _ { - fail ~"ty_size: unhandled type" - } + _ => fail ~"ty_size: unhandled type" }; } @@ -185,23 +181,23 @@ fn classify_ty(ty: TypeRef) -> ~[x86_64_reg_class] { alt llvm::LLVMGetTypeKind(ty) as int { 8 /* integer */ | - 12 /* pointer */ { + 12 /* pointer */ => { unify(cls, ix + off / 8u, integer_class); } - 2 /* float */ { + 2 /* float */ => { if off % 8u == 4u { unify(cls, ix + off / 8u, sse_fv_class); } else { unify(cls, ix + off / 8u, sse_fs_class); } } - 3 /* double */ { + 3 /* double */ => { unify(cls, ix + off / 8u, sse_ds_class); } - 10 /* struct */ { + 10 /* struct */ => { classify_struct(struct_tys(ty), cls, ix, off); } - 11 /* array */ { + 11 /* array */ => { let elt = llvm::LLVMGetElementType(ty); let eltsz = ty_size(elt); let len = llvm::LLVMGetArrayLength(ty) as uint; @@ -211,9 +207,7 @@ fn classify_ty(ty: TypeRef) -> ~[x86_64_reg_class] { i += 1u; } } - _ { - fail ~"classify: unhandled type"; - } + _ => fail ~"classify: unhandled type" } } @@ -292,10 +286,10 @@ fn llreg_ty(cls: ~[x86_64_reg_class]) -> TypeRef { let e = vec::len(cls); while i < e { alt cls[i] { - integer_class { + integer_class => { vec::push(tys, T_i64()); } - sse_fv_class { + sse_fv_class => { let vec_len = llvec_len(vec::tailn(cls, i + 1u)) * 2u; let vec_ty = llvm::LLVMVectorType(T_f32(), vec_len as c_uint); @@ -303,15 +297,13 @@ fn llreg_ty(cls: ~[x86_64_reg_class]) -> TypeRef { i += vec_len; again; } - sse_fs_class { + sse_fs_class => { vec::push(tys, T_f32()); } - sse_ds_class { + sse_ds_class => { vec::push(tys, T_f64()); } - _ { - fail ~"llregtype: unhandled class"; - } + _ => fail ~"llregtype: unhandled class" } i += 1u; } @@ -338,8 +330,8 @@ fn x86_64_tys(atys: ~[TypeRef], 8 /* integer */ | 12 /* pointer */ | 2 /* float */ | - 3 /* double */ { true } - _ { false } + 3 /* double */ => true, + _ => false }; } @@ -410,11 +402,11 @@ fn decl_x86_64_fn(tys: x86_64_tys, do vec::iteri(tys.attrs) |i, a| { alt a { - option::some(attr) { + option::some(attr) => { let llarg = get_param(llfn, i); llvm::LLVMAddAttribute(llarg, attr as c_uint); } - _ {} + _ => () } } return llfn; @@ -422,8 +414,8 @@ fn decl_x86_64_fn(tys: x86_64_tys, fn link_name(i: @ast::foreign_item) -> ~str { alt attr::first_attr_value_str_by_name(i.attrs, ~"link_name") { - none { return *i.ident; } - option::some(ln) { return *ln; } + none => return *i.ident, + option::some(ln) => return *ln } } @@ -439,12 +431,12 @@ type c_stack_tys = { fn c_arg_and_ret_lltys(ccx: @crate_ctxt, id: ast::node_id) -> (~[TypeRef], TypeRef, ty::t) { alt ty::get(ty::node_id_to_type(ccx.tcx, id)).struct { - ty::ty_fn({inputs: arg_tys, output: ret_ty, _}) { + ty::ty_fn({inputs: arg_tys, output: ret_ty, _}) => { let llargtys = type_of_explicit_args(ccx, arg_tys); let llretty = type_of::type_of(ccx, ret_ty); (llargtys, llretty, ret_ty) } - _ { ccx.sess.bug(~"c_arg_and_ret_lltys called on non-function type"); } + _ => ccx.sess.bug(~"c_arg_and_ret_lltys called on non-function type") } } @@ -596,7 +588,7 @@ fn trans_foreign_mod(ccx: @crate_ctxt, let n = vec::len(tys.arg_tys); alt tys.x86_64_tys { - some(x86_64) { + some(x86_64) => { let mut atys = x86_64.arg_tys; let mut attrs = x86_64.attrs; if x86_64.sret { @@ -622,7 +614,7 @@ fn trans_foreign_mod(ccx: @crate_ctxt, i += 1u; } } - _ { + _ => { while i < n { let llargval = load_inbounds(bcx, llargbundle, ~[0u, i]); @@ -638,15 +630,15 @@ fn trans_foreign_mod(ccx: @crate_ctxt, llargbundle: ValueRef, llretval: ValueRef) { let _icx = bcx.insn_ctxt(~"foreign::shim::build_ret"); alt tys.x86_64_tys { - some(x86_64) { + some(x86_64) => { do vec::iteri(x86_64.attrs) |i, a| { alt a { - some(attr) { + some(attr) => { llvm::LLVMAddInstrAttribute( llretval, (i + 1u) as c_uint, attr as c_uint); } - _ {} + _ => () } } if x86_64.sret || !tys.ret_def { @@ -663,7 +655,7 @@ fn trans_foreign_mod(ccx: @crate_ctxt, Store(bcx, llretval, llretloc); }; } - _ { + _ => { if tys.ret_def { let n = vec::len(tys.arg_tys); // R** llretptr = &args->r; @@ -689,12 +681,12 @@ fn trans_foreign_mod(ccx: @crate_ctxt, cc: lib::llvm::CallConv) -> ValueRef { // Declare the "prototype" for the base function F: alt tys.x86_64_tys { - some(x86_64) { + some(x86_64) => { do decl_x86_64_fn(x86_64) |fnty| { decl_fn(ccx.llmod, lname, cc, fnty) } } - _ { + _ => { let llbasefnty = T_fn(tys.arg_tys, tys.ret_ty); decl_fn(ccx.llmod, lname, cc, llbasefnty) } @@ -757,13 +749,13 @@ fn trans_foreign_mod(ccx: @crate_ctxt, let mut cc = alt abi { ast::foreign_abi_rust_intrinsic | - ast::foreign_abi_cdecl { lib::llvm::CCallConv } - ast::foreign_abi_stdcall { lib::llvm::X86StdcallCallConv } + ast::foreign_abi_cdecl => lib::llvm::CCallConv, + ast::foreign_abi_stdcall => lib::llvm::X86StdcallCallConv }; for vec::each(foreign_mod.items) |foreign_item| { alt foreign_item.node { - ast::foreign_item_fn(fn_decl, typarams) { + ast::foreign_item_fn(fn_decl, typarams) => { let id = foreign_item.id; if abi != ast::foreign_abi_rust_intrinsic { let llwrapfn = get_item_val(ccx, id); @@ -781,8 +773,8 @@ fn trans_foreign_mod(ccx: @crate_ctxt, if typarams.is_empty() { let llwrapfn = get_item_val(ccx, id); let path = alt ccx.tcx.items.find(id) { - some(ast_map::node_foreign_item(_, _, pt)) { pt } - _ { + some(ast_map::node_foreign_item(_, _, pt)) => pt, + _ => { ccx.sess.span_bug(foreign_item.span, ~"can't find intrinsic path") } @@ -808,76 +800,76 @@ fn trans_intrinsic(ccx: @crate_ctxt, decl: ValueRef, item: @ast::foreign_item, some(substs), some(item.span)); let mut bcx = top_scope_block(fcx, none), lltop = bcx.llbb; alt check *item.ident { - ~"atomic_xchng" { + ~"atomic_xchng" => { let old = AtomicRMW(bcx, Xchg, get_param(decl, first_real_arg), get_param(decl, first_real_arg + 1u), SequentiallyConsistent); Store(bcx, old, fcx.llretptr); } - ~"atomic_xchng_acq" { + ~"atomic_xchng_acq" => { let old = AtomicRMW(bcx, Xchg, get_param(decl, first_real_arg), get_param(decl, first_real_arg + 1u), Acquire); Store(bcx, old, fcx.llretptr); } - ~"atomic_xchng_rel" { + ~"atomic_xchng_rel" => { let old = AtomicRMW(bcx, Xchg, get_param(decl, first_real_arg), get_param(decl, first_real_arg + 1u), Release); Store(bcx, old, fcx.llretptr); } - ~"atomic_add" { + ~"atomic_add" => { let old = AtomicRMW(bcx, lib::llvm::Add, get_param(decl, first_real_arg), get_param(decl, first_real_arg + 1u), SequentiallyConsistent); Store(bcx, old, fcx.llretptr); } - ~"atomic_add_acq" { + ~"atomic_add_acq" => { let old = AtomicRMW(bcx, lib::llvm::Add, get_param(decl, first_real_arg), get_param(decl, first_real_arg + 1u), Acquire); Store(bcx, old, fcx.llretptr); } - ~"atomic_add_rel" { + ~"atomic_add_rel" => { let old = AtomicRMW(bcx, lib::llvm::Add, get_param(decl, first_real_arg), get_param(decl, first_real_arg + 1u), Release); Store(bcx, old, fcx.llretptr); } - ~"atomic_sub" { + ~"atomic_sub" => { let old = AtomicRMW(bcx, lib::llvm::Sub, get_param(decl, first_real_arg), get_param(decl, first_real_arg + 1u), SequentiallyConsistent); Store(bcx, old, fcx.llretptr); } - ~"atomic_sub_acq" { + ~"atomic_sub_acq" => { let old = AtomicRMW(bcx, lib::llvm::Sub, get_param(decl, first_real_arg), get_param(decl, first_real_arg + 1u), Acquire); Store(bcx, old, fcx.llretptr); } - ~"atomic_sub_rel" { + ~"atomic_sub_rel" => { let old = AtomicRMW(bcx, lib::llvm::Sub, get_param(decl, first_real_arg), get_param(decl, first_real_arg + 1u), Release); Store(bcx, old, fcx.llretptr); } - ~"size_of" { + ~"size_of" => { let tp_ty = substs.tys[0]; let lltp_ty = type_of::type_of(ccx, tp_ty); Store(bcx, C_uint(ccx, shape::llsize_of_real(ccx, lltp_ty)), fcx.llretptr); } - ~"move_val" { + ~"move_val" => { let tp_ty = substs.tys[0]; let src = {bcx: bcx, val: get_param(decl, first_real_arg + 1u), @@ -887,7 +879,7 @@ fn trans_intrinsic(ccx: @crate_ctxt, decl: ValueRef, item: @ast::foreign_item, src, tp_ty); } - ~"move_val_init" { + ~"move_val_init" => { let tp_ty = substs.tys[0]; let src = {bcx: bcx, val: get_param(decl, first_real_arg + 1u), @@ -897,19 +889,19 @@ fn trans_intrinsic(ccx: @crate_ctxt, decl: ValueRef, item: @ast::foreign_item, src, tp_ty); } - ~"min_align_of" { + ~"min_align_of" => { let tp_ty = substs.tys[0]; let lltp_ty = type_of::type_of(ccx, tp_ty); Store(bcx, C_uint(ccx, shape::llalign_of_min(ccx, lltp_ty)), fcx.llretptr); } - ~"pref_align_of" { + ~"pref_align_of"=> { let tp_ty = substs.tys[0]; let lltp_ty = type_of::type_of(ccx, tp_ty); Store(bcx, C_uint(ccx, shape::llalign_of_pref(ccx, lltp_ty)), fcx.llretptr); } - ~"get_tydesc" { + ~"get_tydesc" => { let tp_ty = substs.tys[0]; let static_ti = get_tydesc(ccx, tp_ty); lazily_emit_all_tydesc_glue(ccx, static_ti); @@ -918,15 +910,15 @@ fn trans_intrinsic(ccx: @crate_ctxt, decl: ValueRef, item: @ast::foreign_item, let td = PointerCast(bcx, static_ti.tydesc, T_ptr(T_nil())); Store(bcx, td, fcx.llretptr); } - ~"init" { + ~"init" => { let tp_ty = substs.tys[0]; let lltp_ty = type_of::type_of(ccx, tp_ty); if !ty::type_is_nil(tp_ty) { Store(bcx, C_null(lltp_ty), fcx.llretptr); } } - ~"forget" {} - ~"reinterpret_cast" { + ~"forget" => {} + ~"reinterpret_cast" => { let tp_ty = substs.tys[0]; let lltp_ty = type_of::type_of(ccx, tp_ty); let llout_ty = type_of::type_of(ccx, substs.tys[1]); @@ -934,7 +926,7 @@ fn trans_intrinsic(ccx: @crate_ctxt, decl: ValueRef, item: @ast::foreign_item, out_sz = shape::llsize_of_real(ccx, llout_ty); if tp_sz != out_sz { let sp = alt check ccx.tcx.items.get(option::get(ref_id)) { - ast_map::node_expr(e) { e.span } + ast_map::node_expr(e) => e.span }; ccx.sess.span_fatal( sp, fmt!{"reinterpret_cast called on types \ @@ -948,22 +940,22 @@ fn trans_intrinsic(ccx: @crate_ctxt, decl: ValueRef, item: @ast::foreign_item, Store(bcx, Load(bcx, cast), fcx.llretptr); } } - ~"addr_of" { + ~"addr_of" => { Store(bcx, get_param(decl, first_real_arg), fcx.llretptr); } - ~"needs_drop" { + ~"needs_drop" => { let tp_ty = substs.tys[0]; Store(bcx, C_bool(ty::type_needs_drop(ccx.tcx, tp_ty)), fcx.llretptr); } - ~"visit_tydesc" { + ~"visit_tydesc" => { let td = get_param(decl, first_real_arg); let visitor = get_param(decl, first_real_arg + 1u); let td = PointerCast(bcx, td, T_ptr(ccx.tydesc_type)); call_tydesc_glue_full(bcx, visitor, td, abi::tydesc_field_visit_glue, none); } - ~"frame_address" { + ~"frame_address" => { let frameaddress = ccx.intrinsics.get(~"llvm.frameaddress"); let frameaddress_val = Call(bcx, frameaddress, ~[C_i32(0i32)]); let fty = ty::mk_fn(bcx.tcx(), { @@ -1054,7 +1046,7 @@ fn trans_foreign_fn(ccx: @crate_ctxt, path: ast_map::path, decl: ast::fn_decl, llwrapfn: ValueRef, llargbundle: ValueRef) { let _icx = bcx.insn_ctxt(~"foreign::foreign::wrap::build_args"); alt tys.x86_64_tys { - option::some(x86_64) { + option::some(x86_64) => { let mut atys = x86_64.arg_tys; let mut attrs = x86_64.attrs; let mut j = 0u; @@ -1091,7 +1083,7 @@ fn trans_foreign_fn(ccx: @crate_ctxt, path: ast_map::path, decl: ast::fn_decl, } store_inbounds(bcx, llretptr, llargbundle, ~[0u, n]); } - _ { + _ => { let llretptr = alloca(bcx, tys.ret_ty); let n = vec::len(tys.arg_tys); for uint::range(0u, n) |i| { @@ -1108,7 +1100,7 @@ fn trans_foreign_fn(ccx: @crate_ctxt, path: ast_map::path, decl: ast::fn_decl, llargbundle: ValueRef) { let _icx = bcx.insn_ctxt(~"foreign::foreign::wrap::build_ret"); alt tys.x86_64_tys { - option::some(x86_64) { + option::some(x86_64) => { if x86_64.sret || !tys.ret_def { RetVoid(bcx); return; @@ -1124,7 +1116,7 @@ fn trans_foreign_fn(ccx: @crate_ctxt, path: ast_map::path, decl: ast::fn_decl, }; Ret(bcx, llretval); } - _ { + _ => { let n = vec::len(tys.arg_tys); let llretval = load_inbounds(bcx, llargbundle, ~[0u, n]); let llretval = Load(bcx, llretval); @@ -1170,16 +1162,12 @@ fn register_foreign_fn(ccx: @crate_ctxt, sp: span, fn abi_of_foreign_fn(ccx: @crate_ctxt, i: @ast::foreign_item) -> ast::foreign_abi { alt attr::first_attr_value_str_by_name(i.attrs, ~"abi") { - none { - alt check ccx.tcx.items.get(i.id) { - ast_map::node_foreign_item(_, abi, _) { abi } - } + none => alt check ccx.tcx.items.get(i.id) { + ast_map::node_foreign_item(_, abi, _) => abi } - some(_) { - alt attr::foreign_abi(i.attrs) { - either::right(abi) { abi } - either::left(msg) { ccx.sess.span_fatal(i.span, msg); } - } + some(_) => alt attr::foreign_abi(i.attrs) { + either::right(abi) => abi, + either::left(msg) => ccx.sess.span_fatal(i.span, msg) } } } diff --git a/src/rustc/middle/trans/impl.rs b/src/rustc/middle/trans/impl.rs index 363b9ece7ad..434707f3fa8 100644 --- a/src/rustc/middle/trans/impl.rs +++ b/src/rustc/middle/trans/impl.rs @@ -53,21 +53,21 @@ fn trans_method_callee(bcx: block, callee_id: ast::node_id, -> lval_maybe_callee { let _icx = bcx.insn_ctxt(~"impl::trans_method_callee"); alt mentry.origin { - typeck::method_static(did) { + typeck::method_static(did) => { let {bcx, val} = trans_self_arg(bcx, self, mentry.derefs); {env: self_env(val, node_id_type(bcx, self.id), none) with lval_static_fn(bcx, did, callee_id)} } typeck::method_param({trait_id:iid, method_num:off, - param_num:p, bound_num:b}) { + param_num:p, bound_num:b}) => { alt check bcx.fcx.param_substs { - some(substs) { + some(substs) => { trans_monomorphized_callee(bcx, callee_id, self, mentry.derefs, iid, off, p, b, substs) } } } - typeck::method_trait(_, off) { + typeck::method_trait(_, off) => { let {bcx, val} = trans_temp_expr(bcx, self); let fty = node_id_type(bcx, callee_id); trans_trait_callee(bcx, val, fty, off) @@ -84,11 +84,11 @@ fn method_with_name(ccx: @crate_ctxt, impl_id: ast::def_id, name: ast::ident) -> ast::def_id { if impl_id.crate == ast::local_crate { alt check ccx.tcx.items.get(impl_id.node) { - ast_map::node_item(@{node: ast::item_impl(_, _, _, ms), _}, _) { + ast_map::node_item(@{node: ast::item_impl(_, _, _, ms), _}, _) => { method_from_methods(ms, name) } ast_map::node_item(@{node: - ast::item_class(_, _, items, _, _), _}, _) { + ast::item_class(_, _, items, _, _), _}, _) => { let (_,ms) = split_class_items(items); method_from_methods(ms, name) } @@ -102,7 +102,7 @@ fn method_ty_param_count(ccx: @crate_ctxt, m_id: ast::def_id, i_id: ast::def_id) -> uint { if m_id.crate == ast::local_crate { alt check ccx.tcx.items.get(m_id.node) { - ast_map::node_method(m, _, _) { vec::len(m.tps) } + ast_map::node_method(m, _, _) => vec::len(m.tps), } } else { csearch::get_type_param_count(ccx.sess.cstore, m_id) - @@ -117,7 +117,7 @@ fn trans_monomorphized_callee(bcx: block, callee_id: ast::node_id, substs: param_substs) -> lval_maybe_callee { let _icx = bcx.insn_ctxt(~"impl::trans_monomorphized_callee"); alt find_vtable_in_fn_ctxt(substs, n_param, n_bound) { - typeck::vtable_static(impl_did, impl_substs, sub_origins) { + typeck::vtable_static(impl_did, impl_substs, sub_origins) => { let ccx = bcx.ccx(); let mname = ty::trait_methods(ccx.tcx, trait_id)[n_method].ident; let mth_id = method_with_name(bcx.ccx(), impl_did, mname); @@ -135,12 +135,12 @@ fn trans_monomorphized_callee(bcx: block, callee_id: ast::node_id, ccx, node_id_type(bcx, callee_id)))) with lval} } - typeck::vtable_trait(iid, tps) { + typeck::vtable_trait(iid, tps) => { let {bcx, val} = trans_temp_expr(bcx, base); let fty = node_id_type(bcx, callee_id); trans_trait_callee(bcx, val, fty, n_method) } - typeck::vtable_param(n_param, n_bound) { + typeck::vtable_param(n_param, n_bound) => { fail ~"vtable_param left in monomorphized function's vtable substs"; } } @@ -173,7 +173,7 @@ fn find_vtable_in_fn_ctxt(ps: param_substs, n_param: uint, n_bound: uint) for vec::each(*ps.bounds) |bounds| { if i >= n_param { break; } for vec::each(*bounds) |bound| { - alt bound { ty::bound_trait(_) { vtable_off += 1u; } _ {} } + alt bound { ty::bound_trait(_) => vtable_off += 1u, _ => () } } i += 1u; } @@ -190,34 +190,34 @@ fn resolve_vtables_in_fn_ctxt(fcx: fn_ctxt, vts: typeck::vtable_res) fn resolve_vtable_in_fn_ctxt(fcx: fn_ctxt, vt: typeck::vtable_origin) -> typeck::vtable_origin { alt vt { - typeck::vtable_static(iid, tys, sub) { + typeck::vtable_static(iid, tys, sub) => { let tys = alt fcx.param_substs { - some(substs) { + some(substs) => { vec::map(tys, |t| ty::subst_tps(fcx.ccx.tcx, substs.tys, t)) } - _ { tys } + _ => tys }; typeck::vtable_static(iid, tys, resolve_vtables_in_fn_ctxt(fcx, sub)) } - typeck::vtable_param(n_param, n_bound) { + typeck::vtable_param(n_param, n_bound) => { alt check fcx.param_substs { - some(substs) { + some(substs) => { find_vtable_in_fn_ctxt(substs, n_param, n_bound) } } } - _ { vt } + _ => vt } } fn vtable_id(ccx: @crate_ctxt, origin: typeck::vtable_origin) -> mono_id { alt check origin { - typeck::vtable_static(impl_id, substs, sub_vtables) { + typeck::vtable_static(impl_id, substs, sub_vtables) => { make_mono_id(ccx, impl_id, substs, if (*sub_vtables).len() == 0u { none } else { some(sub_vtables) }, none) } - typeck::vtable_trait(trait_id, substs) { + typeck::vtable_trait(trait_id, substs) => { @{def: trait_id, params: vec::map(substs, |t| mono_precise(t, none))} } @@ -228,12 +228,10 @@ fn get_vtable(ccx: @crate_ctxt, origin: typeck::vtable_origin) -> ValueRef { let hash_id = vtable_id(ccx, origin); alt ccx.vtables.find(hash_id) { - some(val) { val } - none { - alt check origin { - typeck::vtable_static(id, substs, sub_vtables) { + some(val) => val, + none => alt check origin { + typeck::vtable_static(id, substs, sub_vtables) => { make_impl_vtable(ccx, id, substs, sub_vtables) - } } } } diff --git a/src/rustc/middle/trans/reachable.rs b/src/rustc/middle/trans/reachable.rs index a1db7e7b4bd..b149857ffaa 100644 --- a/src/rustc/middle/trans/reachable.rs +++ b/src/rustc/middle/trans/reachable.rs @@ -35,18 +35,18 @@ fn traverse_exports(cx: ctx, vis: ~[@view_item]) -> bool { let mut found_export = false; for vec::each(vis) |vi| { alt vi.node { - view_item_export(vps) { + view_item_export(vps) => { found_export = true; for vec::each(vps) |vp| { alt vp.node { view_path_simple(_, _, id) | view_path_glob(_, id) | - view_path_list(_, _, id) { + view_path_list(_, _, id) => { traverse_export(cx, id); } } } } - _ {} + _ => () } } found_export @@ -61,19 +61,21 @@ fn traverse_export(cx: ctx, exp_id: node_id) { fn traverse_def_id(cx: ctx, did: def_id) { if did.crate != local_crate { return; } let n = alt cx.tcx.items.find(did.node) { - none { return; } // This can happen for self, for example - some(n) { n } + none => return, // This can happen for self, for example + some(n) => n }; alt n { - ast_map::node_item(item, _) { traverse_public_item(cx, item); } - ast_map::node_method(_, impl_id, _) { traverse_def_id(cx, impl_id); } - ast_map::node_foreign_item(item, _, _) { cx.rmap.insert(item.id, ()); } - ast_map::node_variant(v, _, _) { cx.rmap.insert(v.node.id, ()); } + ast_map::node_item(item, _) => traverse_public_item(cx, item), + ast_map::node_method(_, impl_id, _) => traverse_def_id(cx, impl_id), + ast_map::node_foreign_item(item, _, _) => { + cx.rmap.insert(item.id, ()); + } + ast_map::node_variant(v, _, _) => { cx.rmap.insert(v.node.id, ()); } // If it's a ctor, consider the parent reachable - ast_map::node_ctor(_, _, _, parent_id, _) { + ast_map::node_ctor(_, _, _, parent_id, _) => { traverse_def_id(cx, parent_id); } - _ {} + _ => () } } @@ -88,19 +90,19 @@ fn traverse_public_item(cx: ctx, item: @item) { if cx.rmap.contains_key(item.id) { return; } cx.rmap.insert(item.id, ()); alt item.node { - item_mod(m) { traverse_public_mod(cx, m); } - item_foreign_mod(nm) { + item_mod(m) => traverse_public_mod(cx, m), + item_foreign_mod(nm) => { if !traverse_exports(cx, nm.view_items) { for vec::each(nm.items) |item| { cx.rmap.insert(item.id, ()); } } } - item_fn(_, tps, blk) { + item_fn(_, tps, blk) => { if tps.len() > 0u || attr::find_inline_attr(item.attrs) != attr::ia_none { traverse_inline_body(cx, blk); } } - item_impl(tps, _, _, ms) { + item_impl(tps, _, _, ms) => { for vec::each(ms) |m| { if tps.len() > 0u || m.tps.len() > 0u || attr::find_inline_attr(m.attrs) != attr::ia_none { @@ -109,7 +111,7 @@ fn traverse_public_item(cx: ctx, item: @item) { } } } - item_class(tps, _traits, items, m_ctor, m_dtor) { + item_class(tps, _traits, items, m_ctor, m_dtor) => { do option::iter(m_ctor) |ctor| { cx.rmap.insert(ctor.node.id, ()); if tps.len() > 0u || attr::find_inline_attr(ctor.node.attrs) @@ -126,23 +128,23 @@ fn traverse_public_item(cx: ctx, item: @item) { } for vec::each(items) |item| { alt item.node { - class_method(m) { + class_method(m) => { cx.rmap.insert(m.id, ()); if tps.len() > 0u || attr::find_inline_attr(m.attrs) != attr::ia_none { traverse_inline_body(cx, m.body); } } - _ {} + _ => () } } } - item_ty(t, _) { + item_ty(t, _) => { traverse_ty(t, cx, mk_ty_visitor()); } item_const(*) | - item_enum(*) | item_trait(*) {} - item_mac(*) { fail ~"item macros unimplemented" } + item_enum(*) | item_trait(*) => (), + item_mac(*) => fail ~"item macros unimplemented" } } @@ -155,41 +157,41 @@ fn traverse_ty(ty: @ty, cx: ctx, v: visit::vt<ctx>) { cx.rmap.insert(ty.id, ()); alt ty.node { - ty_path(p, p_id) { + ty_path(p, p_id) => { alt cx.tcx.def_map.find(p_id) { // Kind of a hack to check this here, but I'm not sure what else // to do - some(def_prim_ty(_)) { /* do nothing */ } - some(d) { traverse_def_id(cx, def_id_of_def(d)); } - none { /* do nothing -- but should we fail here? */ } + some(def_prim_ty(_)) => { /* do nothing */ } + some(d) => traverse_def_id(cx, def_id_of_def(d)), + none => { /* do nothing -- but should we fail here? */ } } for p.types.each |t| { v.visit_ty(t, cx, v); }; } - _ { visit::visit_ty(ty, cx, v); } + _ => visit::visit_ty(ty, cx, v) } } fn traverse_inline_body(cx: ctx, body: blk) { fn traverse_expr(e: @expr, cx: ctx, v: visit::vt<ctx>) { alt e.node { - expr_path(_) { + expr_path(_) => { alt cx.tcx.def_map.find(e.id) { - some(d) { + some(d) => { traverse_def_id(cx, def_id_of_def(d)); } - none { cx.tcx.sess.span_bug(e.span, fmt!{"Unbound node \ - id %? while traversing %s", e.id, expr_to_str(e)}); } + none => cx.tcx.sess.span_bug(e.span, fmt!{"Unbound node \ + id %? while traversing %s", e.id, expr_to_str(e)}) } } - expr_field(_, _, _) { + expr_field(_, _, _) => { alt cx.method_map.find(e.id) { - some({origin: typeck::method_static(did), _}) { + some({origin: typeck::method_static(did), _}) => { traverse_def_id(cx, did); } - _ {} + _ => () } } - _ {} + _ => () } visit::visit_expr(e, cx, v); } @@ -212,13 +214,13 @@ fn traverse_all_resources_and_impls(cx: ctx, crate_mod: _mod) { visit_item: |i, cx, v| { visit::visit_item(i, cx, v); alt i.node { - item_class(_, _, _, _, some(_)) { + item_class(_, _, _, _, some(_)) => { traverse_public_item(cx, i); } - item_impl(*) { + item_impl(*) => { traverse_public_item(cx, i); } - _ {} + _ => () } } with *visit::default_visitor() diff --git a/src/rustc/middle/trans/reflect.rs b/src/rustc/middle/trans/reflect.rs index f83d4a2ccc6..c4d4cd6f9b3 100644 --- a/src/rustc/middle/trans/reflect.rs +++ b/src/rustc/middle/trans/reflect.rs @@ -92,14 +92,14 @@ impl methods for reflector { vstore: ty::vstore, f: fn(~str,~[ValueRef])) { alt vstore { - ty::vstore_fixed(n) { + ty::vstore_fixed(n) => { let extra = vec::append(~[self.c_uint(n)], self.c_size_and_align(t)); f(~"fixed", extra) } - ty::vstore_slice(_) { f(~"slice", ~[]) } - ty::vstore_uniq { f(~"uniq", ~[]);} - ty::vstore_box { f(~"box", ~[]); } + ty::vstore_slice(_) => f(~"slice", ~[]), + ty::vstore_uniq => f(~"uniq", ~[]), + ty::vstore_box => f(~"box", ~[]) } } @@ -115,42 +115,42 @@ impl methods for reflector { ty_to_str(bcx.ccx().tcx, t)}; alt ty::get(t).struct { - ty::ty_bot { self.leaf(~"bot") } - ty::ty_nil { self.leaf(~"nil") } - ty::ty_bool { self.leaf(~"bool") } - ty::ty_int(ast::ty_i) { self.leaf(~"int") } - ty::ty_int(ast::ty_char) { self.leaf(~"char") } - ty::ty_int(ast::ty_i8) { self.leaf(~"i8") } - ty::ty_int(ast::ty_i16) { self.leaf(~"i16") } - ty::ty_int(ast::ty_i32) { self.leaf(~"i32") } - ty::ty_int(ast::ty_i64) { self.leaf(~"i64") } - ty::ty_uint(ast::ty_u) { self.leaf(~"uint") } - ty::ty_uint(ast::ty_u8) { self.leaf(~"u8") } - ty::ty_uint(ast::ty_u16) { self.leaf(~"u16") } - ty::ty_uint(ast::ty_u32) { self.leaf(~"u32") } - ty::ty_uint(ast::ty_u64) { self.leaf(~"u64") } - ty::ty_float(ast::ty_f) { self.leaf(~"float") } - ty::ty_float(ast::ty_f32) { self.leaf(~"f32") } - ty::ty_float(ast::ty_f64) { self.leaf(~"f64") } + ty::ty_bot => self.leaf(~"bot"), + ty::ty_nil => self.leaf(~"nil"), + ty::ty_bool => self.leaf(~"bool"), + ty::ty_int(ast::ty_i) => self.leaf(~"int"), + ty::ty_int(ast::ty_char) => self.leaf(~"char"), + ty::ty_int(ast::ty_i8) => self.leaf(~"i8"), + ty::ty_int(ast::ty_i16) => self.leaf(~"i16"), + ty::ty_int(ast::ty_i32) => self.leaf(~"i32"), + ty::ty_int(ast::ty_i64) => self.leaf(~"i64"), + ty::ty_uint(ast::ty_u) => self.leaf(~"uint"), + ty::ty_uint(ast::ty_u8) => self.leaf(~"u8"), + ty::ty_uint(ast::ty_u16) => self.leaf(~"u16"), + ty::ty_uint(ast::ty_u32) => self.leaf(~"u32"), + ty::ty_uint(ast::ty_u64) => self.leaf(~"u64"), + ty::ty_float(ast::ty_f) => self.leaf(~"float"), + ty::ty_float(ast::ty_f32) => self.leaf(~"f32"), + ty::ty_float(ast::ty_f64) => self.leaf(~"f64"), - ty::ty_unboxed_vec(mt) { self.visit(~"vec", self.c_mt(mt)) } - ty::ty_estr(vst) { + ty::ty_unboxed_vec(mt) => self.visit(~"vec", self.c_mt(mt)), + ty::ty_estr(vst) => { do self.vstore_name_and_extra(t, vst) |name, extra| { self.visit(~"estr_" + name, extra) } } - ty::ty_evec(mt, vst) { + ty::ty_evec(mt, vst) => { do self.vstore_name_and_extra(t, vst) |name, extra| { self.visit(~"evec_" + name, extra + self.c_mt(mt)) } } - ty::ty_box(mt) { self.visit(~"box", self.c_mt(mt)) } - ty::ty_uniq(mt) { self.visit(~"uniq", self.c_mt(mt)) } - ty::ty_ptr(mt) { self.visit(~"ptr", self.c_mt(mt)) } - ty::ty_rptr(_, mt) { self.visit(~"rptr", self.c_mt(mt)) } + ty::ty_box(mt) => self.visit(~"box", self.c_mt(mt)), + ty::ty_uniq(mt) => self.visit(~"uniq", self.c_mt(mt)), + ty::ty_ptr(mt) => self.visit(~"ptr", self.c_mt(mt)), + ty::ty_rptr(_, mt) => self.visit(~"rptr", self.c_mt(mt)), - ty::ty_rec(fields) { + ty::ty_rec(fields) => { do self.bracketed(~"rec", ~[self.c_uint(vec::len(fields))] + self.c_size_and_align(t)) { @@ -163,7 +163,7 @@ impl methods for reflector { } } - ty::ty_tup(tys) { + ty::ty_tup(tys) => { do self.bracketed(~"tup", ~[self.c_uint(vec::len(tys))] + self.c_size_and_align(t)) { @@ -177,22 +177,22 @@ impl methods for reflector { // FIXME (#2594): fetch constants out of intrinsic:: for the // numbers. - ty::ty_fn(fty) { + ty::ty_fn(fty) => { let pureval = alt fty.purity { - ast::pure_fn { 0u } - ast::unsafe_fn { 1u } - ast::impure_fn { 2u } - ast::extern_fn { 3u } + ast::pure_fn => 0u, + ast::unsafe_fn => 1u, + ast::impure_fn => 2u, + ast::extern_fn => 3u }; let protoval = alt fty.proto { - ast::proto_bare { 0u } - ast::proto_uniq { 2u } - ast::proto_box { 3u } - ast::proto_block { 4u } + ast::proto_bare => 0u, + ast::proto_uniq => 2u, + ast::proto_box => 3u, + ast::proto_block => 4u }; let retval = alt fty.ret_style { - ast::noreturn { 0u } - ast::return_val { 1u } + ast::noreturn => 0u, + ast::return_val => 1u }; let extra = ~[self.c_uint(pureval), self.c_uint(protoval), @@ -201,15 +201,13 @@ impl methods for reflector { self.visit(~"enter_fn", extra); for fty.inputs.eachi |i, arg| { let modeval = alt arg.mode { - ast::infer(_) { 0u } - ast::expl(e) { - alt e { - ast::by_ref { 1u } - ast::by_val { 2u } - ast::by_mutbl_ref { 3u } - ast::by_move { 4u } - ast::by_copy { 5u } - } + ast::infer(_) => 0u, + ast::expl(e) => alt e { + ast::by_ref => 1u, + ast::by_val => 2u, + ast::by_mutbl_ref => 3u, + ast::by_move => 4u, + ast::by_copy => 5u } }; self.visit(~"fn_input", @@ -223,7 +221,7 @@ impl methods for reflector { self.visit(~"leave_fn", extra); } - ty::ty_class(did, substs) { + ty::ty_class(did, substs) => { let bcx = self.bcx; let tcx = bcx.ccx().tcx; let fields = ty::class_items_as_fields(tcx, did, substs); @@ -243,7 +241,7 @@ impl methods for reflector { // not ideal. It'll work but will get costly on big enums. Maybe // let the visitor tell us if it wants to visit only a particular // variant? - ty::ty_enum(did, substs) { + ty::ty_enum(did, substs) => { let bcx = self.bcx; let tcx = bcx.ccx().tcx; let variants = ty::substd_enum_variants(tcx, did, substs); @@ -268,18 +266,18 @@ impl methods for reflector { } // Miscallaneous extra types - ty::ty_trait(_, _) { self.leaf(~"trait") } - ty::ty_var(_) { self.leaf(~"var") } - ty::ty_var_integral(_) { self.leaf(~"var_integral") } - ty::ty_param(p) { self.visit(~"param", ~[self.c_uint(p.idx)]) } - ty::ty_self { self.leaf(~"self") } - ty::ty_type { self.leaf(~"type") } - ty::ty_opaque_box { self.leaf(~"opaque_box") } - ty::ty_opaque_closure_ptr(ck) { + ty::ty_trait(_, _) => self.leaf(~"trait"), + ty::ty_var(_) => self.leaf(~"var"), + ty::ty_var_integral(_) => self.leaf(~"var_integral"), + ty::ty_param(p) => self.visit(~"param", ~[self.c_uint(p.idx)]), + ty::ty_self => self.leaf(~"self"), + ty::ty_type => self.leaf(~"type"), + ty::ty_opaque_box => self.leaf(~"opaque_box"), + ty::ty_opaque_closure_ptr(ck) => { let ckval = alt ck { - ty::ck_block { 0u } - ty::ck_box { 1u } - ty::ck_uniq { 2u } + ty::ck_block => 0u, + ty::ck_box => 1u, + ty::ck_uniq => 2u }; self.visit(~"closure_ptr", ~[self.c_uint(ckval)]) } diff --git a/src/rustc/middle/trans/shape.rs b/src/rustc/middle/trans/shape.rs index 1e25501da6c..d6d5d96e4dc 100644 --- a/src/rustc/middle/trans/shape.rs +++ b/src/rustc/middle/trans/shape.rs @@ -150,25 +150,25 @@ fn enum_kind(ccx: @crate_ctxt, did: ast::def_id) -> enum_kind { // Returns the code corresponding to the pointer size on this architecture. fn s_int(tcx: ty_ctxt) -> u8 { return alt tcx.sess.targ_cfg.arch { - session::arch_x86 { shape_i32 } - session::arch_x86_64 { shape_i64 } - session::arch_arm { shape_i32 } + session::arch_x86 => shape_i32, + session::arch_x86_64 => shape_i64, + session::arch_arm => shape_i32 }; } fn s_uint(tcx: ty_ctxt) -> u8 { return alt tcx.sess.targ_cfg.arch { - session::arch_x86 { shape_u32 } - session::arch_x86_64 { shape_u64 } - session::arch_arm { shape_u32 } + session::arch_x86 => shape_u32, + session::arch_x86_64 => shape_u64, + session::arch_arm => shape_u32 }; } fn s_float(tcx: ty_ctxt) -> u8 { return alt tcx.sess.targ_cfg.arch { - session::arch_x86 { shape_f64 } - session::arch_x86_64 { shape_f64 } - session::arch_arm { shape_f64 } + session::arch_x86 => shape_f64, + session::arch_x86_64 => shape_f64, + session::arch_arm => shape_f64 }; } @@ -215,38 +215,38 @@ fn add_substr(&dest: ~[u8], src: ~[u8]) { fn shape_of(ccx: @crate_ctxt, t: ty::t) -> ~[u8] { alt ty::get(t).struct { ty::ty_nil | ty::ty_bool | ty::ty_uint(ast::ty_u8) | - ty::ty_bot { ~[shape_u8] } - ty::ty_int(ast::ty_i) { ~[s_int(ccx.tcx)] } - ty::ty_float(ast::ty_f) { ~[s_float(ccx.tcx)] } - ty::ty_uint(ast::ty_u) | ty::ty_ptr(_) { ~[s_uint(ccx.tcx)] } - ty::ty_type { ~[s_tydesc(ccx.tcx)] } - ty::ty_int(ast::ty_i8) { ~[shape_i8] } - ty::ty_uint(ast::ty_u16) { ~[shape_u16] } - ty::ty_int(ast::ty_i16) { ~[shape_i16] } - ty::ty_uint(ast::ty_u32) { ~[shape_u32] } - ty::ty_int(ast::ty_i32) | ty::ty_int(ast::ty_char) { ~[shape_i32] } - ty::ty_uint(ast::ty_u64) { ~[shape_u64] } - ty::ty_int(ast::ty_i64) { ~[shape_i64] } - ty::ty_float(ast::ty_f32) { ~[shape_f32] } - ty::ty_float(ast::ty_f64) { ~[shape_f64] } - ty::ty_estr(ty::vstore_uniq) { + ty::ty_bot => ~[shape_u8], + ty::ty_int(ast::ty_i) => ~[s_int(ccx.tcx)], + ty::ty_float(ast::ty_f) => ~[s_float(ccx.tcx)], + ty::ty_uint(ast::ty_u) | ty::ty_ptr(_) => ~[s_uint(ccx.tcx)], + ty::ty_type => ~[s_tydesc(ccx.tcx)], + ty::ty_int(ast::ty_i8) => ~[shape_i8], + ty::ty_uint(ast::ty_u16) => ~[shape_u16], + ty::ty_int(ast::ty_i16) => ~[shape_i16], + ty::ty_uint(ast::ty_u32) => ~[shape_u32], + ty::ty_int(ast::ty_i32) | ty::ty_int(ast::ty_char) => ~[shape_i32], + ty::ty_uint(ast::ty_u64) => ~[shape_u64], + ty::ty_int(ast::ty_i64) => ~[shape_i64], + ty::ty_float(ast::ty_f32) => ~[shape_f32], + ty::ty_float(ast::ty_f64) => ~[shape_f64], + ty::ty_estr(ty::vstore_uniq) => { shape_of(ccx, tvec::expand_boxed_vec_ty(ccx.tcx, t)) } - ty::ty_enum(did, substs) { + ty::ty_enum(did, substs) => { alt enum_kind(ccx, did) { - tk_unit { ~[s_variant_enum_t(ccx.tcx)] } - tk_enum { ~[s_variant_enum_t(ccx.tcx)] } - tk_newtype | tk_complex { + tk_unit => ~[s_variant_enum_t(ccx.tcx)], + tk_enum => ~[s_variant_enum_t(ccx.tcx)], + tk_newtype | tk_complex => { let mut s = ~[shape_enum], id; let nom_id = mk_nominal_id(ccx.tcx, did, none, substs.tps); alt ccx.shape_cx.tag_id_to_index.find(nom_id) { - none { + none => { id = ccx.shape_cx.next_tag_id; ccx.shape_cx.tag_id_to_index.insert(nom_id, id); ccx.shape_cx.tag_order.push({did: did, substs: substs}); ccx.shape_cx.next_tag_id += 1u16; } - some(existing_id) { id = existing_id; } + some(existing_id) => id = existing_id, } add_u16(s, id as u16); @@ -256,23 +256,23 @@ fn shape_of(ccx: @crate_ctxt, t: ty::t) -> ~[u8] { } ty::ty_estr(ty::vstore_box) | ty::ty_evec(_, ty::vstore_box) | - ty::ty_box(_) | ty::ty_opaque_box { ~[shape_box] } - ty::ty_uniq(mt) { + ty::ty_box(_) | ty::ty_opaque_box => ~[shape_box], + ty::ty_uniq(mt) => { let mut s = ~[shape_uniq]; add_substr(s, shape_of(ccx, mt.ty)); s } - ty::ty_unboxed_vec(mt) { + ty::ty_unboxed_vec(mt) => { let mut s = ~[shape_unboxed_vec]; add_bool(s, ty::type_is_pod(ccx.tcx, mt.ty)); add_substr(s, shape_of(ccx, mt.ty)); s } - ty::ty_evec(mt, ty::vstore_uniq) { + ty::ty_evec(mt, ty::vstore_uniq) => { shape_of(ccx, tvec::expand_boxed_vec_ty(ccx.tcx, t)) } - ty::ty_estr(ty::vstore_fixed(n)) { + ty::ty_estr(ty::vstore_fixed(n)) => { let mut s = ~[shape_fixedvec]; let u8_t = ty::mk_mach_uint(ccx.tcx, ast::ty_u8); assert (n + 1u) <= 0xffffu; @@ -282,7 +282,7 @@ fn shape_of(ccx: @crate_ctxt, t: ty::t) -> ~[u8] { s } - ty::ty_evec(mt, ty::vstore_fixed(n)) { + ty::ty_evec(mt, ty::vstore_fixed(n)) => { let mut s = ~[shape_fixedvec]; assert n <= 0xffffu; add_u16(s, n as u16); @@ -291,7 +291,7 @@ fn shape_of(ccx: @crate_ctxt, t: ty::t) -> ~[u8] { s } - ty::ty_estr(ty::vstore_slice(r)) { + ty::ty_estr(ty::vstore_slice(r)) => { let mut s = ~[shape_slice]; let u8_t = ty::mk_mach_uint(ccx.tcx, ast::ty_u8); add_bool(s, true); // is_pod @@ -300,7 +300,7 @@ fn shape_of(ccx: @crate_ctxt, t: ty::t) -> ~[u8] { s } - ty::ty_evec(mt, ty::vstore_slice(r)) { + ty::ty_evec(mt, ty::vstore_slice(r)) => { let mut s = ~[shape_slice]; add_bool(s, ty::type_is_pod(ccx.tcx, mt.ty)); add_bool(s, false); // is_str @@ -308,7 +308,7 @@ fn shape_of(ccx: @crate_ctxt, t: ty::t) -> ~[u8] { s } - ty::ty_rec(fields) { + ty::ty_rec(fields) => { let mut s = ~[shape_struct], sub = ~[]; for vec::each(fields) |f| { sub += shape_of(ccx, f.mt.ty); @@ -316,7 +316,7 @@ fn shape_of(ccx: @crate_ctxt, t: ty::t) -> ~[u8] { add_substr(s, sub); s } - ty::ty_tup(elts) { + ty::ty_tup(elts) => { let mut s = ~[shape_struct], sub = ~[]; for vec::each(elts) |elt| { sub += shape_of(ccx, elt); @@ -324,8 +324,8 @@ fn shape_of(ccx: @crate_ctxt, t: ty::t) -> ~[u8] { add_substr(s, sub); s } - ty::ty_trait(_, _) { ~[shape_box_fn] } - ty::ty_class(did, substs) { + ty::ty_trait(_, _) => ~[shape_box_fn], + ty::ty_class(did, substs) => { // same as records, unless there's a dtor let tps = substs.tps; let m_dtor_did = ty::ty_dtor(ccx.tcx, did); @@ -344,20 +344,20 @@ fn shape_of(ccx: @crate_ctxt, t: ty::t) -> ~[u8] { add_substr(s, sub); s } - ty::ty_rptr(_, mt) { + ty::ty_rptr(_, mt) => { let mut s = ~[shape_rptr]; add_substr(s, shape_of(ccx, mt.ty)); s } - ty::ty_param(*) { + ty::ty_param(*) => { ccx.tcx.sess.bug(~"non-monomorphized type parameter"); } - ty::ty_fn({proto: ast::proto_box, _}) { ~[shape_box_fn] } - ty::ty_fn({proto: ast::proto_uniq, _}) { ~[shape_uniq_fn] } - ty::ty_fn({proto: ast::proto_block, _}) { ~[shape_stack_fn] } - ty::ty_fn({proto: ast::proto_bare, _}) { ~[shape_bare_fn] } - ty::ty_opaque_closure_ptr(_) { ~[shape_opaque_closure_ptr] } - ty::ty_var(_) | ty::ty_var_integral(_) | ty::ty_self { + ty::ty_fn({proto: ast::proto_box, _}) => ~[shape_box_fn], + ty::ty_fn({proto: ast::proto_uniq, _}) => ~[shape_uniq_fn], + ty::ty_fn({proto: ast::proto_block, _}) => ~[shape_stack_fn], + ty::ty_fn({proto: ast::proto_bare, _}) => ~[shape_bare_fn], + ty::ty_opaque_closure_ptr(_) => ~[shape_opaque_closure_ptr], + ty::ty_var(_) | ty::ty_var_integral(_) | ty::ty_self => { ccx.sess.bug(~"shape_of: unexpected type struct found"); } } @@ -679,7 +679,7 @@ fn llalign_of(cx: @crate_ctxt, t: TypeRef) -> ValueRef { fn static_size_of_enum(cx: @crate_ctxt, t: ty::t) -> uint { if cx.enum_sizes.contains_key(t) { return cx.enum_sizes.get(t); } alt ty::get(t).struct { - ty::ty_enum(tid, substs) { + ty::ty_enum(tid, substs) => { // Compute max(variant sizes). let mut max_size = 0u; let variants = ty::enum_variants(cx.tcx, tid); @@ -696,7 +696,7 @@ fn static_size_of_enum(cx: @crate_ctxt, t: ty::t) -> uint { cx.enum_sizes.insert(t, max_size); return max_size; } - _ { cx.sess.bug(~"static_size_of_enum called on non-enum"); } + _ => cx.sess.bug(~"static_size_of_enum called on non-enum") } } @@ -716,15 +716,15 @@ fn simplify_type(tcx: ty::ctxt, typ: ty::t) -> ty::t { ty::ty_box(_) | ty::ty_opaque_box | ty::ty_uniq(_) | ty::ty_evec(_, ty::vstore_uniq) | ty::ty_evec(_, ty::vstore_box) | ty::ty_estr(ty::vstore_uniq) | ty::ty_estr(ty::vstore_box) | - ty::ty_ptr(_) | ty::ty_rptr(_,_) { nilptr(tcx) } - ty::ty_fn(_) { ty::mk_tup(tcx, ~[nilptr(tcx), nilptr(tcx)]) } + ty::ty_ptr(_) | ty::ty_rptr(_,_) => nilptr(tcx), + ty::ty_fn(_) => ty::mk_tup(tcx, ~[nilptr(tcx), nilptr(tcx)]), ty::ty_evec(_, ty::vstore_slice(_)) | - ty::ty_estr(ty::vstore_slice(_)) { + ty::ty_estr(ty::vstore_slice(_)) => { ty::mk_tup(tcx, ~[nilptr(tcx), ty::mk_int(tcx)]) } // Reduce a class type to a record type in which all the fields are // simplified - ty::ty_class(did, substs) { + ty::ty_class(did, substs) => { let simpl_fields = (if is_some(ty::ty_dtor(tcx, did)) { // remember the drop flag ~[{ident: @~"drop", mt: {ty: @@ -738,7 +738,7 @@ fn simplify_type(tcx: ty::ctxt, typ: ty::t) -> ty::t { }; ty::mk_rec(tcx, simpl_fields) } - _ { typ } + _ => typ } } ty::fold_ty(tcx, typ, |t| simplifier(tcx, t)) diff --git a/src/rustc/middle/trans/tvec.rs b/src/rustc/middle/trans/tvec.rs index f85ca19a4b6..84d7ca370f9 100644 --- a/src/rustc/middle/trans/tvec.rs +++ b/src/rustc/middle/trans/tvec.rs @@ -20,15 +20,14 @@ fn expand_boxed_vec_ty(tcx: ty::ctxt, t: ty::t) -> ty::t { let unit_ty = ty::sequence_element_type(tcx, t); let unboxed_vec_ty = ty::mk_mut_unboxed_vec(tcx, unit_ty); alt ty::get(t).struct { - ty::ty_estr(ty::vstore_uniq) | ty::ty_evec(_, ty::vstore_uniq) { + ty::ty_estr(ty::vstore_uniq) | ty::ty_evec(_, ty::vstore_uniq) => { ty::mk_imm_uniq(tcx, unboxed_vec_ty) } - ty::ty_estr(ty::vstore_box) | ty::ty_evec(_, ty::vstore_box) { + ty::ty_estr(ty::vstore_box) | ty::ty_evec(_, ty::vstore_box) => { ty::mk_imm_box(tcx, unboxed_vec_ty) } - _ { tcx.sess.bug(~"non boxed-vec type \ - in tvec::expand_boxed_vec_ty"); - } + _ => tcx.sess.bug(~"non boxed-vec type \ + in tvec::expand_boxed_vec_ty") } } @@ -158,20 +157,20 @@ fn trans_evec(bcx: block, elements: evec_elements, let mut {bcx, val, dataptr} = alt vst { - ast::vstore_fixed(_) { + ast::vstore_fixed(_) => { // Destination should be pre-allocated for us. let v = alt dest { - base::save_in(v) { + base::save_in(v) => { PointerCast(bcx, v, T_ptr(llunitty)) } - _ { + _ => { bcx.ccx().sess.bug(~"bad dest for vstore_fixed \ in tvec::trans_evec"); } }; {bcx: bcx, val: v, dataptr: v} } - ast::vstore_slice(_) { + ast::vstore_slice(_) => { // Make a fake type to use for the cleanup let ty = ty::mk_evec(bcx.tcx(), {ty: unit_ty, mutbl: ast::m_mutbl}, @@ -190,13 +189,13 @@ fn trans_evec(bcx: block, elements: evec_elements, {bcx: bcx, val: p, dataptr: vp} } - ast::vstore_uniq { + ast::vstore_uniq => { let {bcx, val} = alloc_vec(bcx, unit_ty, count, heap_exchange); add_clean_free(bcx, val, heap_exchange); let dataptr = get_dataptr(bcx, get_bodyptr(bcx, val)); {bcx: bcx, val: val, dataptr: dataptr} } - ast::vstore_box { + ast::vstore_box => { let {bcx, val} = alloc_vec(bcx, unit_ty, count, heap_shared); add_clean_free(bcx, val, heap_shared); let dataptr = get_dataptr(bcx, get_bodyptr(bcx, val)); @@ -247,14 +246,14 @@ fn trans_evec(bcx: block, elements: evec_elements, for vec::each(temp_cleanups) |cln| { revoke_clean(bcx, cln); } alt vst { - ast::vstore_fixed(_) { + ast::vstore_fixed(_) => { // We wrote into the destination in the fixed case. return bcx; } - ast::vstore_slice(_) { + ast::vstore_slice(_) => { return base::store_in_dest(bcx, Load(bcx, val), dest); } - _ { + _ => { return base::store_in_dest(bcx, val, dest); } } @@ -290,23 +289,23 @@ fn get_base_and_len(cx: block, v: ValueRef, e_ty: ty::t) let unit_sz = llsize_of(ccx, llunitty); let vstore = alt ty::get(vec_ty).struct { - ty::ty_estr(vst) | ty::ty_evec(_, vst) { vst } - _ { ty::vstore_uniq } + ty::ty_estr(vst) | ty::ty_evec(_, vst) => vst, + _ => ty::vstore_uniq }; alt vstore { - ty::vstore_fixed(n) { + ty::vstore_fixed(n) => { let base = GEPi(cx, v, ~[0u, 0u]); let n = if ty::type_is_str(e_ty) { n + 1u } else { n }; let len = Mul(cx, C_uint(ccx, n), unit_sz); (base, len) } - ty::vstore_slice(_) { + ty::vstore_slice(_) => { let base = Load(cx, GEPi(cx, v, ~[0u, abi::slice_elt_base])); let len = Load(cx, GEPi(cx, v, ~[0u, abi::slice_elt_len])); (base, len) } - ty::vstore_uniq | ty::vstore_box { + ty::vstore_uniq | ty::vstore_box => { debug!{"get_base_and_len: %s", val_str(ccx.tn, v)}; let body = tvec::get_bodyptr(cx, v); (tvec::get_dataptr(cx, body), tvec::get_fill(cx, body)) diff --git a/src/rustc/middle/trans/type_of.rs b/src/rustc/middle/trans/type_of.rs index 79cd20bb36e..03f7d2b5482 100644 --- a/src/rustc/middle/trans/type_of.rs +++ b/src/rustc/middle/trans/type_of.rs @@ -18,8 +18,8 @@ fn type_of_explicit_args(cx: @crate_ctxt, let arg_ty = arg.ty; let llty = type_of(cx, arg_ty); alt ty::resolved_mode(cx.tcx, arg.mode) { - ast::by_val { llty } - _ { T_ptr(llty) } + ast::by_val => llty, + _ => T_ptr(llty) } } } @@ -52,13 +52,13 @@ fn type_of_non_gc_box(cx: @crate_ctxt, t: ty::t) -> TypeRef { type_of_non_gc_box(cx, t_norm) } else { alt ty::get(t).struct { - ty::ty_box(mt) { + ty::ty_box(mt) => { T_ptr(T_box(cx, type_of(cx, mt.ty))) } - ty::ty_uniq(mt) { + ty::ty_uniq(mt) => { T_ptr(T_unique(cx, type_of(cx, mt.ty))) } - _ { + _ => { cx.sess.bug(~"non-box in type_of_non_gc_box"); } } @@ -84,52 +84,52 @@ fn type_of(cx: @crate_ctxt, t: ty::t) -> TypeRef { cx.lltypes.insert(t, llty); } else { llty = alt ty::get(t).struct { - ty::ty_nil | ty::ty_bot { T_nil() } - ty::ty_bool { T_bool() } - ty::ty_int(t) { T_int_ty(cx, t) } - ty::ty_uint(t) { T_uint_ty(cx, t) } - ty::ty_float(t) { T_float_ty(cx, t) } - ty::ty_estr(ty::vstore_uniq) { + ty::ty_nil | ty::ty_bot => T_nil(), + ty::ty_bool => T_bool(), + ty::ty_int(t) => T_int_ty(cx, t), + ty::ty_uint(t) => T_uint_ty(cx, t), + ty::ty_float(t) => T_float_ty(cx, t), + ty::ty_estr(ty::vstore_uniq) => { T_unique_ptr(T_unique(cx, T_vec(cx, T_i8()))) } - ty::ty_enum(did, _) { type_of_enum(cx, did, t) } - ty::ty_estr(ty::vstore_box) { + ty::ty_enum(did, _) => type_of_enum(cx, did, t), + ty::ty_estr(ty::vstore_box) => { T_box_ptr(T_box(cx, T_vec(cx, T_i8()))) } - ty::ty_evec(mt, ty::vstore_box) { + ty::ty_evec(mt, ty::vstore_box) => { T_box_ptr(T_box(cx, T_vec(cx, type_of(cx, mt.ty)))) } - ty::ty_box(mt) { T_box_ptr(T_box(cx, type_of(cx, mt.ty))) } - ty::ty_opaque_box { T_box_ptr(T_box(cx, T_i8())) } - ty::ty_uniq(mt) { T_unique_ptr(T_unique(cx, type_of(cx, mt.ty))) } - ty::ty_evec(mt, ty::vstore_uniq) { + ty::ty_box(mt) => T_box_ptr(T_box(cx, type_of(cx, mt.ty))), + ty::ty_opaque_box => T_box_ptr(T_box(cx, T_i8())), + ty::ty_uniq(mt) => T_unique_ptr(T_unique(cx, type_of(cx, mt.ty))), + ty::ty_evec(mt, ty::vstore_uniq) => { T_unique_ptr(T_unique(cx, T_vec(cx, type_of(cx, mt.ty)))) } - ty::ty_unboxed_vec(mt) { + ty::ty_unboxed_vec(mt) => { T_vec(cx, type_of(cx, mt.ty)) } - ty::ty_ptr(mt) { T_ptr(type_of(cx, mt.ty)) } - ty::ty_rptr(_, mt) { T_ptr(type_of(cx, mt.ty)) } + ty::ty_ptr(mt) => T_ptr(type_of(cx, mt.ty)), + ty::ty_rptr(_, mt) => T_ptr(type_of(cx, mt.ty)), - ty::ty_evec(mt, ty::vstore_slice(_)) { + ty::ty_evec(mt, ty::vstore_slice(_)) => { T_struct(~[T_ptr(type_of(cx, mt.ty)), T_uint_ty(cx, ast::ty_u)]) } - ty::ty_estr(ty::vstore_slice(_)) { + ty::ty_estr(ty::vstore_slice(_)) => { T_struct(~[T_ptr(T_i8()), T_uint_ty(cx, ast::ty_u)]) } - ty::ty_estr(ty::vstore_fixed(n)) { + ty::ty_estr(ty::vstore_fixed(n)) => { T_array(T_i8(), n + 1u /* +1 for trailing null */) } - ty::ty_evec(mt, ty::vstore_fixed(n)) { + ty::ty_evec(mt, ty::vstore_fixed(n)) => { T_array(type_of(cx, mt.ty), n) } - ty::ty_rec(fields) { + ty::ty_rec(fields) => { let mut tys: ~[TypeRef] = ~[]; for vec::each(fields) |f| { let mt_ty = f.mt.ty; @@ -137,28 +137,28 @@ fn type_of(cx: @crate_ctxt, t: ty::t) -> TypeRef { } T_struct(tys) } - ty::ty_fn(_) { T_fn_pair(cx, type_of_fn_from_ty(cx, t)) } - ty::ty_trait(_, _) { T_opaque_trait(cx) } - ty::ty_type { T_ptr(cx.tydesc_type) } - ty::ty_tup(elts) { + ty::ty_fn(_) => T_fn_pair(cx, type_of_fn_from_ty(cx, t)), + ty::ty_trait(_, _) => T_opaque_trait(cx), + ty::ty_type => T_ptr(cx.tydesc_type), + ty::ty_tup(elts) => { let mut tys = ~[]; for vec::each(elts) |elt| { vec::push(tys, type_of(cx, elt)); } T_struct(tys) } - ty::ty_opaque_closure_ptr(_) { T_opaque_box_ptr(cx) } - ty::ty_class(*) { + ty::ty_opaque_closure_ptr(_) => T_opaque_box_ptr(cx), + ty::ty_class(*) => { // Only create the named struct, but don't fill it in. We fill it // in *after* placing it into the type cache. This prevents // infinite recursion with recursive class types. common::T_named_struct(llvm_type_name(cx, t)) } - ty::ty_self { cx.tcx.sess.unimpl(~"type_of: ty_self"); } - ty::ty_var(_) { cx.tcx.sess.bug(~"type_of with ty_var"); } - ty::ty_param(*) { cx.tcx.sess.bug(~"type_of with ty_param"); } - ty::ty_var_integral(_) { + ty::ty_self => cx.tcx.sess.unimpl(~"type_of: ty_self"), + ty::ty_var(_) => cx.tcx.sess.bug(~"type_of with ty_var"), + ty::ty_param(*) => cx.tcx.sess.bug(~"type_of with ty_param"), + ty::ty_var_integral(_) => { cx.tcx.sess.bug(~"type_of shouldn't see a ty_var_integral"); } }; @@ -167,7 +167,7 @@ fn type_of(cx: @crate_ctxt, t: ty::t) -> TypeRef { // If this was a class, fill in the type now. alt ty::get(t).struct { - ty::ty_class(did, ts) { + ty::ty_class(did, ts) => { // Only instance vars are record fields at runtime. let fields = ty::lookup_class_fields(cx.tcx, did); let mut tys = do vec::map(fields) |f| { @@ -182,7 +182,7 @@ fn type_of(cx: @crate_ctxt, t: ty::t) -> TypeRef { common::set_struct_body(llty, tys); } - _ { + _ => { // Nothing more to do. } } @@ -226,12 +226,8 @@ fn type_of_enum(cx: @crate_ctxt, did: ast::def_id, t: ty::t) fn llvm_type_name(cx: @crate_ctxt, t: ty::t) -> ~str { let (name, did, tps) = alt check ty::get(t).struct { - ty::ty_enum(did, substs) { - (~"enum", did, substs.tps) - } - ty::ty_class(did, substs) { - (~"class", did, substs.tps) - } + ty::ty_enum(did, substs) => (~"enum", did, substs.tps), + ty::ty_class(did, substs) => (~"class", did, substs.tps) }; return fmt!{ "%s %s[#%d]", diff --git a/src/rustc/middle/trans/type_use.rs b/src/rustc/middle/trans/type_use.rs index fd21d227632..4026d2b0a24 100644 --- a/src/rustc/middle/trans/type_use.rs +++ b/src/rustc/middle/trans/type_use.rs @@ -36,8 +36,8 @@ type ctx = {ccx: @crate_ctxt, fn type_uses_for(ccx: @crate_ctxt, fn_id: def_id, n_tps: uint) -> ~[type_uses] { alt ccx.type_use_cache.find(fn_id) { - some(uses) { return uses; } - none {} + some(uses) => return uses, + none => () } let fn_id_loc = if fn_id.crate == local_crate { fn_id } else { base::maybe_instantiate_inline(ccx, fn_id) }; @@ -46,12 +46,12 @@ fn type_uses_for(ccx: @crate_ctxt, fn_id: def_id, n_tps: uint) let cx = {ccx: ccx, uses: vec::to_mut(vec::from_elem(n_tps, 0u))}; alt ty::get(ty::lookup_item_type(cx.ccx.tcx, fn_id).ty).struct { - ty::ty_fn({inputs, _}) { + ty::ty_fn({inputs, _}) => { for vec::each(inputs) |arg| { if arg.mode == expl(by_val) { type_needs(cx, use_repr, arg.ty); } } } - _ {} + _ => () } if fn_id_loc.crate != local_crate { @@ -60,42 +60,46 @@ fn type_uses_for(ccx: @crate_ctxt, fn_id: def_id, n_tps: uint) return uses; } let map_node = alt ccx.tcx.items.find(fn_id_loc.node) { - some(x) { x } - none { ccx.sess.bug(fmt!{"type_uses_for: unbound item ID %?", - fn_id_loc}); } + some(x) => x, + none => ccx.sess.bug(fmt!{"type_uses_for: unbound item ID %?", + fn_id_loc}) }; alt check map_node { ast_map::node_item(@{node: item_fn(_, _, body), _}, _) | - ast_map::node_method(@{body, _}, _, _) { + ast_map::node_method(@{body, _}, _, _) => { handle_body(cx, body); } - ast_map::node_variant(_, _, _) { + ast_map::node_variant(_, _, _) => { for uint::range(0u, n_tps) |n| { cx.uses[n] |= use_repr;} } ast_map::node_foreign_item(i@@{node: foreign_item_fn(_, _), _}, - abi, _) { + abi, _) => { if abi == foreign_abi_rust_intrinsic { let flags = alt check *i.ident { ~"size_of" | ~"pref_align_of" | ~"min_align_of" | ~"init" | ~"reinterpret_cast" | - ~"move_val" | ~"move_val_init" { + ~"move_val" | ~"move_val_init" => { use_repr } - ~"get_tydesc" | ~"needs_drop" { use_tydesc } + ~"get_tydesc" | ~"needs_drop" => { + use_tydesc + } ~"atomic_xchng" | ~"atomic_add" | ~"atomic_sub" | ~"atomic_xchng_acq" | ~"atomic_add_acq" | ~"atomic_sub_acq" | - ~"atomic_xchng_rel" | ~"atomic_add_rel" | ~"atomic_sub_rel" { + ~"atomic_xchng_rel" | ~"atomic_add_rel" | ~"atomic_sub_rel" => { + 0u + } + ~"visit_tydesc" | ~"forget" | ~"addr_of" => { 0u } - ~"visit_tydesc" | ~"forget" | ~"addr_of" { 0u } }; for uint::range(0u, n_tps) |n| { cx.uses[n] |= flags;} } } - ast_map::node_ctor(_, _, ctor, _, _){ + ast_map::node_ctor(_, _, ctor, _, _) => { handle_body(cx, ctor.node.body); } - ast_map::node_dtor(_, dtor, _, _){ + ast_map::node_dtor(_, dtor, _, _) => { handle_body(cx, dtor.node.body); } @@ -124,8 +128,8 @@ fn type_needs_inner(cx: ctx, use: uint, ty: ty::t, right tydesc into the result) */ ty::ty_fn(_) | ty::ty_ptr(_) | ty::ty_rptr(_, _) - | ty::ty_trait(_, _) { false } - ty::ty_enum(did, substs) { + | ty::ty_trait(_, _) => false, + ty::ty_enum(did, substs) => { if option::is_none(list::find(enums_seen, |id| id == did)) { let seen = @cons(did, enums_seen); for vec::each(*ty::enum_variants(cx.ccx.tcx, did)) |v| { @@ -137,11 +141,11 @@ fn type_needs_inner(cx: ctx, use: uint, ty: ty::t, } false } - ty::ty_param(p) { + ty::ty_param(p) => { cx.uses[p.idx] |= use; false } - _ { true } + _ => true } } else { false } } @@ -162,26 +166,26 @@ fn mark_for_expr(cx: ctx, e: @expr) { expr_repeat(*) => { node_type_needs(cx, use_repr, e.id); } - expr_cast(base, _) { + expr_cast(base, _) => { let result_t = ty::node_id_to_type(cx.ccx.tcx, e.id); alt ty::get(result_t).struct { - ty::ty_trait(*) { + ty::ty_trait(*) => { // When we're casting to an trait, we need the // tydesc for the expr that's being cast. node_type_needs(cx, use_tydesc, base.id); } - _ {} + _ => () } } - expr_binary(op, lhs, _) { + expr_binary(op, lhs, _) => { alt op { - eq | lt | le | ne | ge | gt { + eq | lt | le | ne | ge | gt => { node_type_needs(cx, use_tydesc, lhs.id) } - _ {} + _ => () } } - expr_path(_) { + expr_path(_) => { do cx.ccx.tcx.node_type_substs.find(e.id).iter |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, @@ -190,10 +194,10 @@ fn mark_for_expr(cx: ctx, e: @expr) { }) } } - expr_fn(*) | expr_fn_block(*) { + expr_fn(*) | expr_fn_block(*) => { alt ty::ty_fn_proto(ty::expr_ty(cx.ccx.tcx, e)) { - proto_bare | proto_uniq {} - proto_box | proto_block { + proto_bare | proto_uniq => {} + proto_box | proto_block => { for vec::each(*freevars::get_freevars(cx.ccx.tcx, e.id)) |fv| { let node_id = ast_util::def_id_of_def(fv.def).node; node_type_needs(cx, use_repr, node_id); @@ -202,10 +206,10 @@ fn mark_for_expr(cx: ctx, e: @expr) { } } expr_assign(val, _) | expr_swap(val, _) | expr_assign_op(_, val, _) | - expr_ret(some(val)) { + expr_ret(some(val)) => { node_type_needs(cx, use_repr, val.id); } - expr_index(base, _) | expr_field(base, _, _) { + expr_index(base, _) | expr_field(base, _, _) => { // FIXME (#2537): could be more careful and not count fields after // the chosen field. let base_ty = ty::node_id_to_type(cx.ccx.tcx, base.id); @@ -213,29 +217,29 @@ fn mark_for_expr(cx: ctx, e: @expr) { do option::iter(cx.ccx.maps.method_map.find(e.id)) |mth| { alt mth.origin { - typeck::method_static(did) { + typeck::method_static(did) => { do option::iter(cx.ccx.tcx.node_type_substs.find(e.id)) |ts| { do vec::iter2(type_uses_for(cx.ccx, did, ts.len()), ts) |uses, subst| { type_needs(cx, uses, subst)} } } - typeck::method_param({param_num: param, _}) { + typeck::method_param({param_num: param, _}) => { cx.uses[param] |= use_tydesc; } - typeck::method_trait(_, _) {} + typeck::method_trait(_, _) => (), } } } - expr_log(_, _, val) { + expr_log(_, _, val) => { node_type_needs(cx, use_tydesc, val.id); } - expr_call(f, _, _) { + expr_call(f, _, _) => { vec::iter(ty::ty_fn_args(ty::node_id_to_type(cx.ccx.tcx, f.id)), |a| { alt a.mode { - expl(by_move) | expl(by_copy) | expl(by_val) { + expl(by_move) | expl(by_copy) | expl(by_val) => { type_needs(cx, use_repr, a.ty); } - _ {} + _ => () } }) } @@ -244,7 +248,7 @@ fn mark_for_expr(cx: ctx, e: @expr) { expr_unary(_, _) | expr_lit(_) | expr_assert(_) | expr_mac(_) | expr_addr_of(_, _) | expr_ret(_) | expr_loop(_) | - expr_loop_body(_) | expr_do_body(_) {} + expr_loop_body(_) | expr_do_body(_) => () } } diff --git a/src/rustc/middle/trans/uniq.rs b/src/rustc/middle/trans/uniq.rs index e51d4e4d454..c2bdf280100 100644 --- a/src/rustc/middle/trans/uniq.rs +++ b/src/rustc/middle/trans/uniq.rs @@ -20,8 +20,8 @@ fn make_free_glue(bcx: block, vptr: ValueRef, t: ty::t) fn content_ty(t: ty::t) -> ty::t { alt ty::get(t).struct { - ty::ty_uniq({ty: ct, _}) { ct } - _ { core::unreachable(); } + ty::ty_uniq({ty: ct, _}) => ct, + _ => core::unreachable() } } diff --git a/src/rustc/middle/ty.rs b/src/rustc/middle/ty.rs index efa44f96bce..210c4c9af86 100644 --- a/src/rustc/middle/ty.rs +++ b/src/rustc/middle/ty.rs @@ -511,19 +511,19 @@ fn param_bounds_to_kind(bounds: param_bounds) -> kind { let mut kind = kind_noncopyable(); for vec::each(*bounds) |bound| { alt bound { - bound_copy { + bound_copy => { kind = raise_kind(kind, kind_implicitly_copyable()); } - bound_owned { + bound_owned => { kind = raise_kind(kind, kind_owned()); } - bound_send { + bound_send => { kind = raise_kind(kind, kind_send_only() | kind_owned()); } - bound_const { + bound_const => { kind = raise_kind(kind, kind_const()); } - bound_trait(_) {} + bound_trait(_) => () } } kind @@ -609,15 +609,15 @@ fn mk_t(cx: ctxt, st: sty) -> t { mk_t_with_id(cx, st, none) } fn mk_t_with_id(cx: ctxt, st: sty, o_def_id: option<ast::def_id>) -> t { let key = {struct: st, o_def_id: o_def_id}; alt cx.interner.find(key) { - some(t) { unsafe { return unsafe::reinterpret_cast(t); } } - _ {} + some(t) => unsafe { return unsafe::reinterpret_cast(t); } + _ => () } let mut flags = 0u; fn rflags(r: region) -> uint { (has_regions as uint) | { alt r { - ty::re_var(_) {needs_infer as uint} - _ {0u} + ty::re_var(_) => needs_infer as uint, + _ => 0u } } } @@ -628,37 +628,33 @@ fn mk_t_with_id(cx: ctxt, st: sty, o_def_id: option<ast::def_id>) -> t { return f; } alt st { - ty_estr(vstore_slice(r)) { + ty_estr(vstore_slice(r)) => { flags |= rflags(r); } - ty_evec(mt, vstore_slice(r)) { + ty_evec(mt, vstore_slice(r)) => { flags |= rflags(r); flags |= get(mt.ty).flags; } ty_nil | ty_bot | ty_bool | ty_int(_) | ty_float(_) | ty_uint(_) | ty_estr(_) | ty_type | ty_opaque_closure_ptr(_) | - ty_opaque_box {} - ty_param(_) { flags |= has_params as uint; } - ty_var(_) | ty_var_integral(_) { flags |= needs_infer as uint; } - ty_self { flags |= has_self as uint; } - ty_enum(_, substs) | ty_class(_, substs) | ty_trait(_, substs) { + ty_opaque_box => (), + ty_param(_) => flags |= has_params as uint, + ty_var(_) | ty_var_integral(_) => flags |= needs_infer as uint, + ty_self => flags |= has_self as uint, + ty_enum(_, substs) | ty_class(_, substs) | ty_trait(_, substs) => { flags |= sflags(substs); } ty_box(m) | ty_uniq(m) | ty_evec(m, _) | - ty_ptr(m) | ty_unboxed_vec(m) { + ty_ptr(m) | ty_unboxed_vec(m) => { flags |= get(m.ty).flags; } - ty_rptr(r, m) { + ty_rptr(r, m) => { flags |= rflags(r); flags |= get(m.ty).flags; } - ty_rec(flds) { - for flds.each |f| { flags |= get(f.mt.ty).flags; } - } - ty_tup(ts) { - for ts.each |tt| { flags |= get(tt).flags; } - } - ty_fn(f) { + ty_rec(flds) => for flds.each |f| { flags |= get(f.mt.ty).flags; } + ty_tup(ts) => for ts.each |tt| { flags |= get(tt).flags; } + ty_fn(f) => { for f.inputs.each |a| { flags |= get(a.ty).flags; } flags |= get(f.output).flags; } @@ -791,10 +787,10 @@ fn mk_with_id(cx: ctxt, base: t, def_id: ast::def_id) -> t { // Converts s to its machine type equivalent pure fn mach_sty(cfg: @session::config, t: t) -> sty { alt get(t).struct { - ty_int(ast::ty_i) { ty_int(cfg.int_type) } - ty_uint(ast::ty_u) { ty_uint(cfg.uint_type) } - ty_float(ast::ty_f) { ty_float(cfg.float_type) } - s { s } + ty_int(ast::ty_i) => ty_int(cfg.int_type), + ty_uint(ast::ty_u) => ty_uint(cfg.uint_type), + ty_float(ast::ty_f) => ty_float(cfg.float_type), + s => s } } @@ -807,8 +803,8 @@ fn default_arg_mode_for_ty(ty: ty::t) -> ast::rmode { // with id `id`. fn encl_region(cx: ctxt, id: ast::node_id) -> ty::region { alt cx.region_map.find(id) { - some(encl_scope) {ty::re_scope(encl_scope)} - none {ty::re_static} + some(encl_scope) => ty::re_scope(encl_scope), + none => ty::re_static } } @@ -822,25 +818,25 @@ fn maybe_walk_ty(ty: t, f: fn(t) -> bool) { ty_nil | ty_bot | ty_bool | ty_int(_) | ty_uint(_) | ty_float(_) | ty_estr(_) | ty_type | ty_opaque_box | ty_self | ty_opaque_closure_ptr(_) | ty_var(_) | ty_var_integral(_) | - ty_param(_) { + ty_param(_) => { } ty_box(tm) | ty_evec(tm, _) | ty_unboxed_vec(tm) | - ty_ptr(tm) | ty_rptr(_, tm) { + ty_ptr(tm) | ty_rptr(_, tm) => { maybe_walk_ty(tm.ty, f); } ty_enum(_, substs) | ty_class(_, substs) | - ty_trait(_, substs) { + ty_trait(_, substs) => { for substs.tps.each |subty| { maybe_walk_ty(subty, f); } } - ty_rec(fields) { + ty_rec(fields) => { for fields.each |fl| { maybe_walk_ty(fl.mt.ty, f); } } - ty_tup(ts) { for ts.each |tt| { maybe_walk_ty(tt, f); } } - ty_fn(ft) { + ty_tup(ts) => { for ts.each |tt| { maybe_walk_ty(tt, f); } } + ty_fn(ft) => { for ft.inputs.each |a| { maybe_walk_ty(a.ty, f); } maybe_walk_ty(ft.output, f); } - ty_uniq(tm) { maybe_walk_ty(tm.ty, f); } + ty_uniq(tm) => { maybe_walk_ty(tm.ty, f); } } } @@ -856,28 +852,28 @@ fn fold_sty(sty: sty, fldop: fn(t) -> t) -> sty { } alt sty { - ty_box(tm) { + ty_box(tm) => { ty_box({ty: fldop(tm.ty), mutbl: tm.mutbl}) } - ty_uniq(tm) { + ty_uniq(tm) => { ty_uniq({ty: fldop(tm.ty), mutbl: tm.mutbl}) } - ty_ptr(tm) { + ty_ptr(tm) => { ty_ptr({ty: fldop(tm.ty), mutbl: tm.mutbl}) } - ty_unboxed_vec(tm) { + ty_unboxed_vec(tm) => { ty_unboxed_vec({ty: fldop(tm.ty), mutbl: tm.mutbl}) } - ty_evec(tm, vst) { + ty_evec(tm, vst) => { ty_evec({ty: fldop(tm.ty), mutbl: tm.mutbl}, vst) } - ty_enum(tid, substs) { + ty_enum(tid, substs) => { ty_enum(tid, fold_substs(substs, fldop)) } - ty_trait(did, substs) { + ty_trait(did, substs) => { ty_trait(did, fold_substs(substs, fldop)) } - ty_rec(fields) { + ty_rec(fields) => { let new_fields = do vec::map(fields) |fl| { let new_ty = fldop(fl.mt.ty); let new_mt = {ty: new_ty, mutbl: fl.mt.mutbl}; @@ -885,11 +881,11 @@ fn fold_sty(sty: sty, fldop: fn(t) -> t) -> sty { }; ty_rec(new_fields) } - ty_tup(ts) { + ty_tup(ts) => { let new_ts = vec::map(ts, |tt| fldop(tt)); ty_tup(new_ts) } - ty_fn(f) { + ty_fn(f) => { let new_args = vec::map(f.inputs, |a| { let new_ty = fldop(a.ty); {mode: a.mode, ty: new_ty} @@ -897,15 +893,16 @@ fn fold_sty(sty: sty, fldop: fn(t) -> t) -> sty { let new_output = fldop(f.output); ty_fn({inputs: new_args, output: new_output with f}) } - ty_rptr(r, tm) { + ty_rptr(r, tm) => { ty_rptr(r, {ty: fldop(tm.ty), mutbl: tm.mutbl}) } - ty_class(did, substs) { + ty_class(did, substs) => { ty_class(did, fold_substs(substs, fldop)) } ty_nil | ty_bot | ty_bool | ty_int(_) | ty_uint(_) | ty_float(_) | ty_estr(_) | ty_type | ty_opaque_closure_ptr(_) | - ty_opaque_box | ty_var(_) | ty_var_integral(_) | ty_param(*) | ty_self { + ty_opaque_box | ty_var(_) | ty_var_integral(_) | + ty_param(*) | ty_self => { sty } } @@ -951,33 +948,33 @@ fn fold_regions_and_ty( let tb = ty::get(ty); alt tb.struct { - ty::ty_rptr(r, mt) { + ty::ty_rptr(r, mt) => { let m_r = fldr(r); let m_t = fldt(mt.ty); ty::mk_rptr(cx, m_r, {ty: m_t, mutbl: mt.mutbl}) } - ty_estr(vstore_slice(r)) { + ty_estr(vstore_slice(r)) => { let m_r = fldr(r); ty::mk_estr(cx, vstore_slice(m_r)) } - ty_evec(mt, vstore_slice(r)) { + ty_evec(mt, vstore_slice(r)) => { let m_r = fldr(r); let m_t = fldt(mt.ty); ty::mk_evec(cx, {ty: m_t, mutbl: mt.mutbl}, vstore_slice(m_r)) } - ty_enum(def_id, substs) { + ty_enum(def_id, substs) => { ty::mk_enum(cx, def_id, fold_substs(substs, fldr, fldt)) } - ty_class(def_id, substs) { + ty_class(def_id, substs) => { ty::mk_class(cx, def_id, fold_substs(substs, fldr, fldt)) } - ty_trait(def_id, substs) { + ty_trait(def_id, substs) => { ty::mk_trait(cx, def_id, fold_substs(substs, fldr, fldt)) } - sty @ ty_fn(_) { + sty @ ty_fn(_) => { fold_sty_to_ty(cx, sty, |t| fldfnt(t)) } - sty { + sty => { fold_sty_to_ty(cx, sty, |t| fldt(t)) } } @@ -1008,25 +1005,25 @@ fn fold_region(cx: ctxt, t0: t, fldop: fn(region, bool) -> region) -> t { let tb = get(t0); if !tbox_has_flag(tb, has_regions) { return t0; } alt tb.struct { - ty_rptr(r, {ty: t1, mutbl: m}) { + ty_rptr(r, {ty: t1, mutbl: m}) => { let m_r = fldop(r, under_r); let m_t1 = do_fold(cx, t1, true, fldop); ty::mk_rptr(cx, m_r, {ty: m_t1, mutbl: m}) } - ty_estr(vstore_slice(r)) { + ty_estr(vstore_slice(r)) => { let m_r = fldop(r, under_r); ty::mk_estr(cx, vstore_slice(m_r)) } - ty_evec({ty: t1, mutbl: m}, vstore_slice(r)) { + ty_evec({ty: t1, mutbl: m}, vstore_slice(r)) => { let m_r = fldop(r, under_r); let m_t1 = do_fold(cx, t1, true, fldop); ty::mk_evec(cx, {ty: m_t1, mutbl: m}, vstore_slice(m_r)) } - ty_fn(_) { + ty_fn(_) => { // do not recurse into functions, which introduce fresh bindings t0 } - sty { + sty => { do fold_sty_to_ty(cx, sty) |t| { do_fold(cx, t, under_r, fldop) } @@ -1043,8 +1040,8 @@ fn subst_tps(cx: ctxt, tps: ~[t], typ: t) -> t { let tb = ty::get(typ); if !tbox_has_flag(tb, has_params) { return typ; } alt tb.struct { - ty_param(p) { tps[p.idx] } - sty { fold_sty_to_ty(cx, sty, |t| subst_tps(cx, tps, t)) } + ty_param(p) => tps[p.idx], + sty => fold_sty_to_ty(cx, sty, |t| subst_tps(cx, tps, t)) } } @@ -1080,14 +1077,14 @@ fn subst(cx: ctxt, let tb = get(typ); if !tbox_has_flag(tb, needs_subst) { return typ; } alt tb.struct { - ty_param(p) {substs.tps[p.idx]} - ty_self {substs.self_ty.get()} - _ { + ty_param(p) => substs.tps[p.idx], + ty_self => substs.self_ty.get(), + _ => { fold_regions_and_ty( cx, typ, |r| alt r { - re_bound(br_self) {substs.self_r.get()} - _ {r} + re_bound(br_self) => substs.self_r.get(), + _ => r }, |t| do_subst(cx, substs, t), |t| do_subst(cx, substs, t)) @@ -1104,15 +1101,15 @@ fn type_is_bot(ty: t) -> bool { get(ty).struct == ty_bot } fn type_is_var(ty: t) -> bool { alt get(ty).struct { - ty_var(_) { true } - _ { false } + ty_var(_) => true, + _ => false } } fn type_is_var_integral(ty: t) -> bool { alt get(ty).struct { - ty_var_integral(_) { true } - _ { false } + ty_var_integral(_) => true, + _ => false } } @@ -1124,8 +1121,8 @@ fn type_is_structural(ty: t) -> bool { ty_trait(*) | ty_evec(_, vstore_fixed(_)) | ty_estr(vstore_fixed(_)) | ty_evec(_, vstore_slice(_)) | ty_estr(vstore_slice(_)) - { true } - _ { false } + => true, + _ => false } } @@ -1135,93 +1132,92 @@ fn type_is_copyable(cx: ctxt, ty: t) -> bool { fn type_is_sequence(ty: t) -> bool { alt get(ty).struct { - ty_estr(_) | ty_evec(_, _) { true } - _ { false } + ty_estr(_) | ty_evec(_, _) => true, + _ => false } } fn type_is_str(ty: t) -> bool { alt get(ty).struct { - ty_estr(_) { true } - _ { false } + ty_estr(_) => true, + _ => false } } fn sequence_element_type(cx: ctxt, ty: t) -> t { alt get(ty).struct { - ty_estr(_) { return mk_mach_uint(cx, ast::ty_u8); } - ty_evec(mt, _) | ty_unboxed_vec(mt) { return mt.ty; } - _ { cx.sess.bug( - ~"sequence_element_type called on non-sequence value"); - } + ty_estr(_) => return mk_mach_uint(cx, ast::ty_u8), + ty_evec(mt, _) | ty_unboxed_vec(mt) => return mt.ty, + _ => cx.sess.bug( + ~"sequence_element_type called on non-sequence value"), } } fn get_element_type(ty: t, i: uint) -> t { alt get(ty).struct { - ty_rec(flds) { return flds[i].mt.ty; } - ty_tup(ts) { return ts[i]; } - _ { fail ~"get_element_type called on invalid type"; } + ty_rec(flds) => return flds[i].mt.ty, + ty_tup(ts) => return ts[i], + _ => fail ~"get_element_type called on invalid type" } } pure fn type_is_box(ty: t) -> bool { alt get(ty).struct { - ty_box(_) { return true; } - _ { return false; } + ty_box(_) => return true, + _ => return false } } pure fn type_is_boxed(ty: t) -> bool { alt get(ty).struct { ty_box(_) | ty_opaque_box | - ty_evec(_, vstore_box) | ty_estr(vstore_box) { true } - _ { false } + ty_evec(_, vstore_box) | ty_estr(vstore_box) => true, + _ => false } } pure fn type_is_region_ptr(ty: t) -> bool { alt get(ty).struct { - ty_rptr(_, _) { true } - _ { false } + ty_rptr(_, _) => true, + _ => false } } pure fn type_is_slice(ty: t) -> bool { alt get(ty).struct { - ty_evec(_, vstore_slice(_)) | ty_estr(vstore_slice(_)) { true } - _ { return false; } + ty_evec(_, vstore_slice(_)) | ty_estr(vstore_slice(_)) => true, + _ => return false } } pure fn type_is_unique_box(ty: t) -> bool { alt get(ty).struct { - ty_uniq(_) { return true; } - _ { return false; } + ty_uniq(_) => return true, + _ => return false } } pure fn type_is_unsafe_ptr(ty: t) -> bool { alt get(ty).struct { - ty_ptr(_) { return true; } - _ { return false; } + ty_ptr(_) => return true, + _ => return false } } pure fn type_is_vec(ty: t) -> bool { return alt get(ty).struct { - ty_evec(_, _) | ty_unboxed_vec(_) { true } - ty_estr(_) { true } - _ { false } + ty_evec(_, _) | ty_unboxed_vec(_) => true, + ty_estr(_) => true, + _ => false }; } pure fn type_is_unique(ty: t) -> bool { alt get(ty).struct { - ty_uniq(_) { return true; } - ty_evec(_, vstore_uniq) { true } - ty_estr(vstore_uniq) { true } - _ { return false; } + ty_uniq(_) => return true, + ty_evec(_, vstore_uniq) => true, + ty_estr(vstore_uniq) => true, + _ => return false } } @@ -1233,8 +1229,8 @@ pure fn type_is_unique(ty: t) -> bool { pure fn type_is_scalar(ty: t) -> bool { alt get(ty).struct { ty_nil | ty_bool | ty_int(_) | ty_float(_) | ty_uint(_) | - ty_var_integral(_) | ty_type | ty_ptr(_) { true } - _ { false } + ty_var_integral(_) | ty_type | ty_ptr(_) => true, + _ => false } } @@ -1245,8 +1241,8 @@ fn type_is_immediate(ty: t) -> bool { fn type_needs_drop(cx: ctxt, ty: t) -> bool { alt cx.needs_drop_cache.find(ty) { - some(result) { return result; } - none {/* fall through */ } + some(result) => return result, + none => {/* fall through */ } } let mut accum = false; @@ -1255,16 +1251,16 @@ fn type_needs_drop(cx: ctxt, ty: t) -> bool { ty_nil | ty_bot | ty_bool | ty_int(_) | ty_float(_) | ty_uint(_) | ty_type | ty_ptr(_) | ty_rptr(_, _) | ty_estr(vstore_fixed(_)) | ty_estr(vstore_slice(_)) | - ty_evec(_, vstore_slice(_)) { false } - ty_evec(mt, vstore_fixed(_)) { type_needs_drop(cx, mt.ty) } - ty_unboxed_vec(mt) { type_needs_drop(cx, mt.ty) } - ty_rec(flds) { + ty_evec(_, vstore_slice(_)) => false, + ty_evec(mt, vstore_fixed(_)) => type_needs_drop(cx, mt.ty), + ty_unboxed_vec(mt) => type_needs_drop(cx, mt.ty), + ty_rec(flds) => { for flds.each |f| { if type_needs_drop(cx, f.mt.ty) { accum = true; } } accum } - ty_class(did, substs) { + ty_class(did, substs) => { // Any class with a dtor needs a drop option::is_some(ty_dtor(cx, did)) || { for vec::each(ty::class_items_as_fields(cx, did, substs)) |f| { @@ -1273,11 +1269,11 @@ fn type_needs_drop(cx: ctxt, ty: t) -> bool { accum } } - ty_tup(elts) { + ty_tup(elts) => { for elts.each |m| { if type_needs_drop(cx, m) { accum = true; } } accum } - ty_enum(did, substs) { + ty_enum(did, substs) => { let variants = enum_variants(cx, did); for vec::each(*variants) |variant| { for variant.args.each |aty| { @@ -1289,13 +1285,13 @@ fn type_needs_drop(cx: ctxt, ty: t) -> bool { } accum } - ty_fn(fty) { + ty_fn(fty) => { alt fty.proto { - proto_bare | proto_block { false } - _ { true } + proto_bare | proto_block => false, + _ => true } } - _ { true } + _ => true }; cx.needs_drop_cache.insert(ty, result); @@ -1308,8 +1304,8 @@ fn type_needs_drop(cx: ctxt, ty: t) -> bool { // cleanups. fn type_needs_unwind_cleanup(cx: ctxt, ty: t) -> bool { alt cx.needs_unwind_cleanup_cache.find(ty) { - some(result) { return result; } - none { } + some(result) => return result, + none => () } let tycache = new_ty_hash(); @@ -1325,8 +1321,8 @@ fn type_needs_unwind_cleanup_(cx: ctxt, ty: t, // Prevent infinite recursion alt tycache.find(ty) { - some(_) { return false; } - none { tycache.insert(ty, ()); } + some(_) => return false, + none => { tycache.insert(ty, ()); } } let mut encountered_box = encountered_box; @@ -1334,16 +1330,16 @@ fn type_needs_unwind_cleanup_(cx: ctxt, ty: t, do maybe_walk_ty(ty) |ty| { let old_encountered_box = encountered_box; let result = alt get(ty).struct { - ty_box(_) | ty_opaque_box { + ty_box(_) | ty_opaque_box => { encountered_box = true; true } ty_nil | ty_bot | ty_bool | ty_int(_) | ty_uint(_) | ty_float(_) | - ty_rec(_) | ty_tup(_) | ty_ptr(_) { + ty_rec(_) | ty_tup(_) | ty_ptr(_) => { true } - ty_enum(did, substs) { + ty_enum(did, substs) => { for vec::each(*enum_variants(cx, did)) |v| { for v.args.each |aty| { let t = subst(cx, substs, aty); @@ -1359,7 +1355,7 @@ fn type_needs_unwind_cleanup_(cx: ctxt, ty: t, ty_estr(vstore_box) | ty_evec(_, vstore_uniq) | ty_evec(_, vstore_box) - { + => { // Once we're inside a box, the annihilator will find // it and destroy it. if !encountered_box { @@ -1369,7 +1365,7 @@ fn type_needs_unwind_cleanup_(cx: ctxt, ty: t, true } } - _ { + _ => { needs_unwind_cleanup = true; false } @@ -1533,11 +1529,11 @@ pure fn kind_is_owned(k: kind) -> bool { fn proto_kind(p: proto) -> kind { alt p { - ast::proto_block { kind_noncopyable() } - ast::proto_box { kind_safe_for_default_mode() | kind_owned() } - ast::proto_uniq { kind_send_copy() | kind_owned() } - ast::proto_bare { kind_safe_for_default_mode_send() | kind_const() | - kind_owned() } + ast::proto_block => kind_noncopyable(), + ast::proto_box => kind_safe_for_default_mode() | kind_owned(), + ast::proto_uniq => kind_send_copy() | kind_owned(), + ast::proto_bare => kind_safe_for_default_mode_send() | kind_const() | + kind_owned() } } @@ -1576,9 +1572,9 @@ fn test_kinds() { // implicitly copied and to compute whether things have const kind. fn mutability_kind(m: mutability) -> kind { alt (m) { - m_mutbl { remove_const(remove_implicit(kind_top())) } - m_const { remove_implicit(kind_top()) } - m_imm { kind_top() } + m_mutbl => remove_const(remove_implicit(kind_top())), + m_const => remove_implicit(kind_top()), + m_imm => kind_top() } } @@ -1588,8 +1584,8 @@ fn mutable_type_kind(cx: ctxt, ty: mt) -> kind { fn type_kind(cx: ctxt, ty: t) -> kind { alt cx.kind_cache.find(ty) { - some(result) { return result; } - none {/* fall through */ } + some(result) => return result, + none => {/* fall through */ } } // Insert a default in case we loop back on self recursively. @@ -1598,12 +1594,12 @@ fn type_kind(cx: ctxt, ty: t) -> kind { let mut result = alt get(ty).struct { // Scalar and unique types are sendable, constant, and owned ty_nil | ty_bot | ty_bool | ty_int(_) | ty_uint(_) | ty_float(_) | - ty_ptr(_) { + ty_ptr(_) => { kind_safe_for_default_mode_send() | kind_const() | kind_owned() } // Implicit copyability of strs is configurable - ty_estr(vstore_uniq) { + ty_estr(vstore_uniq) => { if cx.vecs_implicitly_copyable { kind_implicitly_sendable() | kind_const() | kind_owned() } else { @@ -1612,26 +1608,26 @@ fn type_kind(cx: ctxt, ty: t) -> kind { } // functions depend on the protocol - ty_fn(f) { proto_kind(f.proto) } + ty_fn(f) => proto_kind(f.proto), // Those with refcounts raise noncopyable to copyable, // lower sendable to copyable. Therefore just set result to copyable. - ty_box(tm) { + ty_box(tm) => { remove_send(mutable_type_kind(cx, tm) | kind_safe_for_default_mode()) } // Trait instances are (for now) like shared boxes, basically - ty_trait(_, _) { kind_safe_for_default_mode() | kind_owned() } + ty_trait(_, _) => kind_safe_for_default_mode() | kind_owned(), // Region pointers are copyable but NOT owned nor sendable - ty_rptr(_, _) { kind_safe_for_default_mode() } + ty_rptr(_, _) => kind_safe_for_default_mode(), // Unique boxes and vecs have the kind of their contained type, // but unique boxes can't be implicitly copyable. - ty_uniq(tm) { remove_implicit(mutable_type_kind(cx, tm)) } + ty_uniq(tm) => remove_implicit(mutable_type_kind(cx, tm)), // Implicit copyability of vecs is configurable - ty_evec(tm, vstore_uniq) { + ty_evec(tm, vstore_uniq) => { if cx.vecs_implicitly_copyable { mutable_type_kind(cx, tm) } else { @@ -1642,30 +1638,30 @@ fn type_kind(cx: ctxt, ty: t) -> kind { // Slices, refcounted evecs are copyable; uniques depend on the their // contained type, but aren't implicitly copyable. Fixed vectors have // the kind of the element they contain, taking mutability into account. - ty_evec(tm, vstore_box) { + ty_evec(tm, vstore_box) => { remove_send(kind_safe_for_default_mode() | mutable_type_kind(cx, tm)) } - ty_evec(tm, vstore_slice(_)) { + ty_evec(tm, vstore_slice(_)) => { remove_owned_send(kind_safe_for_default_mode() | mutable_type_kind(cx, tm)) } - ty_evec(tm, vstore_fixed(_)) { + ty_evec(tm, vstore_fixed(_)) => { mutable_type_kind(cx, tm) } // All estrs are copyable; uniques and interiors are sendable. - ty_estr(vstore_box) { + ty_estr(vstore_box) => { kind_safe_for_default_mode() | kind_const() | kind_owned() } - ty_estr(vstore_slice(_)) { + ty_estr(vstore_slice(_)) => { kind_safe_for_default_mode() | kind_const() } - ty_estr(vstore_fixed(_)) { + ty_estr(vstore_fixed(_)) => { kind_safe_for_default_mode_send() | kind_const() | kind_owned() } // Records lower to the lowest of their members. - ty_rec(flds) { + ty_rec(flds) => { let mut lowest = kind_top(); for flds.each |f| { lowest = lower_kind(lowest, mutable_type_kind(cx, f.mt)); @@ -1673,7 +1669,7 @@ fn type_kind(cx: ctxt, ty: t) -> kind { lowest } - ty_class(did, substs) { + ty_class(did, substs) => { // Classes are sendable if all their fields are sendable, // likewise for copyable... // also factor out this code, copied from the records case @@ -1691,14 +1687,14 @@ fn type_kind(cx: ctxt, ty: t) -> kind { } // Tuples lower to the lowest of their members. - ty_tup(tys) { + ty_tup(tys) => { let mut lowest = kind_top(); for tys.each |ty| { lowest = lower_kind(lowest, type_kind(cx, ty)); } lowest } // Enums lower to the lowest of their variants. - ty_enum(did, substs) { + ty_enum(did, substs) => { let mut lowest = kind_top(); let variants = enum_variants(cx, did); if vec::len(*variants) == 0u { @@ -1716,18 +1712,19 @@ fn type_kind(cx: ctxt, ty: t) -> kind { lowest } - ty_param(p) { + ty_param(p) => { param_bounds_to_kind(cx.ty_param_bounds.get(p.def_id.node)) } // self is a special type parameter that can only appear in traits; it // is never bounded in any way, hence it has the bottom kind. - ty_self { kind_noncopyable() } + ty_self => kind_noncopyable(), - ty_var(_) | ty_var_integral(_) { + ty_var(_) | ty_var_integral(_) => { cx.sess.bug(~"Asked to compute kind of a type variable"); } - ty_type | ty_opaque_closure_ptr(_) | ty_opaque_box | ty_unboxed_vec(_) { + ty_type | ty_opaque_closure_ptr(_) + | ty_opaque_box | ty_unboxed_vec(_) => { cx.sess.bug(~"Asked to compute kind of fictitious type"); } }; @@ -1772,16 +1769,16 @@ fn type_size(cx: ctxt, ty: t) -> uint { flds.foldl(0, |s, f| s + type_size(cx, f.mt.ty)) } - ty_class(did, substs) { + ty_class(did, substs) => { let flds = class_items_as_fields(cx, did, substs); flds.foldl(0, |s, f| s + type_size(cx, f.mt.ty)) } - ty_tup(tys) { + ty_tup(tys) => { tys.foldl(0, |s, t| s + type_size(cx, t)) } - ty_enum(did, substs) { + ty_enum(did, substs) => { let variants = substd_enum_variants(cx, did, substs); variants.foldl( // find max size of any variant 0, @@ -1790,14 +1787,15 @@ fn type_size(cx: ctxt, ty: t) -> uint { v.args.foldl(0, |s, a| s + type_size(cx, a)))) } - ty_param(_) | ty_self { + ty_param(_) | ty_self => { 1 } - ty_var(_) | ty_var_integral(_) { + ty_var(_) | ty_var_integral(_) => { cx.sess.bug(~"Asked to compute kind of a type variable"); } - ty_type | ty_opaque_closure_ptr(_) | ty_opaque_box | ty_unboxed_vec(_) { + ty_type | ty_opaque_closure_ptr(_) + | ty_opaque_box | ty_unboxed_vec(_) => { cx.sess.bug(~"Asked to compute kind of fictitious type"); } } @@ -1847,34 +1845,34 @@ fn is_instantiable(cx: ctxt, r_ty: t) -> bool { ty_opaque_box | ty_opaque_closure_ptr(_) | ty_evec(_, _) | - ty_unboxed_vec(_) { + ty_unboxed_vec(_) => { false } ty_box(mt) | ty_uniq(mt) | - ty_rptr(_, mt) { + ty_rptr(_, mt) => { return type_requires(cx, seen, r_ty, mt.ty); } - ty_ptr(mt) { + ty_ptr(mt) => { false // unsafe ptrs can always be NULL } - ty_rec(fields) { + ty_rec(fields) => { do vec::any(fields) |field| { type_requires(cx, seen, r_ty, field.mt.ty) } } - ty_trait(_, _) { + ty_trait(_, _) => { false } - ty_class(did, _) if vec::contains(*seen, did) { + ty_class(did, _) if vec::contains(*seen, did) => { false } - ty_class(did, substs) { + ty_class(did, substs) => { vec::push(*seen, did); let r = vec::any(class_items_as_fields(cx, did, substs), |f| type_requires(cx, seen, r_ty, f.mt.ty)); @@ -1882,15 +1880,15 @@ fn is_instantiable(cx: ctxt, r_ty: t) -> bool { r } - ty_tup(ts) { + ty_tup(ts) => { vec::any(ts, |t| type_requires(cx, seen, r_ty, t)) } - ty_enum(did, _) if vec::contains(*seen, did) { + ty_enum(did, _) if vec::contains(*seen, did) => { false } - ty_enum(did, substs) { + ty_enum(did, substs) => { vec::push(*seen, did); let vs = enum_variants(cx, did); let r = vec::len(*vs) > 0u && vec::all(*vs, |variant| { @@ -1922,7 +1920,7 @@ fn type_structurally_contains(cx: ctxt, ty: t, test: fn(sty) -> bool) -> debug!{"type_structurally_contains: %s", ty_to_str(cx, ty)}; if test(sty) { return true; } alt sty { - ty_enum(did, substs) { + ty_enum(did, substs) => { for vec::each(*enum_variants(cx, did)) |variant| { for variant.args.each |aty| { let sty = subst(cx, substs, aty); @@ -1931,7 +1929,7 @@ fn type_structurally_contains(cx: ctxt, ty: t, test: fn(sty) -> bool) -> } return false; } - ty_rec(fields) { + ty_rec(fields) => { for fields.each |field| { if type_structurally_contains(cx, field.mt.ty, test) { return true; @@ -1939,7 +1937,7 @@ fn type_structurally_contains(cx: ctxt, ty: t, test: fn(sty) -> bool) -> } return false; } - ty_class(did, substs) { + ty_class(did, substs) => { for lookup_class_fields(cx, did).each |field| { let ft = lookup_field_type(cx, did, field.id, substs); if type_structurally_contains(cx, ft, test) { return true; } @@ -1947,16 +1945,16 @@ fn type_structurally_contains(cx: ctxt, ty: t, test: fn(sty) -> bool) -> return false; } - ty_tup(ts) { + ty_tup(ts) => { for ts.each |tt| { if type_structurally_contains(cx, tt, test) { return true; } } return false; } - ty_evec(mt, vstore_fixed(_)) { + ty_evec(mt, vstore_fixed(_)) => { return type_structurally_contains(cx, mt.ty, test); } - _ { return false; } + _ => return false } } @@ -1965,23 +1963,23 @@ fn type_structurally_contains_uniques(cx: ctxt, ty: t) -> bool { alt sty { ty_uniq(_) | ty_evec(_, vstore_uniq) | - ty_estr(vstore_uniq) { true } - _ { false } + ty_estr(vstore_uniq) => true, + _ => false, } }); } fn type_is_integral(ty: t) -> bool { alt get(ty).struct { - ty_var_integral(_) | ty_int(_) | ty_uint(_) | ty_bool { true } - _ { false } + ty_var_integral(_) | ty_int(_) | ty_uint(_) | ty_bool => true, + _ => false } } fn type_is_fp(ty: t) -> bool { alt get(ty).struct { - ty_float(_) { true } - _ { false } + ty_float(_) => true, + _ => false } } @@ -1991,8 +1989,8 @@ fn type_is_numeric(ty: t) -> bool { fn type_is_signed(ty: t) -> bool { alt get(ty).struct { - ty_int(_) { true } - _ { false } + ty_int(_) => true, + _ => false } } @@ -2003,14 +2001,14 @@ fn type_is_pod(cx: ctxt, ty: t) -> bool { alt get(ty).struct { // Scalar types ty_nil | ty_bot | ty_bool | ty_int(_) | ty_float(_) | ty_uint(_) | - ty_type | ty_ptr(_) { result = true; } + ty_type | ty_ptr(_) => result = true, // Boxed types ty_box(_) | ty_uniq(_) | ty_fn(_) | ty_estr(vstore_uniq) | ty_estr(vstore_box) | ty_evec(_, vstore_uniq) | ty_evec(_, vstore_box) | - ty_trait(_, _) | ty_rptr(_,_) | ty_opaque_box { result = false; } + ty_trait(_, _) | ty_rptr(_,_) | ty_opaque_box => result = false, // Structural types - ty_enum(did, substs) { + ty_enum(did, substs) => { let variants = enum_variants(cx, did); for vec::each(*variants) |variant| { let tup_ty = mk_tup(cx, variant.args); @@ -2020,21 +2018,21 @@ fn type_is_pod(cx: ctxt, ty: t) -> bool { if !type_is_pod(cx, tup_ty) { result = false; } } } - ty_rec(flds) { + ty_rec(flds) => { for flds.each |f| { if !type_is_pod(cx, f.mt.ty) { result = false; } } } - ty_tup(elts) { + ty_tup(elts) => { for elts.each |elt| { if !type_is_pod(cx, elt) { result = false; } } } - ty_estr(vstore_fixed(_)) { result = true; } - ty_evec(mt, vstore_fixed(_)) | ty_unboxed_vec(mt) { + ty_estr(vstore_fixed(_)) => result = true, + ty_evec(mt, vstore_fixed(_)) | ty_unboxed_vec(mt) => { result = type_is_pod(cx, mt.ty); } - ty_param(_) { result = false; } - ty_opaque_closure_ptr(_) { result = true; } - ty_class(did, substs) { + ty_param(_) => result = false, + ty_opaque_closure_ptr(_) => result = true, + ty_class(did, substs) => { result = vec::any(lookup_class_fields(cx, did), |f| { let fty = ty::lookup_item_type(cx, f.id); let sty = subst(cx, substs, fty.ty); @@ -2042,11 +2040,11 @@ fn type_is_pod(cx: ctxt, ty: t) -> bool { }); } - ty_estr(vstore_slice(*)) | ty_evec(_, vstore_slice(*)) { + ty_estr(vstore_slice(*)) | ty_evec(_, vstore_slice(*)) => { result = false; } - ty_var(*) | ty_var_integral(*) | ty_self(*) { + ty_var(*) | ty_var_integral(*) | ty_self(*) => { cx.sess.bug(~"non concrete type in type_is_pod"); } } @@ -2056,8 +2054,8 @@ fn type_is_pod(cx: ctxt, ty: t) -> bool { fn type_is_enum(ty: t) -> bool { alt get(ty).struct { - ty_enum(_, _) { return true; } - _ { return false;} + ty_enum(_, _) => return true, + _ => return false } } @@ -2065,19 +2063,19 @@ fn type_is_enum(ty: t) -> bool { // constructors fn type_is_c_like_enum(cx: ctxt, ty: t) -> bool { alt get(ty).struct { - ty_enum(did, substs) { + ty_enum(did, substs) => { let variants = enum_variants(cx, did); let some_n_ary = vec::any(*variants, |v| vec::len(v.args) > 0u); return !some_n_ary; } - _ { return false;} + _ => return false } } fn type_param(ty: t) -> option<uint> { alt get(ty).struct { - ty_param(p) { return some(p.idx); } - _ {/* fall through */ } + ty_param(p) => return some(p.idx), + _ => {/* fall through */ } } return none; } @@ -2091,15 +2089,15 @@ fn deref(cx: ctxt, t: t, expl: bool) -> option<mt> { } fn deref_sty(cx: ctxt, sty: sty, expl: bool) -> option<mt> { alt sty { - ty_rptr(_, mt) | ty_box(mt) | ty_uniq(mt) { + ty_rptr(_, mt) | ty_box(mt) | ty_uniq(mt) => { some(mt) } - ty_ptr(mt) if expl { + ty_ptr(mt) if expl => { some(mt) } - ty_enum(did, substs) { + ty_enum(did, substs) => { let variants = enum_variants(cx, did); if vec::len(*variants) == 1u && vec::len(variants[0].args) == 1u { let v_t = subst(cx, substs, variants[0].args[0]); @@ -2109,7 +2107,7 @@ fn deref_sty(cx: ctxt, sty: sty, expl: bool) -> option<mt> { } } - _ { none } + _ => none } } @@ -2117,8 +2115,8 @@ fn type_autoderef(cx: ctxt, t: t) -> t { let mut t = t; loop { alt deref(cx, t, false) { - none { return t; } - some(mt) { t = mt.ty; } + none => return t, + some(mt) => t = mt.ty } } } @@ -2130,18 +2128,18 @@ fn index(cx: ctxt, t: t) -> option<mt> { fn index_sty(cx: ctxt, sty: sty) -> option<mt> { alt sty { - ty_evec(mt, _) { some(mt) } - ty_estr(_) { some({ty: mk_u8(cx), mutbl: ast::m_imm}) } - _ { none } + ty_evec(mt, _) => some(mt), + ty_estr(_) => some({ty: mk_u8(cx), mutbl: ast::m_imm}), + _ => none } } pure fn hash_bound_region(br: &bound_region) -> uint { alt *br { // no idea if this is any good - ty::br_self { 0u } - ty::br_anon { 1u } - ty::br_named(str) { str::hash(str) } - ty::br_cap_avoid(id, br) { id as uint | hash_bound_region(br) } + ty::br_self => 0u, + ty::br_anon => 1u, + ty::br_named(str) => str::hash(str), + ty::br_cap_avoid(id, br) => id as uint | hash_bound_region(br) } } @@ -2166,12 +2164,12 @@ pure fn hash_type_structure(st: sty) -> uint { } pure fn hash_region(r: ®ion) -> uint { alt *r { // no idea if this is any good - re_bound(br) { (hash_bound_region(&br)) << 2u | 0u } - re_free(id, br) { ((id as uint) << 4u) | - (hash_bound_region(&br)) << 2u | 1u } - re_scope(id) { ((id as uint) << 2u) | 2u } - re_var(id) { (id.to_uint() << 2u) | 3u } - re_bot { 4u } + re_bound(br) => (hash_bound_region(&br)) << 2u | 0u, + re_free(id, br) => ((id as uint) << 4u) | + (hash_bound_region(&br)) << 2u | 1u, + re_scope(id) => ((id as uint) << 2u) | 2u, + re_var(id) => (id.to_uint() << 2u) | 3u, + re_bot => 4u } } pure fn hash_substs(h: uint, substs: substs) -> uint { @@ -2179,62 +2177,68 @@ pure fn hash_type_structure(st: sty) -> uint { h + substs.self_r.map_default(0u, |r| hash_region(&r)) } alt st { - ty_nil { 0u } ty_bool { 1u } - ty_int(t) { - alt t { - ast::ty_i { 2u } ast::ty_char { 3u } ast::ty_i8 { 4u } - ast::ty_i16 { 5u } ast::ty_i32 { 6u } ast::ty_i64 { 7u } - } - } - ty_uint(t) { - alt t { - ast::ty_u { 8u } ast::ty_u8 { 9u } ast::ty_u16 { 10u } - ast::ty_u32 { 11u } ast::ty_u64 { 12u } - } - } - ty_float(t) { - alt t { ast::ty_f { 13u } ast::ty_f32 { 14u } ast::ty_f64 { 15u } } - } - ty_estr(_) { 16u } - ty_enum(did, substs) { + ty_nil => 0u, + ty_bool => 1u, + ty_int(t) => alt t { + ast::ty_i => 2u, + ast::ty_char => 3u, + ast::ty_i8 => 4u, + ast::ty_i16 => 5u, + ast::ty_i32 => 6u, + ast::ty_i64 => 7u + } + ty_uint(t) => alt t { + ast::ty_u => 8u, + ast::ty_u8 => 9u, + ast::ty_u16 => 10u, + ast::ty_u32 => 11u, + ast::ty_u64 => 12u + } + ty_float(t) => alt t { + ast::ty_f => 13u, + ast::ty_f32 => 14u, + ast::ty_f64 => 15u + } + ty_estr(_) => 16u, + ty_enum(did, substs) => { let mut h = hash_def(18u, did); hash_substs(h, substs) } - ty_box(mt) { hash_subty(19u, mt.ty) } - ty_evec(mt, _) { hash_subty(20u, mt.ty) } - ty_unboxed_vec(mt) { hash_subty(22u, mt.ty) } - ty_tup(ts) { hash_subtys(25u, ts) } - ty_rec(fields) { + ty_box(mt) => hash_subty(19u, mt.ty), + ty_evec(mt, _) => hash_subty(20u, mt.ty), + ty_unboxed_vec(mt) => hash_subty(22u, mt.ty), + ty_tup(ts) => hash_subtys(25u, ts), + ty_rec(fields) => { let mut h = 26u; for vec::each(fields) |f| { h = hash_subty(h, f.mt.ty); } h } - ty_fn(f) { + ty_fn(f) => { let mut h = 27u; for vec::each(f.inputs) |a| { h = hash_subty(h, a.ty); } hash_subty(h, f.output) } - ty_self { 28u } - ty_var(v) { hash_uint(29u, v.to_uint()) } - ty_var_integral(v) { hash_uint(30u, v.to_uint()) } - ty_param(p) { hash_def(hash_uint(31u, p.idx), p.def_id) } - ty_type { 32u } - ty_bot { 34u } - ty_ptr(mt) { hash_subty(35u, mt.ty) } - ty_uniq(mt) { hash_subty(37u, mt.ty) } - ty_trait(did, substs) { + ty_self => 28u, + ty_var(v) => hash_uint(29u, v.to_uint()), + ty_var_integral(v) => hash_uint(30u, v.to_uint()), + ty_param(p) => hash_def(hash_uint(31u, p.idx), p.def_id), + ty_type => 32u, + ty_bot => 34u, + ty_ptr(mt) => hash_subty(35u, mt.ty), + ty_uniq(mt) => hash_subty(37u, mt.ty), + ty_trait(did, substs) => { let mut h = hash_def(40u, did); hash_substs(h, substs) } - ty_opaque_closure_ptr(ck_block) { 41u } - ty_opaque_closure_ptr(ck_box) { 42u } - ty_opaque_closure_ptr(ck_uniq) { 43u } - ty_opaque_box { 44u } - ty_class(did, substs) { + ty_opaque_closure_ptr(ck_block) => 41u, + ty_opaque_closure_ptr(ck_box) => 42u, + ty_opaque_closure_ptr(ck_uniq) => 43u, + ty_opaque_box => 44u, + ty_class(did, substs) => { let mut h = hash_def(45u, did); hash_substs(h, substs) } - ty_rptr(region, mt) { + ty_rptr(region, mt) => { let mut h = (46u << 2u) + hash_region(®ion); hash_subty(h, mt.ty) } @@ -2243,16 +2247,16 @@ pure fn hash_type_structure(st: sty) -> uint { fn node_id_to_type(cx: ctxt, id: ast::node_id) -> t { alt smallintmap::find(*cx.node_types, id as uint) { - some(t) { t } - none { cx.sess.bug(fmt!{"node_id_to_type: unbound node ID %s", - ast_map::node_id_to_str(cx.items, id)}); } + some(t) => t, + none => cx.sess.bug(fmt!{"node_id_to_type: unbound node ID %s", + ast_map::node_id_to_str(cx.items, id)}) } } fn node_id_to_type_params(cx: ctxt, id: ast::node_id) -> ~[t] { alt cx.node_type_substs.find(id) { - none { return ~[]; } - some(ts) { return ts; } + none => return ~[], + some(ts) => return ts } } @@ -2263,36 +2267,36 @@ fn node_id_has_type_params(cx: ctxt, id: ast::node_id) -> bool { // Type accessors for substructures of types fn ty_fn_args(fty: t) -> ~[arg] { alt get(fty).struct { - ty_fn(f) { f.inputs } - _ { fail ~"ty_fn_args() called on non-fn type"; } + ty_fn(f) => f.inputs, + _ => fail ~"ty_fn_args() called on non-fn type" } } fn ty_fn_proto(fty: t) -> ast::proto { alt get(fty).struct { - ty_fn(f) { f.proto } - _ { fail ~"ty_fn_proto() called on non-fn type"; } + ty_fn(f) => f.proto, + _ => fail ~"ty_fn_proto() called on non-fn type" } } pure fn ty_fn_ret(fty: t) -> t { alt get(fty).struct { - ty_fn(f) { f.output } - _ { fail ~"ty_fn_ret() called on non-fn type"; } + ty_fn(f) => f.output, + _ => fail ~"ty_fn_ret() called on non-fn type" } } fn ty_fn_ret_style(fty: t) -> ast::ret_style { alt get(fty).struct { - ty_fn(f) { f.ret_style } - _ { fail ~"ty_fn_ret_style() called on non-fn type"; } + ty_fn(f) => f.ret_style, + _ => fail ~"ty_fn_ret_style() called on non-fn type" } } fn is_fn_ty(fty: t) -> bool { alt get(fty).struct { - ty_fn(_) { return true; } - _ { return false; } + ty_fn(_) => return true, + _ => return false } } @@ -2309,15 +2313,15 @@ fn is_pred_ty(fty: t) -> bool { fn ty_var_id(typ: t) -> tv_vid { alt get(typ).struct { - ty_var(vid) { return vid; } - _ { error!{"ty_var_id called on non-var ty"}; fail; } + ty_var(vid) => return vid, + _ => { error!{"ty_var_id called on non-var ty"}; fail; } } } fn ty_var_integral_id(typ: t) -> tvi_vid { alt get(typ).struct { - ty_var_integral(vid) { return vid; } - _ { error!{"ty_var_integral_id called on ty other than \ + ty_var_integral(vid) => return vid, + _ => { error!{"ty_var_integral_id called on ty other than \ ty_var_integral"}; fail; } } @@ -2358,17 +2362,17 @@ fn expr_has_ty_params(cx: ctxt, expr: @ast::expr) -> bool { fn expr_is_lval(method_map: typeck::method_map, e: @ast::expr) -> bool { alt e.node { - ast::expr_path(_) | ast::expr_unary(ast::deref, _) { true } - ast::expr_field(_, _, _) | ast::expr_index(_, _) { + ast::expr_path(_) | ast::expr_unary(ast::deref, _) => true, + ast::expr_field(_, _, _) | ast::expr_index(_, _) => { !method_map.contains_key(e.id) } - _ { false } + _ => false } } fn stmt_node_id(s: @ast::stmt) -> ast::node_id { alt s.node { - ast::stmt_decl(_, id) | stmt_expr(_, id) | stmt_semi(_, id) { + ast::stmt_decl(_, id) | stmt_expr(_, id) | stmt_semi(_, id) => { return id; } } @@ -2382,13 +2386,13 @@ fn field_idx(id: ast::ident, fields: ~[field]) -> option<uint> { fn get_field(rec_ty: t, id: ast::ident) -> field { alt check vec::find(get_fields(rec_ty), |f| str::eq(f.ident, id)) { - some(f) { f } + some(f) => f } } fn get_fields(rec_ty:t) -> ~[field] { alt check get(rec_ty).struct { - ty_rec(fields) { fields } + ty_rec(fields) => fields } } @@ -2405,10 +2409,10 @@ fn param_tys_in_type(ty: t) -> ~[param_ty] { let mut rslt = ~[]; do walk_ty(ty) |ty| { alt get(ty).struct { - ty_param(p) { + ty_param(p) => { vec::push(rslt, p); } - _ { } + _ => () } } rslt @@ -2421,7 +2425,10 @@ fn occurs_check(tcx: ctxt, sp: span, vid: tv_vid, rt: t) { fn vars_in_type(ty: t) -> ~[tv_vid] { let mut rslt = ~[]; do walk_ty(ty) |ty| { - alt get(ty).struct { ty_var(v) { vec::push(rslt, v); } _ { } } + alt get(ty).struct { + ty_var(v) => vec::push(rslt, v), + _ => () + } } rslt } @@ -2448,18 +2455,16 @@ fn occurs_check(tcx: ctxt, sp: span, vid: tv_vid, rt: t) { fn canon<T:copy>(tbl: hashmap<ast::node_id, ast::inferable<T>>, m0: ast::inferable<T>) -> ast::inferable<T> { alt m0 { - ast::infer(id) { - alt tbl.find(id) { - none { m0 } - some(m1) { + ast::infer(id) => alt tbl.find(id) { + none => m0, + some(m1) => { let cm1 = canon(tbl, m1); // path compression: if cm1 != m1 { tbl.insert(id, cm1); } cm1 - } } } - _ { m0 } + _ => m0 } } @@ -2473,10 +2478,10 @@ fn canon_mode(cx: ctxt, m0: ast::mode) -> ast::mode { // was never inferred. This should be safe for use after typeck. fn resolved_mode(cx: ctxt, m: ast::mode) -> ast::rmode { alt canon_mode(cx, m) { - ast::infer(_) { + ast::infer(_) => { cx.sess.bug(fmt!{"mode %? was never resolved", m}); } - ast::expl(m0) { m0 } + ast::expl(m0) => m0 } } @@ -2486,18 +2491,18 @@ fn arg_mode(cx: ctxt, a: arg) -> ast::rmode { resolved_mode(cx, a.mode) } fn unify_mode(cx: ctxt, m1: ast::mode, m2: ast::mode) -> result<ast::mode, type_err> { alt (canon_mode(cx, m1), canon_mode(cx, m2)) { - (m1, m2) if (m1 == m2) { + (m1, m2) if (m1 == m2) => { result::ok(m1) } - (ast::infer(id1), ast::infer(id2)) { + (ast::infer(id1), ast::infer(id2)) => { cx.inferred_modes.insert(id2, m1); result::ok(m1) } - (ast::infer(id), m) | (m, ast::infer(id)) { + (ast::infer(id), m) | (m, ast::infer(id)) => { cx.inferred_modes.insert(id, m); result::ok(m1) } - (m1, m2) { + (m1, m2) => { result::err(terr_mode_mismatch(m1, m2)) } } @@ -2507,10 +2512,10 @@ fn unify_mode(cx: ctxt, m1: ast::mode, m2: ast::mode) // for `m`. fn set_default_mode(cx: ctxt, m: ast::mode, m_def: ast::rmode) { alt canon_mode(cx, m) { - ast::infer(id) { + ast::infer(id) => { cx.inferred_modes.insert(id, ast::expl(m_def)); } - ast::expl(_) { } + ast::expl(_) => () } } @@ -2518,107 +2523,107 @@ fn ty_sort_str(cx: ctxt, t: t) -> ~str { alt get(t).struct { ty_nil | ty_bot | ty_bool | ty_int(_) | ty_uint(_) | ty_float(_) | ty_estr(_) | - ty_type | ty_opaque_box | ty_opaque_closure_ptr(_) { + ty_type | ty_opaque_box | ty_opaque_closure_ptr(_) => { ty_to_str(cx, t) } - ty_enum(id, _) { fmt!{"enum %s", item_path_str(cx, id)} } - ty_box(_) { ~"@-ptr" } - ty_uniq(_) { ~"~-ptr" } - ty_evec(_, _) { ~"vector" } - ty_unboxed_vec(_) { ~"unboxed vector" } - ty_ptr(_) { ~"*-ptr" } - ty_rptr(_, _) { ~"&-ptr" } - ty_rec(_) { ~"record" } - ty_fn(_) { ~"fn" } - ty_trait(id, _) { fmt!{"trait %s", item_path_str(cx, id)} } - ty_class(id, _) { fmt!{"class %s", item_path_str(cx, id)} } - ty_tup(_) { ~"tuple" } - ty_var(_) { ~"variable" } - ty_var_integral(_) { ~"integral variable" } - ty_param(_) { ~"type parameter" } - ty_self { ~"self" } + ty_enum(id, _) => fmt!{"enum %s", item_path_str(cx, id)}, + ty_box(_) => ~"@-ptr", + ty_uniq(_) => ~"~-ptr", + ty_evec(_, _) => ~"vector", + ty_unboxed_vec(_) => ~"unboxed vector", + ty_ptr(_) => ~"*-ptr", + ty_rptr(_, _) => ~"&-ptr", + ty_rec(_) => ~"record", + ty_fn(_) => ~"fn", + ty_trait(id, _) => fmt!{"trait %s", item_path_str(cx, id)}, + ty_class(id, _) => fmt!{"class %s", item_path_str(cx, id)}, + ty_tup(_) => ~"tuple", + ty_var(_) => ~"variable", + ty_var_integral(_) => ~"integral variable", + ty_param(_) => ~"type parameter", + ty_self => ~"self" } } fn type_err_to_str(cx: ctxt, err: type_err) -> ~str { fn terr_vstore_kind_to_str(k: terr_vstore_kind) -> ~str { - alt k { terr_vec { ~"[]" } terr_str { ~"str" } } + alt k { terr_vec => ~"[]", terr_str => ~"str" } } alt err { - terr_mismatch { return ~"types differ"; } - terr_ret_style_mismatch(expect, actual) { + terr_mismatch => return ~"types differ", + terr_ret_style_mismatch(expect, actual) => { fn to_str(s: ast::ret_style) -> ~str { alt s { - ast::noreturn { ~"non-returning" } - ast::return_val { ~"return-by-value" } + ast::noreturn => ~"non-returning", + ast::return_val => ~"return-by-value" } } return to_str(actual) + ~" function found where " + to_str(expect) + ~" function was expected"; } - terr_purity_mismatch(f1, f2) { + terr_purity_mismatch(f1, f2) => { return fmt!{"expected %s fn but found %s fn", purity_to_str(f1), purity_to_str(f2)}; } - terr_proto_mismatch(e, a) { + terr_proto_mismatch(e, a) => { return fmt!{"closure protocol mismatch (%s vs %s)", proto_to_str(e), proto_to_str(a)}; } - terr_mutability { return ~"values differ in mutability"; } - terr_box_mutability { return ~"boxed values differ in mutability"; } - terr_vec_mutability { return ~"vectors differ in mutability"; } - terr_ptr_mutability { return ~"pointers differ in mutability"; } - terr_ref_mutability { return ~"references differ in mutability"; } - terr_ty_param_size(e_sz, a_sz) { + terr_mutability => return ~"values differ in mutability", + terr_box_mutability => return ~"boxed values differ in mutability", + terr_vec_mutability => return ~"vectors differ in mutability", + terr_ptr_mutability => return ~"pointers differ in mutability", + terr_ref_mutability => return ~"references differ in mutability", + terr_ty_param_size(e_sz, a_sz) => { return ~"expected a type with " + uint::to_str(e_sz, 10u) + ~" type params but found one with " + uint::to_str(a_sz, 10u) + ~" type params"; } - terr_tuple_size(e_sz, a_sz) { + terr_tuple_size(e_sz, a_sz) => { return ~"expected a tuple with " + uint::to_str(e_sz, 10u) + ~" elements but found one with " + uint::to_str(a_sz, 10u) + ~" elements"; } - terr_record_size(e_sz, a_sz) { + terr_record_size(e_sz, a_sz) => { return ~"expected a record with " + uint::to_str(e_sz, 10u) + ~" fields but found one with " + uint::to_str(a_sz, 10u) + ~" fields"; } - terr_record_mutability { + terr_record_mutability => { return ~"record elements differ in mutability"; } - terr_record_fields(e_fld, a_fld) { + terr_record_fields(e_fld, a_fld) => { return ~"expected a record with field `" + *e_fld + ~"` but found one with field `" + *a_fld + ~"`"; } - terr_arg_count { return ~"incorrect number of function parameters"; } - terr_mode_mismatch(e_mode, a_mode) { + terr_arg_count => return ~"incorrect number of function parameters", + terr_mode_mismatch(e_mode, a_mode) => { return ~"expected argument mode " + mode_to_str(e_mode) + ~" but found " + mode_to_str(a_mode); } - terr_regions_differ(subregion, superregion) { + terr_regions_differ(subregion, superregion) => { return fmt!{"%s does not necessarily outlive %s", explain_region(cx, subregion), explain_region(cx, superregion)}; } - terr_vstores_differ(k, e_vs, a_vs) { + terr_vstores_differ(k, e_vs, a_vs) => { return fmt!{"%s storage differs: expected %s but found %s", terr_vstore_kind_to_str(k), vstore_to_str(cx, e_vs), vstore_to_str(cx, a_vs)}; } - terr_in_field(err, fname) { + terr_in_field(err, fname) => { return fmt!{"in field `%s`, %s", *fname, type_err_to_str(cx, *err)}; } - terr_sorts(exp, act) { + terr_sorts(exp, act) => { return fmt!{"%s vs %s", ty_sort_str(cx, exp), ty_sort_str(cx, act)}; } - terr_self_substs { + terr_self_substs => { return ~"inconsistent self substitution"; // XXX this is more of a bug } - terr_no_integral_type { + terr_no_integral_type => { return ~"couldn't determine an appropriate integral type for integer \ literal"; } @@ -2628,8 +2633,8 @@ fn type_err_to_str(cx: ctxt, err: type_err) -> ~str { fn def_has_ty_params(def: ast::def) -> bool { alt def { ast::def_fn(_, _) | ast::def_variant(_, _) | ast::def_class(_, _) - { true } - _ { false } + => true, + _ => false } } @@ -2639,8 +2644,8 @@ fn store_trait_methods(cx: ctxt, id: ast::node_id, ms: @~[method]) { fn trait_methods(cx: ctxt, id: ast::def_id) -> @~[method] { alt cx.trait_method_cache.find(id) { - some(ms) { return ms; } - _ {} + some(ms) => return ms, + _ => () } // Local traits are supposed to have been added explicitly. assert id.crate != ast::local_crate; @@ -2656,30 +2661,30 @@ fn impl_traits(cx: ctxt, id: ast::def_id) -> ~[t] { some(ast_map::node_item(@{ node: ast::item_impl(_, trait_refs, _, _), _}, - _)) { + _)) => { do vec::map(trait_refs) |trait_ref| { node_id_to_type(cx, trait_ref.ref_id) } } some(ast_map::node_item(@{node: ast::item_class(*), - _},_)) { + _},_)) => { alt cx.def_map.find(id.node) { - some(def_ty(trait_id)) { + some(def_ty(trait_id)) => { // XXX: Doesn't work cross-crate. debug!{"(impl_traits) found trait id %?", trait_id}; ~[node_id_to_type(cx, trait_id.node)] } - some(x) { + some(x) => { cx.sess.bug(fmt!{"impl_traits: trait ref is in trait map \ but is bound to %?", x}); } - none { + none => { ~[] } } } - _ { ~[] } + _ => ~[] } } else { csearch::get_impl_traits(cx, id) @@ -2688,10 +2693,8 @@ fn impl_traits(cx: ctxt, id: ast::def_id) -> ~[t] { fn ty_to_def_id(ty: t) -> option<ast::def_id> { alt get(ty).struct { - ty_trait(id, _) | ty_class(id, _) | ty_enum(id, _) { - some(id) - } - _ { none } + ty_trait(id, _) | ty_class(id, _) | ty_enum(id, _) => some(id), + _ => none } } @@ -2723,8 +2726,8 @@ fn ty_dtor(cx: ctxt, class_id: def_id) -> option<def_id> { alt cx.items.find(class_id.node) { some(ast_map::node_item(@{node: ast::item_class(_, _, _, _, some(dtor)), _}, _)) - { some(local_def(dtor.node.id)) } - _ { none } + => some(local_def(dtor.node.id)), + _ => none } } else { @@ -2742,46 +2745,46 @@ fn item_path(cx: ctxt, id: ast::def_id) -> ast_map::path { } else { let node = cx.items.get(id.node); alt node { - ast_map::node_item(item, path) { + ast_map::node_item(item, path) => { let item_elt = alt item.node { - item_mod(_) | item_foreign_mod(_) { + item_mod(_) | item_foreign_mod(_) => { ast_map::path_mod(item.ident) } - _ { + _ => { ast_map::path_name(item.ident) } }; vec::append_one(*path, item_elt) } - ast_map::node_foreign_item(nitem, _, path) { + ast_map::node_foreign_item(nitem, _, path) => { vec::append_one(*path, ast_map::path_name(nitem.ident)) } - ast_map::node_method(method, _, path) { + ast_map::node_method(method, _, path) => { vec::append_one(*path, ast_map::path_name(method.ident)) } - ast_map::node_trait_method(trait_method, _, path) { + ast_map::node_trait_method(trait_method, _, path) => { let method = ast_util::trait_method_to_ty_method(*trait_method); vec::append_one(*path, ast_map::path_name(method.ident)) } - ast_map::node_variant(variant, _, path) { + ast_map::node_variant(variant, _, path) => { vec::append_one(vec::init(*path), ast_map::path_name(variant.node.name)) } - ast_map::node_ctor(nm, _, _, _, path) { + ast_map::node_ctor(nm, _, _, _, path) => { vec::append_one(*path, ast_map::path_name(nm)) } - ast_map::node_dtor(_, _, _, path) { + ast_map::node_dtor(_, _, _, path) => { vec::append_one(*path, ast_map::path_name(@~"dtor")) } ast_map::node_expr(_) | ast_map::node_arg(_, _) | ast_map::node_local(_) | ast_map::node_export(_, _) | - ast_map::node_block(_) { + ast_map::node_block(_) => { cx.sess.bug(fmt!{"cannot find item_path for node %?", node}); } } @@ -2794,17 +2797,15 @@ fn enum_is_univariant(cx: ctxt, id: ast::def_id) -> bool { fn type_is_empty(cx: ctxt, t: t) -> bool { alt ty::get(t).struct { - ty_enum(did, _) { - (*enum_variants(cx, did)).is_empty() - } - _ { false } + ty_enum(did, _) => (*enum_variants(cx, did)).is_empty(), + _ => false } } fn enum_variants(cx: ctxt, id: ast::def_id) -> @~[variant_info] { alt cx.enum_var_cache.find(id) { - some(variants) { return variants; } - _ { /* fallthrough */ } + some(variants) => return variants, + _ => { /* fallthrough */ } } let result = if ast::local_crate != id.crate { @@ -2816,7 +2817,7 @@ fn enum_variants(cx: ctxt, id: ast::def_id) -> @~[variant_info] { expr, since check_enum_variants also updates the enum_var_cache */ alt cx.items.get(id.node) { - ast_map::node_item(@{node: ast::item_enum(variants, _), _}, _) { + ast_map::node_item(@{node: ast::item_enum(variants, _), _}, _) => { let mut disr_val = -1; @vec::map(variants, |variant| { let ctor_ty = node_id_to_type(cx, variant.node.id); @@ -2826,14 +2827,14 @@ fn enum_variants(cx: ctxt, id: ast::def_id) -> @~[variant_info] { } else { ~[] } }; alt variant.node.disr_expr { - some (ex) { + some (ex) => { // FIXME: issue #1417 disr_val = alt const_eval::eval_const_expr(cx, ex) { - const_eval::const_int(val) {val as int} - _ { cx.sess.bug(~"tag_variants: bad disr expr"); } + const_eval::const_int(val) =>val as int, + _ => cx.sess.bug(~"tag_variants: bad disr expr") } } - _ {disr_val += 1;} + _ => disr_val += 1 } @{args: arg_tys, ctor_ty: ctor_ty, @@ -2843,7 +2844,7 @@ fn enum_variants(cx: ctxt, id: ast::def_id) -> @~[variant_info] { } }) } - _ { cx.sess.bug(~"tag_variants: id not bound to an enum"); } + _ => cx.sess.bug(~"tag_variants: id not bound to an enum") } }; cx.enum_var_cache.insert(id, result); @@ -2869,8 +2870,8 @@ fn enum_variant_with_id(cx: ctxt, enum_id: ast::def_id, // the type cache. Returns the type parameters and type. fn lookup_item_type(cx: ctxt, did: ast::def_id) -> ty_param_bounds_and_ty { alt cx.tcache.find(did) { - some(tpt) { return tpt; } - none { + some(tpt) => return tpt, + none => { // The item is in this crate. The caller should have added it to the // type cache already assert did.crate != ast::local_crate; @@ -2891,8 +2892,8 @@ fn lookup_field_type(tcx: ctxt, class_id: def_id, id: def_id, } else { alt tcx.tcache.find(id) { - some(tpt) { tpt.ty } - none { + some(tpt) => tpt.ty, + none => { let tpt = csearch::get_field_type(tcx, class_id, id); tcx.tcache.insert(id, tpt); tpt.ty @@ -2907,15 +2908,15 @@ fn lookup_field_type(tcx: ctxt, class_id: def_id, id: def_id, fn lookup_class_fields(cx: ctxt, did: ast::def_id) -> ~[field_ty] { if did.crate == ast::local_crate { alt cx.items.find(did.node) { - some(ast_map::node_item(i,_)) { + some(ast_map::node_item(i,_)) => { alt i.node { - ast::item_class(_, _, items, _, _) { + ast::item_class(_, _, items, _, _) => { class_field_tys(items) } - _ { cx.sess.bug(~"class ID bound to non-class"); } + _ => cx.sess.bug(~"class ID bound to non-class") } } - _ { + _ => { cx.sess.bug(fmt!{"class ID not bound to an item: %s", ast_map::node_id_to_str(cx.items, did.node)}); } @@ -2930,8 +2931,8 @@ fn lookup_class_field(cx: ctxt, parent: ast::def_id, field_id: ast::def_id) -> field_ty { alt vec::find(lookup_class_fields(cx, parent), |f| f.id.node == field_id.node) { - some(t) { t } - none { cx.sess.bug(~"class ID not found in parent's fields"); } + some(t) => t, + none => cx.sess.bug(~"class ID not found in parent's fields") } } @@ -2962,12 +2963,14 @@ fn lookup_class_method_by_name(cx:ctxt, did: ast::def_id, name: ident, assert is_local(did); alt cx.items.find(did.node) { - some(ast_map::node_item(@{node: item_class(_,_,items,_,_), _}, _)) { + some(ast_map::node_item(@{ + node: item_class(_,_,items,_,_), _ + }, _)) => { let (_,ms) = split_class_items(items); vec::map(ms, |m| {name: m.ident, id: m.id, vis: m.vis}) } - _ { + _ => { cx.sess.bug(~"lookup_class_method_ids: id not bound to a class"); } } @@ -2992,11 +2995,11 @@ fn class_field_tys(items: ~[@class_member]) -> ~[field_ty] { let mut rslt = ~[]; for items.each |it| { alt it.node { - instance_var(nm, _, cm, id, vis) { + instance_var(nm, _, cm, id, vis) => { vec::push(rslt, {ident: nm, id: ast_util::local_def(id), vis: vis, mutability: cm}); } - class_method(_) { } + class_method(_) => () } } rslt @@ -3018,8 +3021,8 @@ fn class_items_as_mutable_fields(cx:ctxt, did: ast::def_id, fn class_items_as_fields(cx:ctxt, did: ast::def_id, substs: substs) -> ~[field] { class_item_fields(cx, did, substs, |mt| alt mt { - class_mutable { m_mutbl } - class_immutable { m_imm }}) + class_mutable => m_mutbl, + class_immutable => m_imm }) } @@ -3056,35 +3059,35 @@ fn is_binopable(_cx: ctxt, ty: t, op: ast::binop) -> bool { fn opcat(op: ast::binop) -> int { alt op { - ast::add { opcat_add } - ast::subtract { opcat_sub } - ast::mul { opcat_mult } - ast::div { opcat_mult } - ast::rem { opcat_mult } - ast::and { opcat_logic } - ast::or { opcat_logic } - ast::bitxor { opcat_bit } - ast::bitand { opcat_bit } - ast::bitor { opcat_bit } - ast::shl { opcat_shift } - ast::shr { opcat_shift } - ast::eq { opcat_eq } - ast::ne { opcat_eq } - ast::lt { opcat_rel } - ast::le { opcat_rel } - ast::ge { opcat_rel } - ast::gt { opcat_rel } + ast::add => opcat_add, + ast::subtract => opcat_sub, + ast::mul => opcat_mult, + ast::div => opcat_mult, + ast::rem => opcat_mult, + ast::and => opcat_logic, + ast::or => opcat_logic, + ast::bitxor => opcat_bit, + ast::bitand => opcat_bit, + ast::bitor => opcat_bit, + ast::shl => opcat_shift, + ast::shr => opcat_shift, + ast::eq => opcat_eq, + ast::ne => opcat_eq, + ast::lt => opcat_rel, + ast::le => opcat_rel, + ast::ge => opcat_rel, + ast::gt => opcat_rel } } fn tycat(ty: t) -> int { alt get(ty).struct { - ty_bool { tycat_bool } - ty_int(_) | ty_uint(_) | ty_var_integral(_) { tycat_int } - ty_float(_) { tycat_float } - ty_rec(_) | ty_tup(_) | ty_enum(_, _) { tycat_struct } - ty_bot { tycat_bot } - _ { tycat_other } + ty_bool => tycat_bool, + ty_int(_) | ty_uint(_) | ty_var_integral(_) => tycat_int, + ty_float(_) => tycat_float, + ty_rec(_) | ty_tup(_) | ty_enum(_, _) => tycat_struct, + ty_bot => tycat_bot, + _ => tycat_other } } @@ -3124,8 +3127,8 @@ fn normalize_ty(cx: ctxt, t: t) -> t { } alt cx.normalized_cache.find(t) { - some(t) { return t; } - none { } + some(t) => return t, + none => () } let t = match get(t).struct { diff --git a/src/rustc/middle/typeck.rs b/src/rustc/middle/typeck.rs index 910d57e875e..a0c1d1da02f 100644 --- a/src/rustc/middle/typeck.rs +++ b/src/rustc/middle/typeck.rs @@ -181,8 +181,8 @@ fn write_substs_to_tcx(tcx: ty::ctxt, fn lookup_def_tcx(tcx: ty::ctxt, sp: span, id: ast::node_id) -> ast::def { alt tcx.def_map.find(id) { - some(x) { x } - _ { + some(x) => x, + _ => { tcx.sess.span_fatal(sp, ~"internal error looking up a definition") } } @@ -206,19 +206,19 @@ fn require_same_types( let l_tcx, l_infcx; alt maybe_infcx { - none { + none => { l_tcx = tcx; l_infcx = infer::new_infer_ctxt(tcx); } - some(i) { + some(i) => { l_tcx = i.tcx; l_infcx = i; } } alt infer::mk_eqty(l_infcx, t1, t2) { - result::ok(()) { true } - result::err(terr) { + result::ok(()) => true, + result::err(terr) => { l_tcx.sess.span_err(span, msg() + ~": " + ty::type_err_to_str(l_tcx, terr)); false @@ -228,14 +228,14 @@ fn require_same_types( fn arg_is_argv_ty(_tcx: ty::ctxt, a: ty::arg) -> bool { alt ty::get(a.ty).struct { - ty::ty_evec(mt, vstore_uniq) { + ty::ty_evec(mt, vstore_uniq) => { if mt.mutbl != ast::m_imm { return false; } alt ty::get(mt.ty).struct { - ty::ty_estr(vstore_uniq) { return true; } - _ { return false; } + ty::ty_estr(vstore_uniq) => return true, + _ => return false } } - _ { return false; } + _ => return false } } @@ -247,19 +247,19 @@ fn check_main_fn_ty(ccx: @crate_ctxt, let main_t = ty::node_id_to_type(tcx, main_id); alt ty::get(main_t).struct { ty::ty_fn({purity: ast::impure_fn, proto: ast::proto_bare, - inputs, output, ret_style: ast::return_val}) { + inputs, output, ret_style: ast::return_val}) => { alt tcx.items.find(main_id) { - some(ast_map::node_item(it,_)) { + some(ast_map::node_item(it,_)) => { alt it.node { - ast::item_fn(_,ps,_) if vec::is_not_empty(ps) { + ast::item_fn(_,ps,_) if vec::is_not_empty(ps) => { tcx.sess.span_err(main_span, ~"main function is not allowed to have type parameters"); return; } - _ {} + _ => () } } - _ {} + _ => () } let mut ok = ty::type_is_nil(output); let num_args = vec::len(inputs); @@ -273,7 +273,7 @@ fn check_main_fn_ty(ccx: @crate_ctxt, ty_to_str(tcx, main_t)}); } } - _ { + _ => { tcx.sess.span_bug(main_span, ~"main has a non-function type: found `" + ty_to_str(tcx, main_t) + ~"`"); @@ -285,8 +285,8 @@ fn check_for_main_fn(ccx: @crate_ctxt) { let tcx = ccx.tcx; if !tcx.sess.building_library { alt copy tcx.sess.main_fn { - some((id, sp)) { check_main_fn_ty(ccx, id, sp); } - none { tcx.sess.err(~"main function not found"); } + some((id, sp)) => check_main_fn_ty(ccx, id, sp), + none => tcx.sess.err(~"main function not found") } } } diff --git a/src/rustc/middle/typeck/astconv.rs b/src/rustc/middle/typeck/astconv.rs index 632a29ba8e8..1211c5aa8d6 100644 --- a/src/rustc/middle/typeck/astconv.rs +++ b/src/rustc/middle/typeck/astconv.rs @@ -60,8 +60,8 @@ fn get_region_reporting_err(tcx: ty::ctxt, res: result<ty::region, ~str>) -> ty::region { alt res { - result::ok(r) { r } - result::err(e) { + result::ok(r) => r, + result::err(e) => { tcx.sess.span_err(span, e); ty::re_static } @@ -72,8 +72,8 @@ fn ast_region_to_region<AC: ast_conv, RS: region_scope copy owned>( self: AC, rscope: RS, span: span, a_r: @ast::region) -> ty::region { let res = alt a_r.node { - ast::re_anon { rscope.anon_region() } - ast::re_named(id) { rscope.named_region(id) } + ast::re_anon => rscope.anon_region(), + ast::re_named(id) => rscope.named_region(id) }; get_region_reporting_err(self.tcx(), span, res) @@ -94,10 +94,10 @@ fn ast_path_to_substs_and_ty<AC: ast_conv, RS: region_scope copy owned>( // region with the current anon region binding (in other words, // whatever & would get replaced with). let self_r = alt (decl_rp, path.rp) { - (false, none) { + (false, none) => { none } - (false, some(_)) { + (false, some(_)) => { tcx.sess.span_err( path.span, fmt!{"no region bound is allowed on `%s`, \ @@ -105,12 +105,12 @@ fn ast_path_to_substs_and_ty<AC: ast_conv, RS: region_scope copy owned>( ty::item_path_str(tcx, did)}); none } - (true, none) { + (true, none) => { let res = rscope.anon_region(); let r = get_region_reporting_err(self.tcx(), path.span, res); some(r) } - (true, some(r)) { + (true, some(r)) => { some(ast_region_to_region(self, rscope, path.span, r)) } }; @@ -170,20 +170,20 @@ fn ast_ty_to_ty<AC: ast_conv, RS: region_scope copy owned>( alt a_seq_ty.ty.node { // to convert to an e{vec,str}, there can't be a mutability argument - _ if a_seq_ty.mutbl != ast::m_imm {} - ast::ty_vec(mt) { + _ if a_seq_ty.mutbl != ast::m_imm => (), + ast::ty_vec(mt) => { return ty::mk_evec(tcx, ast_mt_to_mt(self, rscope, mt), vst); } - ast::ty_path(path, id) { + ast::ty_path(path, id) => { alt tcx.def_map.find(id) { - some(ast::def_prim_ty(ast::ty_str)) { + some(ast::def_prim_ty(ast::ty_str)) => { check_path_args(tcx, path, NO_TPS | NO_REGIONS); return ty::mk_estr(tcx, vst); } - _ {} + _ => () } } - _ {} + _ => () } let seq_ty = ast_mt_to_mt(self, rscope, a_seq_ty); @@ -213,85 +213,86 @@ fn ast_ty_to_ty<AC: ast_conv, RS: region_scope copy owned>( let tcx = self.tcx(); alt tcx.ast_ty_to_ty_cache.find(ast_ty) { - some(ty::atttce_resolved(ty)) { return ty; } - some(ty::atttce_unresolved) { + some(ty::atttce_resolved(ty)) => return ty, + some(ty::atttce_unresolved) => { tcx.sess.span_fatal(ast_ty.span, ~"illegal recursive type; \ insert an enum in the cycle, \ if this is desired"); } - none { /* go on */ } + none => { /* go on */ } } tcx.ast_ty_to_ty_cache.insert(ast_ty, ty::atttce_unresolved); let typ = alt ast_ty.node { - ast::ty_nil { ty::mk_nil(tcx) } - ast::ty_bot { ty::mk_bot(tcx) } - ast::ty_box(mt) { + ast::ty_nil => ty::mk_nil(tcx), + ast::ty_bot => ty::mk_bot(tcx), + ast::ty_box(mt) => { mk_maybe_vstore(self, rscope, mt, ty::vstore_box, |tmt| ty::mk_box(tcx, tmt)) } - ast::ty_uniq(mt) { + ast::ty_uniq(mt) => { mk_maybe_vstore(self, rscope, mt, ty::vstore_uniq, |tmt| ty::mk_uniq(tcx, tmt)) } - ast::ty_vec(mt) { + ast::ty_vec(mt) => { tcx.sess.span_err(ast_ty.span, ~"bare `[]` is not a type"); // return /something/ so they can at least get more errors ty::mk_evec(tcx, ast_mt_to_mt(self, rscope, mt), ty::vstore_uniq) } - ast::ty_ptr(mt) { + ast::ty_ptr(mt) => { ty::mk_ptr(tcx, ast_mt_to_mt(self, rscope, mt)) } - ast::ty_rptr(region, mt) { + ast::ty_rptr(region, mt) => { let r = ast_region_to_region(self, rscope, ast_ty.span, region); mk_maybe_vstore(self, in_anon_rscope(rscope, r), mt, ty::vstore_slice(r), |tmt| ty::mk_rptr(tcx, r, tmt)) } - ast::ty_tup(fields) { + ast::ty_tup(fields) => { let flds = vec::map(fields, |t| ast_ty_to_ty(self, rscope, t)); ty::mk_tup(tcx, flds) } - ast::ty_rec(fields) { + ast::ty_rec(fields) => { let flds = do fields.map |f| { let tm = ast_mt_to_mt(self, rscope, f.node.mt); {ident: f.node.ident, mt: tm} }; ty::mk_rec(tcx, flds) } - ast::ty_fn(proto, decl) { + ast::ty_fn(proto, decl) => { ty::mk_fn(tcx, ty_of_fn_decl(self, rscope, proto, decl, none)) } - ast::ty_path(path, id) { + ast::ty_path(path, id) => { let a_def = alt tcx.def_map.find(id) { - none { tcx.sess.span_fatal(ast_ty.span, fmt!{"unbound path %s", - path_to_str(path)}); } - some(d) { d }}; + none => tcx.sess.span_fatal(ast_ty.span, fmt!{"unbound path %s", + path_to_str(path)}), + some(d) => d + }; alt a_def { - ast::def_ty(did) | ast::def_class(did, _) { + ast::def_ty(did) | ast::def_class(did, _) => { ast_path_to_ty(self, rscope, did, path, id).ty } - ast::def_prim_ty(nty) { + ast::def_prim_ty(nty) => { alt nty { - ast::ty_bool { + ast::ty_bool => { check_path_args(tcx, path, NO_TPS | NO_REGIONS); ty::mk_bool(tcx) } - ast::ty_int(it) { + ast::ty_int(it) => { check_path_args(tcx, path, NO_TPS | NO_REGIONS); ty::mk_mach_int(tcx, it) } - ast::ty_uint(uit) { + ast::ty_uint(uit) => { check_path_args(tcx, path, NO_TPS | NO_REGIONS); ty::mk_mach_uint(tcx, uit) } - ast::ty_float(ft) { + ast::ty_float(ft) => { check_path_args(tcx, path, NO_TPS | NO_REGIONS); ty::mk_mach_float(tcx, ft) } - ast::ty_str { + ast::ty_str => { tcx.sess.span_err(ast_ty.span, ~"bare `str` is not a type"); // return /something/ so they can at least get more errors @@ -299,24 +300,24 @@ fn ast_ty_to_ty<AC: ast_conv, RS: region_scope copy owned>( } } } - ast::def_ty_param(id, n) { + ast::def_ty_param(id, n) => { check_path_args(tcx, path, NO_TPS | NO_REGIONS); ty::mk_param(tcx, n, id) } - ast::def_self(_) { + ast::def_self(_) => { // n.b.: resolve guarantees that the self type only appears in a // trait, which we rely upon in various places when creating // substs check_path_args(tcx, path, NO_TPS | NO_REGIONS); ty::mk_self(tcx) } - _ { + _ => { tcx.sess.span_fatal(ast_ty.span, ~"found type name used as a variable"); } } } - ast::ty_fixed_length(a_t, some(u)) { + ast::ty_fixed_length(a_t, some(u)) => { mk_maybe_vstore(self, rscope, {ty: a_t, mutbl: ast::m_imm}, ty::vstore_fixed(u), |ty| { @@ -327,12 +328,12 @@ fn ast_ty_to_ty<AC: ast_conv, RS: region_scope copy owned>( ty.ty }) } - ast::ty_fixed_length(_, none) { + ast::ty_fixed_length(_, none) => { tcx.sess.span_bug( ast_ty.span, ~"implied fixed length for bound"); } - ast::ty_infer { + ast::ty_infer => { // ty_infer should only appear as the type of arguments or return // values in a fn_expr, or as the type of local variables. Both of // these cases are handled specially and should not descend into this @@ -341,7 +342,7 @@ fn ast_ty_to_ty<AC: ast_conv, RS: region_scope copy owned>( ast_ty.span, ~"found `ty_infer` in unexpected place"); } - ast::ty_mac(_) { + ast::ty_mac(_) => { tcx.sess.span_bug(ast_ty.span, ~"found `ty_mac` in unexpected place"); } @@ -356,35 +357,35 @@ fn ty_of_arg<AC: ast_conv, RS: region_scope copy owned>( expected_ty: option<ty::arg>) -> ty::arg { let ty = alt a.ty.node { - ast::ty_infer if expected_ty.is_some() {expected_ty.get().ty} - ast::ty_infer {self.ty_infer(a.ty.span)} - _ {ast_ty_to_ty(self, rscope, a.ty)} + ast::ty_infer if expected_ty.is_some() => expected_ty.get().ty, + ast::ty_infer => self.ty_infer(a.ty.span), + _ => ast_ty_to_ty(self, rscope, a.ty) }; let mode = { alt a.mode { - ast::infer(_) if expected_ty.is_some() { + ast::infer(_) if expected_ty.is_some() => { result::get(ty::unify_mode(self.tcx(), a.mode, expected_ty.get().mode)) } - ast::infer(_) { + ast::infer(_) => { alt ty::get(ty).struct { // If the type is not specified, then this must be a fn expr. // Leave the mode as infer(_), it will get inferred based // on constraints elsewhere. - ty::ty_var(_) {a.mode} + ty::ty_var(_) => a.mode, // If the type is known, then use the default for that type. // Here we unify m and the default. This should update the // tables in tcx but should never fail, because nothing else // will have been unified with m yet: - _ { + _ => { let m1 = ast::expl(ty::default_arg_mode_for_ty(ty)); result::get(ty::unify_mode(self.tcx(), a.mode, m1)) } } } - ast::expl(_) {a.mode} + ast::expl(_) => a.mode } }; @@ -417,9 +418,9 @@ fn ty_of_fn_decl<AC: ast_conv, RS: region_scope copy owned>( let expected_ret_ty = expected_tys.map(|e| e.output); let output_ty = alt decl.output.node { - ast::ty_infer if expected_ret_ty.is_some() {expected_ret_ty.get()} - ast::ty_infer {self.ty_infer(decl.output.span)} - _ {ast_ty_to_ty(self, rb, decl.output)} + ast::ty_infer if expected_ret_ty.is_some() => expected_ret_ty.get(), + ast::ty_infer => self.ty_infer(decl.output.span), + _ => ast_ty_to_ty(self, rb, decl.output) }; {purity: decl.purity, proto: proto, inputs: input_tys, diff --git a/src/rustc/middle/typeck/check.rs b/src/rustc/middle/typeck/check.rs index b362b00c55b..d4efdbf7b01 100644 --- a/src/rustc/middle/typeck/check.rs +++ b/src/rustc/middle/typeck/check.rs @@ -177,7 +177,7 @@ fn check_bare_fn(ccx: @crate_ctxt, id: ast::node_id, self_info: option<self_info>) { let fty = ty::node_id_to_type(ccx.tcx, id); - let fn_ty = alt check ty::get(fty).struct { ty::ty_fn(f) {f} }; + let fn_ty = alt check ty::get(fty).struct { ty::ty_fn(f) => f }; check_fn(ccx, self_info, fn_ty, decl, body, false, none); } @@ -217,14 +217,14 @@ fn check_fn(ccx: @crate_ctxt, let fcx: @fn_ctxt = { let {infcx, locals, purity, node_types, node_type_substs} = alt old_fcx { - none { + none => { {infcx: infer::new_infer_ctxt(tcx), locals: int_hash(), purity: decl.purity, node_types: map::int_hash(), node_type_substs: map::int_hash()} } - some(fcx) { + some(fcx) => { assert decl.purity == ast::impure_fn; {infcx: fcx.infcx, locals: fcx.locals, @@ -237,8 +237,8 @@ fn check_fn(ccx: @crate_ctxt, let indirect_ret_ty = if indirect_ret { let ofcx = option::get(old_fcx); alt ofcx.indirect_ret_ty { - some(t) { some(t) } - none { some(ofcx.ret_ty) } + some(t) => some(t), + none => some(ofcx.ret_ty) } } else { none }; @@ -261,11 +261,11 @@ fn check_fn(ccx: @crate_ctxt, // We unify the tail expr's type with the // function result type, if there is a tail expr. alt body.node.expr { - some(tail_expr) { + some(tail_expr) => { let tail_expr_ty = fcx.expr_ty(tail_expr); demand::suptype(fcx, tail_expr.span, fcx.ret_ty, tail_expr_ty); } - none { } + none => () } let mut i = 0u; @@ -294,8 +294,8 @@ fn check_fn(ccx: @crate_ctxt, let var_id = fcx.infcx.next_ty_var_id(); fcx.locals.insert(nid, var_id); alt ty_opt { - none {/* nothing to do */ } - some(typ) { + none => {/* nothing to do */ } + some(typ) => { infer::mk_eqty(fcx.infcx, ty::mk_var(tcx, var_id), typ); } } @@ -312,8 +312,8 @@ fn check_fn(ccx: @crate_ctxt, let visit_local = fn@(local: @ast::local, &&e: (), v: visit::vt<()>) { let o_ty = alt local.node.ty.node { - ast::ty_infer { none } - _ { some(fcx.to_ty(local.node.ty)) } + ast::ty_infer => none, + _ => some(fcx.to_ty(local.node.ty)) }; assign(local.node.id, o_ty); debug!{"Local variable %s is assigned to %s", @@ -372,10 +372,8 @@ fn check_method(ccx: @crate_ctxt, method: @ast::method, fn check_class_member(ccx: @crate_ctxt, class_t: self_info, cm: @ast::class_member) { alt cm.node { - ast::instance_var(_,t,_,_,_) { } - ast::class_method(m) { - check_method(ccx, m, class_t); - } + ast::instance_var(_,t,_,_,_) => (), + ast::class_method(m) => check_method(ccx, m, class_t) } } @@ -386,7 +384,7 @@ fn check_no_duplicate_fields(tcx: ty::ctxt, fields: for fields.each |p| { let (id, sp) = p; alt field_names.find(id) { - some(orig_sp) { + some(orig_sp) => { tcx.sess.span_err(sp, fmt!{"Duplicate field \ name %s in record type declaration", *id}); @@ -394,7 +392,7 @@ fn check_no_duplicate_fields(tcx: ty::ctxt, fields: this field occurred here"); break; } - none { + none => { field_names.insert(id, sp); } } @@ -404,14 +402,14 @@ fn check_no_duplicate_fields(tcx: ty::ctxt, fields: fn check_item(ccx: @crate_ctxt, it: @ast::item) { alt it.node { - ast::item_const(_, e) { check_const(ccx, it.span, e, it.id); } - ast::item_enum(vs, _) { + ast::item_const(_, e) => check_const(ccx, it.span, e, it.id), + ast::item_enum(vs, _) => { check_enum_variants(ccx, it.span, vs, it.id); } - ast::item_fn(decl, tps, body) { + ast::item_fn(decl, tps, body) => { check_bare_fn(ccx, decl, body, it.id, none); } - ast::item_impl(tps, _, ty, ms) { + ast::item_impl(tps, _, ty, ms) => { let rp = ccx.tcx.region_paramd_items.contains_key(it.id); debug!{"item_impl %s with id %d rp %b", *it.ident, it.id, rp}; @@ -419,14 +417,14 @@ fn check_item(ccx: @crate_ctxt, it: @ast::item) { node_id: it.id }; for ms.each |m| { check_method(ccx, m, self_info);} } - ast::item_trait(_, _, trait_methods) { + ast::item_trait(_, _, trait_methods) => { for trait_methods.each |trait_method| { alt trait_method { - required(ty_m) { + required(ty_m) => { // Nothing to do, since required methods don't have // bodies to check. } - provided(m) { + provided(m) => { let self_info = {self_ty: ty::mk_self(ccx.tcx), node_id: it.id}; check_method(ccx, m, self_info); @@ -434,7 +432,7 @@ fn check_item(ccx: @crate_ctxt, it: @ast::item) { } } } - ast::item_class(tps, _, members, m_ctor, m_dtor) { + ast::item_class(tps, _, members, m_ctor, m_dtor) => { let tcx = ccx.tcx; let class_t = {self_ty: ty::node_id_to_type(tcx, it.id), node_id: it.id}; @@ -469,19 +467,19 @@ fn check_item(ccx: @crate_ctxt, it: @ast::item) { // Check that the class is instantiable check_instantiable(ccx.tcx, it.span, it.id); } - ast::item_ty(t, tps) { + ast::item_ty(t, tps) => { let tpt_ty = ty::node_id_to_type(ccx.tcx, it.id); check_bounds_are_used(ccx, t.span, tps, tpt_ty); // If this is a record ty, check for duplicate fields alt t.node { - ast::ty_rec(fields) { + ast::ty_rec(fields) => { check_no_duplicate_fields(ccx.tcx, fields.map(|f| (f.node.ident, f.span))); } - _ {} + _ => () } } - ast::item_foreign_mod(m) { + ast::item_foreign_mod(m) => { if syntax::attr::foreign_abi(it.attrs) == either::right(ast::foreign_abi_rust_intrinsic) { for m.items.each |item| { @@ -498,7 +496,7 @@ fn check_item(ccx: @crate_ctxt, it: @ast::item) { } } } - _ {/* nothing to do */ } + _ => {/* nothing to do */ } } } @@ -522,9 +520,9 @@ impl of region_scope for @fn_ctxt { fn named_region(id: ast::ident) -> result<ty::region, ~str> { do empty_rscope.named_region(id).chain_err |_e| { alt self.in_scope_regions.find(ty::br_named(id)) { - some(r) { result::ok(r) } - none if *id == ~"blk" { self.block_region() } - none { + some(r) => result::ok(r), + none if *id == ~"blk" => self.block_region(), + none => { result::err(fmt!{"named region `%s` not in scope here", *id}) } } @@ -567,8 +565,8 @@ impl methods for @fn_ctxt { fn expr_ty(ex: @ast::expr) -> ty::t { alt self.node_types.find(ex.id) { - some(t) { t } - none { + some(t) => t, + none => { self.tcx().sess.bug(fmt!{"no type for expr %d (%s) in fcx %s", ex.id, expr_to_str(ex), self.tag()}); } @@ -576,8 +574,8 @@ impl methods for @fn_ctxt { } fn node_ty(id: ast::node_id) -> ty::t { alt self.node_types.find(id) { - some(t) { t } - none { + some(t) => t, + none => { self.tcx().sess.bug( fmt!{"no type for node %d: %s in fcx %s", id, ast_map::node_id_to_str(self.tcx().items, id), @@ -587,8 +585,8 @@ impl methods for @fn_ctxt { } fn node_ty_substs(id: ast::node_id) -> ty::substs { alt self.node_type_substs.find(id) { - some(ts) { ts } - none { + some(ts) => ts, + none => { self.tcx().sess.bug( fmt!{"no type substs for node %d: %s in fcx %s", id, ast_map::node_id_to_str(self.tcx().items, id), @@ -640,8 +638,8 @@ impl methods for @fn_ctxt { fn require_unsafe(sp: span, op: ~str) { alt self.purity { - ast::unsafe_fn {/*ok*/} - _ { + ast::unsafe_fn => {/*ok*/} + _ => { self.ccx.tcx.sess.span_err( sp, fmt!{"%s requires unsafe function or block", op}); @@ -665,16 +663,16 @@ fn do_autoderef(fcx: @fn_ctxt, sp: span, t: ty::t) -> ty::t { // Some extra checks to detect weird cycles and so forth: alt sty { - ty::ty_box(inner) | ty::ty_uniq(inner) | ty::ty_rptr(_, inner) { + ty::ty_box(inner) | ty::ty_uniq(inner) | ty::ty_rptr(_, inner) => { alt ty::get(t1).struct { - ty::ty_var(v1) { + ty::ty_var(v1) => { ty::occurs_check(fcx.ccx.tcx, sp, v1, ty::mk_box(fcx.ccx.tcx, inner)); } - _ { } + _ => () } } - ty::ty_enum(did, substs) { + ty::ty_enum(did, substs) => { // Watch out for a type like `enum t = @t`. Such a type would // otherwise infinitely auto-deref. This is the only autoderef // loop that needs to be concerned with this, as an error will be @@ -685,13 +683,13 @@ fn do_autoderef(fcx: @fn_ctxt, sp: span, t: ty::t) -> ty::t { } vec::push(enum_dids, did); } - _ { /*ok*/ } + _ => { /*ok*/ } } // Otherwise, deref if type is derefable: alt ty::deref_sty(fcx.ccx.tcx, sty, false) { - none { return t1; } - some(mt) { t1 = mt.ty; } + none => return t1, + some(mt) => t1 = mt.ty } }; } @@ -701,17 +699,17 @@ fn check_lit(fcx: @fn_ctxt, lit: @ast::lit) -> ty::t { let tcx = fcx.ccx.tcx; alt lit.node { - ast::lit_str(s) => { ty::mk_estr(tcx, ty::vstore_slice(ty::re_static)) } - ast::lit_int(_, t) { ty::mk_mach_int(tcx, t) } - ast::lit_uint(_, t) { ty::mk_mach_uint(tcx, t) } - ast::lit_int_unsuffixed(_) { + ast::lit_str(s) => ty::mk_estr(tcx, ty::vstore_slice(ty::re_static)), + ast::lit_int(_, t) => ty::mk_mach_int(tcx, t), + ast::lit_uint(_, t) => ty::mk_mach_uint(tcx, t), + ast::lit_int_unsuffixed(_) => { // An unsuffixed integer literal could have any integral type, // so we create an integral type variable for it. ty::mk_var_integral(tcx, fcx.infcx.next_ty_var_integral_id()) } - ast::lit_float(_, t) { ty::mk_mach_float(tcx, t) } - ast::lit_nil { ty::mk_nil(tcx) } - ast::lit_bool(_) { ty::mk_bool(tcx) } + ast::lit_float(_, t) => ty::mk_mach_float(tcx, t), + ast::lit_nil => ty::mk_nil(tcx), + ast::lit_bool(_) => ty::mk_bool(tcx) } } @@ -744,13 +742,13 @@ fn impl_self_ty(fcx: @fn_ctxt, did: ast::def_id) -> ty_param_substs_and_ty { let rp = fcx.tcx().region_paramd_items.contains_key(did.node); alt check tcx.items.find(did.node) { some(ast_map::node_item(@{node: ast::item_impl(ts, _, st, _), - _}, _)) { + _}, _)) => { {n_tps: ts.len(), rp: rp, raw_ty: fcx.ccx.to_ty(rscope::type_rscope(rp), st)} } some(ast_map::node_item(@{node: ast::item_class(ts, - _,_,_,_), id: class_id, _},_)) { + _,_,_,_), id: class_id, _},_)) => { /* If the impl is a class, the self ty is just the class ty (doing a no-op subst for the ty params; in the next step, we substitute in fresh vars for them) @@ -763,7 +761,7 @@ fn impl_self_ty(fcx: @fn_ctxt, did: ast::def_id) -> ty_param_substs_and_ty { self_ty: none, tps: ty::ty_params_to_tys(tcx, ts)})} } - _ { tcx.sess.bug(~"impl_self_ty: unbound item or item that \ + _ => { tcx.sess.bug(~"impl_self_ty: unbound item or item that \ doesn't have a self_ty"); } } } else { @@ -821,12 +819,12 @@ fn check_expr_with_unifier(fcx: @fn_ctxt, // functions. Therefore, we match one level of structure. let fn_ty = alt structure_of(fcx, sp, in_fty) { - sty @ ty::ty_fn(fn_ty) { + sty @ ty::ty_fn(fn_ty) => { replace_bound_regions_in_fn_ty( fcx.ccx.tcx, @nil, none, fn_ty, |_br| fcx.infcx.next_region_var_nb()).fn_ty } - sty { + sty => { // I would like to make this span_err, but it's // really hard due to the way that expr_bind() is // written. @@ -875,8 +873,8 @@ fn check_expr_with_unifier(fcx: @fn_ctxt, for [false, true]/_.each |check_blocks| { for args.eachi |i, a| { let is_block = alt a.node { - ast::expr_fn_block(*) { true } - _ { false } + ast::expr_fn_block(*) => true, + _ => false }; if is_block == check_blocks { let arg_ty = arg_tys[i]; @@ -908,10 +906,10 @@ fn check_expr_with_unifier(fcx: @fn_ctxt, // Index expressions need to be handled seperately, to inform // them that they appear in call position. let mut bot = alt f.node { - ast::expr_field(base, field, tys) { + ast::expr_field(base, field, tys) => { check_field(fcx, f, true, base, field, tys) } - _ { check_expr(fcx, f, none) } + _ => check_expr(fcx, f, none) }; let fn_ty = fcx.expr_ty(f); @@ -925,12 +923,12 @@ fn check_expr_with_unifier(fcx: @fn_ctxt, // Pull the return type out of the type of the function. alt structure_of(fcx, sp, fty) { - ty::ty_fn(f) { + ty::ty_fn(f) => { bot |= (f.ret_style == ast::noreturn); fcx.write_ty(call_expr_id, f.output); return bot; } - _ { fcx.ccx.tcx.sess.span_fatal(sp, ~"calling non-function"); } + _ => fcx.ccx.tcx.sess.span_fatal(sp, ~"calling non-function") } } @@ -955,7 +953,7 @@ fn check_expr_with_unifier(fcx: @fn_ctxt, _sp: span) -> bool { let (if_t, if_bot) = alt elsopt { - some(els) { + some(els) => { let if_t = fcx.infcx.next_ty_var(); let thn_bot = check_block(fcx, thn); let thn_t = fcx.node_ty(thn.node.id); @@ -963,7 +961,7 @@ fn check_expr_with_unifier(fcx: @fn_ctxt, let els_bot = check_expr_with(fcx, els, if_t); (if_t, thn_bot & els_bot) } - none { + none => { check_block_no_value(fcx, thn); (ty::mk_nil(fcx.ccx.tcx), false) } @@ -979,7 +977,7 @@ fn check_expr_with_unifier(fcx: @fn_ctxt, let lkup = method::lookup(fcx, op_ex, self_ex, op_ex.id, op_ex.callee_id, @opname, self_t, ~[], false); alt lkup.method() { - some(origin) { + some(origin) => { let {fty: method_ty, bot: bot} = { let method_ty = fcx.node_ty(op_ex.callee_id); check_call_inner(fcx, op_ex.span, op_ex.id, @@ -988,7 +986,7 @@ fn check_expr_with_unifier(fcx: @fn_ctxt, fcx.ccx.method_map.insert(op_ex.id, origin); some((ty::ty_fn_ret(method_ty), bot)) } - _ { none } + _ => none } } // could be either a expr_binop or an expr_assign_binop @@ -1002,7 +1000,7 @@ fn check_expr_with_unifier(fcx: @fn_ctxt, let lhs_t = structurally_resolved_type(fcx, lhs.span, lhs_t); return alt (op, ty::get(lhs_t).struct) { (_, _) if ty::type_is_integral(lhs_t) && - ast_util::is_shift_binop(op) { + ast_util::is_shift_binop(op) => { // Shift is a special case: rhs can be any integral type let rhs_bot = check_expr(fcx, rhs, none); let rhs_t = fcx.expr_ty(rhs); @@ -1011,13 +1009,13 @@ fn check_expr_with_unifier(fcx: @fn_ctxt, lhs_bot | rhs_bot } - (_, _) if ty::is_binopable(tcx, lhs_t, op) { + (_, _) if ty::is_binopable(tcx, lhs_t, op) => { let tvar = fcx.infcx.next_ty_var(); demand::suptype(fcx, expr.span, tvar, lhs_t); let rhs_bot = check_expr_with(fcx, rhs, tvar); let rhs_t = alt op { ast::eq | ast::lt | ast::le | ast::ne | ast::ge | - ast::gt { + ast::gt => { // these comparison operators are handled in a // separate case below. tcx.sess.span_bug( @@ -1025,14 +1023,14 @@ fn check_expr_with_unifier(fcx: @fn_ctxt, fmt!{"comparison operator in expr_binop: %s", ast_util::binop_to_str(op)}); } - _ { lhs_t } + _ => lhs_t }; fcx.write_ty(expr.id, rhs_t); if !ast_util::lazy_binop(op) { lhs_bot | rhs_bot } else { lhs_bot } } - (_, _) { + (_, _) => { let (result, rhs_bot) = check_user_binop(fcx, expr, lhs, lhs_t, op, rhs); fcx.write_ty(expr.id, result); @@ -1045,15 +1043,15 @@ fn check_expr_with_unifier(fcx: @fn_ctxt, op: ast::binop, rhs: @ast::expr) -> (ty::t, bool) { let tcx = fcx.ccx.tcx; alt ast_util::binop_to_method_name(op) { - some(name) { + some(name) => { alt lookup_op_method(fcx, ex, lhs_expr, lhs_resolved_t, name, ~[rhs]) { - some(pair) { return pair; } - _ {} + some(pair) => return pair, + _ => () } } - _ {} + _ => () } check_expr(fcx, rhs, none); @@ -1067,11 +1065,11 @@ fn check_expr_with_unifier(fcx: @fn_ctxt, // supply the do keyword. Let's be more helpful in that situation. if op == ast::or { alt ty::get(lhs_resolved_t).struct { - ty::ty_fn(f) { + ty::ty_fn(f) => { tcx.sess.span_note( ex.span, ~"did you forget the 'do' keyword for the call?"); } - _ {} + _ => () } } @@ -1081,8 +1079,8 @@ fn check_expr_with_unifier(fcx: @fn_ctxt, ex: @ast::expr, rhs_expr: @ast::expr, rhs_t: ty::t) -> ty::t { alt lookup_op_method(fcx, ex, rhs_expr, rhs_t, mname, ~[]) { - some((ret_ty, _)) { ret_ty } - _ { + some((ret_ty, _)) => ret_ty, + _ => { fcx.ccx.tcx.sess.span_err( ex.span, fmt!{"cannot apply unary operator `%s` to type `%s`", op_str, fcx.infcx.ty_to_str(rhs_t)}); @@ -1099,13 +1097,13 @@ fn check_expr_with_unifier(fcx: @fn_ctxt, unpack: fn(ty::sty) -> option<O>) -> option<O> { alt expected { - some(t) { + some(t) => { alt resolve_type(fcx.infcx, t, force_tvar) { - result::ok(t) { unpack(ty::get(t).struct) } - _ { none } + result::ok(t) => unpack(ty::get(t).struct), + _ => none } } - _ { none } + _ => none } } @@ -1163,9 +1161,9 @@ fn check_expr_with_unifier(fcx: @fn_ctxt, let mut handled = false; let n_tys = vec::len(tys); alt structure_of(fcx, expr.span, base_t) { - ty::ty_rec(fields) { + ty::ty_rec(fields) => { alt ty::field_idx(field, fields) { - some(ix) { + some(ix) => { if n_tys > 0u { tcx.sess.span_err(expr.span, ~"can't provide type parameters \ @@ -1174,10 +1172,10 @@ fn check_expr_with_unifier(fcx: @fn_ctxt, fcx.write_ty(expr.id, fields[ix].mt.ty); handled = true; } - _ {} + _ => () } } - ty::ty_class(base_id, substs) { + ty::ty_class(base_id, substs) => { // This is just for fields -- the same code handles // methods in both classes and traits @@ -1197,15 +1195,15 @@ fn check_expr_with_unifier(fcx: @fn_ctxt, lookup_public_fields(tcx, base_id) }; alt lookup_field_ty(tcx, base_id, cls_items, field, substs) { - some(field_ty) { + some(field_ty) => { // (2) look up what field's type is, and return it fcx.write_ty(expr.id, field_ty); handled = true; } - none {} + none => () } } - _ {} + _ => () } if !handled { let tps = vec::map(tys, |ty| fcx.to_ty(ty)); @@ -1219,7 +1217,7 @@ fn check_expr_with_unifier(fcx: @fn_ctxt, expr.id, field, expr_t, tps, is_self_ref); alt lkup.method() { - some(entry) { + some(entry) => { fcx.ccx.method_map.insert(expr.id, entry); // If we have resolved to a method but this is not in @@ -1231,7 +1229,7 @@ fn check_expr_with_unifier(fcx: @fn_ctxt, (try writing an anonymous function)"); } } - none { + none => { let t_err = fcx.infcx.resolve_type_vars_if_possible(expr_t); let msg = fmt!{"attempted access of field `%s` on type `%s`, \ but no public field or method with that name \ @@ -1251,7 +1249,7 @@ fn check_expr_with_unifier(fcx: @fn_ctxt, let id = expr.id; let mut bot = false; alt expr.node { - ast::expr_vstore(ev, vst) { + ast::expr_vstore(ev, vst) => { let typ = alt ev.node { ast::expr_lit(@{node: ast::lit_str(s), span:_}) => { let tt = ast_expr_vstore_to_vstore(fcx, ev, str::len(*s), vst); @@ -1278,7 +1276,7 @@ fn check_expr_with_unifier(fcx: @fn_ctxt, fcx.write_ty(id, typ); } - ast::expr_lit(lit) { + ast::expr_lit(lit) => { let typ = check_lit(fcx, lit); fcx.write_ty(id, typ); } @@ -1294,17 +1292,17 @@ fn check_expr_with_unifier(fcx: @fn_ctxt, ast::expr_binary(ast::lt, lhs, rhs) | ast::expr_binary(ast::le, lhs, rhs) | ast::expr_binary(ast::gt, lhs, rhs) | - ast::expr_binary(ast::ge, lhs, rhs) { + ast::expr_binary(ast::ge, lhs, rhs) => { let tcx = fcx.ccx.tcx; let tvar = fcx.infcx.next_ty_var(); bot |= check_expr_with(fcx, lhs, tvar); bot |= check_expr_with(fcx, rhs, tvar); fcx.write_ty(id, ty::mk_bool(tcx)); } - ast::expr_binary(op, lhs, rhs) { + ast::expr_binary(op, lhs, rhs) => { bot |= check_binop(fcx, expr, op, lhs, rhs); } - ast::expr_assign_op(op, lhs, rhs) { + ast::expr_assign_op(op, lhs, rhs) => { bot |= check_binop(fcx, expr, op, lhs, rhs); let lhs_t = fcx.expr_ty(lhs); let result_t = fcx.expr_ty(expr); @@ -1315,54 +1313,52 @@ fn check_expr_with_unifier(fcx: @fn_ctxt, // and so forth. - Niko fcx.write_nil(expr.id); } - ast::expr_unary(unop, oprnd) { + ast::expr_unary(unop, oprnd) => { let exp_inner = do unpack_expected(fcx, expected) |sty| { alt unop { - ast::box(_) | ast::uniq(_) { - alt sty { - ty::ty_box(mt) | ty::ty_uniq(mt) { some(mt.ty) } - _ { none } - } + ast::box(_) | ast::uniq(_) => alt sty { + ty::ty_box(mt) | ty::ty_uniq(mt) => some(mt.ty), + _ => none } - ast::not | ast::neg { expected } - ast::deref { none } + ast::not | ast::neg => expected, + ast::deref => none } }; bot = check_expr(fcx, oprnd, exp_inner); let mut oprnd_t = fcx.expr_ty(oprnd); alt unop { - ast::box(mutbl) { + ast::box(mutbl) => { oprnd_t = ty::mk_box(tcx, {ty: oprnd_t, mutbl: mutbl}); } - ast::uniq(mutbl) { + ast::uniq(mutbl) => { oprnd_t = ty::mk_uniq(tcx, {ty: oprnd_t, mutbl: mutbl}); } - ast::deref { + ast::deref => { let sty = structure_of(fcx, expr.span, oprnd_t); // deref'ing an unsafe pointer requires that we be in an unsafe // context alt sty { - ty::ty_ptr(*) { + ty::ty_ptr(*) => { fcx.require_unsafe( expr.span, ~"dereference of unsafe pointer"); } - _ { /*ok*/ } + _ => { /*ok*/ } } alt ty::deref_sty(tcx, sty, true) { - some(mt) { oprnd_t = mt.ty } - none { + some(mt) => { oprnd_t = mt.ty } + none => { alt sty { - ty::ty_enum(*) { + ty::ty_enum(*) => { tcx.sess.span_err( expr.span, ~"can only dereference enums \ with a single variant which has a \ single argument"); } - _ { + _ => { tcx.sess.span_err( expr.span, fmt!{"type %s cannot be dereferenced", @@ -1372,7 +1368,7 @@ fn check_expr_with_unifier(fcx: @fn_ctxt, } } } - ast::not { + ast::not => { oprnd_t = structurally_resolved_type(fcx, oprnd.span, oprnd_t); if !(ty::type_is_integral(oprnd_t) || ty::get(oprnd_t).struct == ty::ty_bool) { @@ -1380,7 +1376,7 @@ fn check_expr_with_unifier(fcx: @fn_ctxt, oprnd, oprnd_t); } } - ast::neg { + ast::neg => { oprnd_t = structurally_resolved_type(fcx, oprnd.span, oprnd_t); if !(ty::type_is_integral(oprnd_t) || ty::type_is_fp(oprnd_t)) { @@ -1391,9 +1387,9 @@ fn check_expr_with_unifier(fcx: @fn_ctxt, } fcx.write_ty(id, oprnd_t); } - ast::expr_addr_of(mutbl, oprnd) { + ast::expr_addr_of(mutbl, oprnd) => { bot = check_expr(fcx, oprnd, unpack_expected(fcx, expected, |ty| - alt ty { ty::ty_rptr(_, mt) { some(mt.ty) } _ { none } } + alt ty { ty::ty_rptr(_, mt) => some(mt.ty), _ => none } )); //let region = region_of(fcx, oprnd); let region = fcx.infcx.next_region_var_with_scope_lb(expr.id); @@ -1401,96 +1397,97 @@ fn check_expr_with_unifier(fcx: @fn_ctxt, let oprnd_t = ty::mk_rptr(tcx, region, tm); fcx.write_ty(id, oprnd_t); } - ast::expr_path(pth) { + ast::expr_path(pth) => { let defn = lookup_def(fcx, pth.span, id); let tpt = ty_param_bounds_and_ty_for_def(fcx, expr.span, defn); instantiate_path(fcx, pth, tpt, expr.span, expr.id); } - ast::expr_mac(_) { tcx.sess.bug(~"unexpanded macro"); } - ast::expr_fail(expr_opt) { + ast::expr_mac(_) => tcx.sess.bug(~"unexpanded macro"), + ast::expr_fail(expr_opt) => { bot = true; alt expr_opt { - none {/* do nothing */ } - some(e) { check_expr_with(fcx, e, - ty::mk_estr(tcx, ty::vstore_uniq)); } + none => {/* do nothing */ } + some(e) => { + check_expr_with(fcx, e, + ty::mk_estr(tcx, ty::vstore_uniq)); + } } fcx.write_bot(id); } - ast::expr_break { fcx.write_bot(id); bot = true; } - ast::expr_again { fcx.write_bot(id); bot = true; } - ast::expr_ret(expr_opt) { + ast::expr_break => { fcx.write_bot(id); bot = true; } + ast::expr_again => { fcx.write_bot(id); bot = true; } + ast::expr_ret(expr_opt) => { bot = true; let ret_ty = alt fcx.indirect_ret_ty { - some(t) { t } none { fcx.ret_ty } + some(t) => t, none => fcx.ret_ty }; alt expr_opt { - none { - alt fcx.mk_eqty(ret_ty, ty::mk_nil(tcx)) { - result::ok(_) { /* fall through */ } - result::err(_) { + none => alt fcx.mk_eqty(ret_ty, ty::mk_nil(tcx)) { + result::ok(_) => { /* fall through */ } + result::err(_) => { tcx.sess.span_err( expr.span, - ~"`return;` in function returning non-nil"); } + ~"`return;` in function returning non-nil"); } } - some(e) { check_expr_with(fcx, e, ret_ty); } + some(e) => { check_expr_with(fcx, e, ret_ty); } } fcx.write_bot(id); } - ast::expr_log(_, lv, e) { + ast::expr_log(_, lv, e) => { bot = check_expr_with(fcx, lv, ty::mk_mach_uint(tcx, ast::ty_u32)); // Note: this does not always execute, so do not propagate bot: check_expr(fcx, e, none); fcx.write_nil(id); } - ast::expr_assert(e) { + ast::expr_assert(e) => { bot = check_expr_with(fcx, e, ty::mk_bool(tcx)); fcx.write_nil(id); } - ast::expr_copy(a) | ast::expr_unary_move(a) { + ast::expr_copy(a) | ast::expr_unary_move(a) => { bot = check_expr(fcx, a, expected); fcx.write_ty(id, fcx.expr_ty(a)); } - ast::expr_move(lhs, rhs) { + ast::expr_move(lhs, rhs) => { bot = check_assignment(fcx, expr.span, lhs, rhs, id); } - ast::expr_assign(lhs, rhs) { + ast::expr_assign(lhs, rhs) => { bot = check_assignment(fcx, expr.span, lhs, rhs, id); } - ast::expr_swap(lhs, rhs) { + ast::expr_swap(lhs, rhs) => { bot = check_assignment(fcx, expr.span, lhs, rhs, id); } - ast::expr_if(cond, thn, elsopt) { + ast::expr_if(cond, thn, elsopt) => { bot = check_expr_with(fcx, cond, ty::mk_bool(tcx)) | check_then_else(fcx, thn, elsopt, id, expr.span); } - ast::expr_while(cond, body) { + ast::expr_while(cond, body) => { bot = check_expr_with(fcx, cond, ty::mk_bool(tcx)); check_block_no_value(fcx, body); fcx.write_ty(id, ty::mk_nil(tcx)); } - ast::expr_loop(body) { + ast::expr_loop(body) => { check_block_no_value(fcx, body); fcx.write_ty(id, ty::mk_nil(tcx)); bot = !may_break(body); } - ast::expr_alt(discrim, arms, _) { + ast::expr_alt(discrim, arms, _) => { bot = alt::check_alt(fcx, expr, discrim, arms); } - ast::expr_fn(proto, decl, body, cap_clause) { + ast::expr_fn(proto, decl, body, cap_clause) => { check_expr_fn(fcx, expr, proto, decl, body, false, expected); capture::check_capture_clause(tcx, expr.id, cap_clause); } - ast::expr_fn_block(decl, body, cap_clause) { + ast::expr_fn_block(decl, body, cap_clause) => { // Take the prototype from the expected type, but default to block: let proto = unpack_expected(fcx, expected, |sty| - alt sty { ty::ty_fn({proto, _}) { some(proto) } _ { none } } + alt sty { ty::ty_fn({proto, _}) => some(proto), _ => none } ).get_default(ast::proto_box); check_expr_fn(fcx, expr, proto, decl, body, false, expected); capture::check_capture_clause(tcx, expr.id, cap_clause); } - ast::expr_loop_body(b) { + ast::expr_loop_body(b) => { // a loop body is the special argument to a `for` loop. We know that // there will be an expected type in this context because it can only // appear in the context of a call, so we get the expected type of the @@ -1499,10 +1496,10 @@ fn check_expr_with_unifier(fcx: @fn_ctxt, // 2. the cloure that was given returns unit let expected_sty = unpack_expected(fcx, expected, |x| some(x)); let (inner_ty, proto) = alt expected_sty { - some(ty::ty_fn(fty)) { + some(ty::ty_fn(fty)) => { alt infer::mk_subty(fcx.infcx, fty.output, ty::mk_bool(tcx)) { - result::ok(_) {} - result::err(err) { + result::ok(_) => (), + result::err(err) => { tcx.sess.span_fatal( expr.span, fmt!{"a `loop` function's last argument \ should return `bool`, not `%s`", @@ -1511,14 +1508,14 @@ fn check_expr_with_unifier(fcx: @fn_ctxt, } (ty::mk_fn(tcx, {output: ty::mk_nil(tcx) with fty}), fty.proto) } - _ { + _ => { tcx.sess.span_fatal(expr.span, ~"a `loop` function's last \ argument should be of function \ type"); } }; alt check b.node { - ast::expr_fn_block(decl, body, cap_clause) { + ast::expr_fn_block(decl, body, cap_clause) => { check_expr_fn(fcx, b, proto, decl, body, true, some(inner_ty)); demand::suptype(fcx, b.span, inner_ty, fcx.expr_ty(b)); capture::check_capture_clause(tcx, b.id, cap_clause); @@ -1527,26 +1524,26 @@ fn check_expr_with_unifier(fcx: @fn_ctxt, let block_ty = structurally_resolved_type( fcx, expr.span, fcx.node_ty(b.id)); alt check ty::get(block_ty).struct { - ty::ty_fn(fty) { + ty::ty_fn(fty) => { fcx.write_ty(expr.id, ty::mk_fn(tcx, {output: ty::mk_bool(tcx) with fty})); } } } - ast::expr_do_body(b) { + ast::expr_do_body(b) => { let expected_sty = unpack_expected(fcx, expected, |x| some(x)); let (inner_ty, proto) = alt expected_sty { - some(ty::ty_fn(fty)) { + some(ty::ty_fn(fty)) => { (ty::mk_fn(tcx, fty), fty.proto) } - _ { + _ => { tcx.sess.span_fatal(expr.span, ~"Non-function passed to a `do` \ function as its last argument, or wrong number of arguments \ passed to a `do` function"); } }; alt check b.node { - ast::expr_fn_block(decl, body, cap_clause) { + ast::expr_fn_block(decl, body, cap_clause) => { check_expr_fn(fcx, b, proto, decl, body, true, some(inner_ty)); demand::suptype(fcx, b.span, inner_ty, fcx.expr_ty(b)); capture::check_capture_clause(tcx, b.id, cap_clause); @@ -1555,25 +1552,25 @@ fn check_expr_with_unifier(fcx: @fn_ctxt, let block_ty = structurally_resolved_type( fcx, expr.span, fcx.node_ty(b.id)); alt check ty::get(block_ty).struct { - ty::ty_fn(fty) { + ty::ty_fn(fty) => { fcx.write_ty(expr.id, ty::mk_fn(tcx, fty)); } } } - ast::expr_block(b) { + ast::expr_block(b) => { // If this is an unchecked block, turn off purity-checking bot = check_block(fcx, b); let typ = alt b.node.expr { - some(expr) { fcx.expr_ty(expr) } - none { ty::mk_nil(tcx) } + some(expr) => fcx.expr_ty(expr), + none => ty::mk_nil(tcx) }; fcx.write_ty(id, typ); } - ast::expr_call(f, args, _) { + ast::expr_call(f, args, _) => { bot = check_call(fcx, expr.span, expr.id, f, args); } - ast::expr_cast(e, t) { + ast::expr_cast(e, t) => { bot = check_expr(fcx, e, none); let t_1 = fcx.to_ty(t); let t_e = fcx.expr_ty(e); @@ -1583,9 +1580,9 @@ fn check_expr_with_unifier(fcx: @fn_ctxt, alt ty::get(t_1).struct { // This will be looked up later on - ty::ty_trait(*) {} + ty::ty_trait(*) => (), - _ { + _ => { if ty::type_is_nil(t_e) { tcx.sess.span_err(expr.span, ~"cast from nil: " + fcx.infcx.ty_to_str(t_e) + ~" as " + @@ -1614,14 +1611,14 @@ fn check_expr_with_unifier(fcx: @fn_ctxt, } fcx.write_ty(id, t_1); } - ast::expr_vec(args, mutbl) { + ast::expr_vec(args, mutbl) => { let t: ty::t = fcx.infcx.next_ty_var(); for args.each |e| { bot |= check_expr_with(fcx, e, t); } let typ = ty::mk_evec(tcx, {ty: t, mutbl: mutbl}, ty::vstore_fixed(args.len())); fcx.write_ty(id, typ); } - ast::expr_repeat(element, count_expr, mutbl) { + ast::expr_repeat(element, count_expr, mutbl) => { let count = ty::eval_repeat_count(tcx, count_expr, expr.span); fcx.write_ty(count_expr.id, ty::mk_uint(tcx)); let t: ty::t = fcx.infcx.next_ty_var(); @@ -1630,11 +1627,11 @@ fn check_expr_with_unifier(fcx: @fn_ctxt, ty::vstore_fixed(count)); fcx.write_ty(id, t); } - ast::expr_tup(elts) { + ast::expr_tup(elts) => { let mut elt_ts = ~[]; vec::reserve(elt_ts, vec::len(elts)); let flds = unpack_expected(fcx, expected, |sty| { - alt sty { ty::ty_tup(flds) { some(flds) } _ { none } } + alt sty { ty::ty_tup(flds) => some(flds), _ => none } }); for elts.eachi |i, e| { check_expr(fcx, e, flds.map(|fs| fs[i])); @@ -1644,13 +1641,13 @@ fn check_expr_with_unifier(fcx: @fn_ctxt, let typ = ty::mk_tup(tcx, elt_ts); fcx.write_ty(id, typ); } - ast::expr_rec(fields, base) { + ast::expr_rec(fields, base) => { option::iter(base, |b| { check_expr(fcx, b, expected); }); let expected = if expected == none && base != none { some(fcx.expr_ty(base.get())) } else { expected }; let flds = unpack_expected(fcx, expected, |sty| - alt sty { ty::ty_rec(flds) { some(flds) } _ { none } } + alt sty { ty::ty_rec(flds) => some(flds), _ => none } ); let fields_t = vec::map(fields, |f| { bot |= check_expr(fcx, f.node.expr, flds.chain(|flds| @@ -1663,7 +1660,7 @@ fn check_expr_with_unifier(fcx: @fn_ctxt, respan(f.node.expr.span, {ident: f.node.ident, mt: expr_mt}) }); alt base { - none { + none => { fn get_node(f: spanned<field>) -> field { f.node } let typ = ty::mk_rec(tcx, vec::map(fields_t, get_node)); fcx.write_ty(id, typ); @@ -1675,11 +1672,11 @@ fn check_expr_with_unifier(fcx: @fn_ctxt, check_no_duplicate_fields(tcx, fields.map(|f| (f.node.ident, f.span))); } - some(bexpr) { + some(bexpr) => { let bexpr_t = fcx.expr_ty(bexpr); let base_fields = alt structure_of(fcx, expr.span, bexpr_t) { - ty::ty_rec(flds) { flds } - _ { + ty::ty_rec(flds) => flds, + _ => { tcx.sess.span_fatal(expr.span, ~"record update has non-record base"); } @@ -1702,7 +1699,7 @@ fn check_expr_with_unifier(fcx: @fn_ctxt, } } } - ast::expr_struct(path, fields) { + ast::expr_struct(path, fields) => { // Resolve the path. let class_id; alt tcx.def_map.find(id) { @@ -1833,27 +1830,27 @@ fn check_expr_with_unifier(fcx: @fn_ctxt, // Write in the resulting type. fcx.write_ty(id, struct_type); } - ast::expr_field(base, field, tys) { + ast::expr_field(base, field, tys) => { bot = check_field(fcx, expr, false, base, field, tys); } - ast::expr_index(base, idx) { + ast::expr_index(base, idx) => { bot |= check_expr(fcx, base, none); let raw_base_t = fcx.expr_ty(base); let base_t = do_autoderef(fcx, expr.span, raw_base_t); bot |= check_expr(fcx, idx, none); let idx_t = fcx.expr_ty(idx); alt ty::index_sty(tcx, structure_of(fcx, expr.span, base_t)) { - some(mt) { + some(mt) => { require_integral(fcx, idx.span, idx_t); fcx.write_ty(id, mt.ty); } - none { + none => { let resolved = structurally_resolved_type(fcx, expr.span, raw_base_t); alt lookup_op_method(fcx, expr, base, resolved, ~"index", ~[idx]) { - some((ret_ty, _)) { fcx.write_ty(id, ret_ty); } - _ { + some((ret_ty, _)) => fcx.write_ty(id, ret_ty), + _ => { tcx.sess.span_fatal( expr.span, ~"cannot index a value of type `" + fcx.infcx.ty_to_str(base_t) + ~"`"); @@ -1869,8 +1866,8 @@ fn check_expr_with_unifier(fcx: @fn_ctxt, syntax::print::pprust::expr_to_str(expr), ty_to_str(tcx, fcx.expr_ty(expr)), alt expected { - some(t) { ty_to_str(tcx, t) } - _ { ~"empty" } + some(t) => ty_to_str(tcx, t), + _ => ~"empty" }}; unifier(); @@ -1899,10 +1896,10 @@ fn check_decl_local(fcx: @fn_ctxt, local: @ast::local) -> bool { let t = ty::mk_var(fcx.ccx.tcx, fcx.locals.get(local.node.id)); fcx.write_ty(local.node.id, t); alt local.node.init { - some(init) { + some(init) => { bot = check_decl_initializer(fcx, local.node.id, init); } - _ {/* fall through */ } + _ => {/* fall through */ } } let region = @@ -1922,20 +1919,20 @@ fn check_stmt(fcx: @fn_ctxt, stmt: @ast::stmt) -> bool { let mut node_id; let mut bot = false; alt stmt.node { - ast::stmt_decl(decl, id) { + ast::stmt_decl(decl, id) => { node_id = id; alt decl.node { - ast::decl_local(ls) { - for ls.each |l| { bot |= check_decl_local(fcx, l); } + ast::decl_local(ls) => for ls.each |l| { + bot |= check_decl_local(fcx, l); } - ast::decl_item(_) {/* ignore for now */ } + ast::decl_item(_) => {/* ignore for now */ } } } - ast::stmt_expr(expr, id) { + ast::stmt_expr(expr, id) => { node_id = id; bot = check_expr_with(fcx, expr, ty::mk_nil(fcx.ccx.tcx)); } - ast::stmt_semi(expr, id) { + ast::stmt_semi(expr, id) => { node_id = id; bot = check_expr(fcx, expr, none); } @@ -1956,9 +1953,9 @@ fn check_block_no_value(fcx: @fn_ctxt, blk: ast::blk) -> bool { fn check_block(fcx0: @fn_ctxt, blk: ast::blk) -> bool { let fcx = alt blk.node.rules { - ast::unchecked_blk { @fn_ctxt_({purity: ast::impure_fn with **fcx0}) } - ast::unsafe_blk { @fn_ctxt_({purity: ast::unsafe_fn with **fcx0}) } - ast::default_blk { fcx0 } + ast::unchecked_blk => @fn_ctxt_({purity: ast::impure_fn with **fcx0}), + ast::unsafe_blk => @fn_ctxt_({purity: ast::unsafe_fn with **fcx0}), + ast::default_blk => fcx0 }; do fcx.with_region_lb(blk.node.id) { let mut bot = false; @@ -1967,10 +1964,10 @@ fn check_block(fcx0: @fn_ctxt, blk: ast::blk) -> bool { if bot && !warned && alt s.node { ast::stmt_decl(@{node: ast::decl_local(_), _}, _) | - ast::stmt_expr(_, _) | ast::stmt_semi(_, _) { + ast::stmt_expr(_, _) | ast::stmt_semi(_, _) => { true } - _ { false } + _ => false } { fcx.ccx.tcx.sess.span_warn(s.span, ~"unreachable statement"); warned = true; @@ -1978,8 +1975,8 @@ fn check_block(fcx0: @fn_ctxt, blk: ast::blk) -> bool { bot |= check_stmt(fcx, s); } alt blk.node.expr { - none { fcx.write_nil(blk.node.id); } - some(e) { + none => fcx.write_nil(blk.node.id), + some(e) => { if bot && !warned { fcx.ccx.tcx.sess.span_warn(e.span, ~"unreachable expression"); } @@ -2039,7 +2036,7 @@ fn check_enum_variants(ccx: @crate_ctxt, let mut variants = ~[]; for vs.each |v| { alt v.node.disr_expr { - some(e) { + some(e) => { let fcx = blank_fn_ctxt(ccx, rty, e.id); check_expr(fcx, e, none); let cty = fcx.expr_ty(e); @@ -2050,16 +2047,16 @@ fn check_enum_variants(ccx: @crate_ctxt, // the expression in an form that eval_const_expr can handle, so // we may still get an internal compiler error alt const_eval::eval_const_expr(ccx.tcx, e) { - const_eval::const_int(val) { + const_eval::const_int(val) => { disr_val = val as int; } - _ { + _ => { ccx.tcx.sess.span_err(e.span, ~"expected signed integer constant"); } } } - _ {} + _ => () } if vec::contains(disr_vals, disr_val) { ccx.tcx.sess.span_err(v.span, @@ -2083,11 +2080,11 @@ fn check_enum_variants(ccx: @crate_ctxt, let mut outer = true, did = local_def(id); if ty::type_structurally_contains(ccx.tcx, rty, |sty| { alt sty { - ty::ty_enum(id, _) if id == did { + ty::ty_enum(id, _) if id == did => { if outer { outer = false; false } else { true } } - _ { false } + _ => false } }) { ccx.tcx.sess.span_err(sp, ~"illegal recursive enum type; \ @@ -2114,8 +2111,8 @@ fn self_ref(fcx: @fn_ctxt, id: ast::node_id) -> bool { fn lookup_local(fcx: @fn_ctxt, sp: span, id: ast::node_id) -> tv_vid { alt fcx.locals.find(id) { - some(x) { x } - _ { + some(x) => x, + _ => { fcx.ccx.tcx.sess.span_fatal(sp, ~"internal error looking up a local var") } @@ -2131,27 +2128,27 @@ fn ty_param_bounds_and_ty_for_def(fcx: @fn_ctxt, sp: span, defn: ast::def) -> ty_param_bounds_and_ty { alt defn { - ast::def_arg(nid, _) { + ast::def_arg(nid, _) => { assert (fcx.locals.contains_key(nid)); let typ = ty::mk_var(fcx.ccx.tcx, lookup_local(fcx, sp, nid)); return no_params(typ); } - ast::def_local(nid, _) { + ast::def_local(nid, _) => { assert (fcx.locals.contains_key(nid)); let typ = ty::mk_var(fcx.ccx.tcx, lookup_local(fcx, sp, nid)); return no_params(typ); } - ast::def_self(_) { + ast::def_self(_) => { alt fcx.self_info { - some(self_info) { + some(self_info) => { return no_params(self_info.self_ty); } - none { + none => { fcx.ccx.tcx.sess.span_bug(sp, ~"def_self with no self_info"); } } } - ast::def_fn(id, ast::extern_fn) { + ast::def_fn(id, ast::extern_fn) => { // extern functions are just u8 pointers return { bounds: @~[], @@ -2165,40 +2162,40 @@ fn ty_param_bounds_and_ty_for_def(fcx: @fn_ctxt, sp: span, defn: ast::def) -> }; } - ast::def_fn(id, ast::unsafe_fn) { + ast::def_fn(id, ast::unsafe_fn) => { // Unsafe functions can only be touched in an unsafe context fcx.require_unsafe(sp, ~"access to unsafe function"); return ty::lookup_item_type(fcx.ccx.tcx, id); } ast::def_fn(id, _) | ast::def_const(id) | - ast::def_variant(_, id) | ast::def_class(id, _) { + ast::def_variant(_, id) | ast::def_class(id, _) => { return ty::lookup_item_type(fcx.ccx.tcx, id); } - ast::def_binding(nid, _) { + ast::def_binding(nid, _) => { assert (fcx.locals.contains_key(nid)); let typ = ty::mk_var(fcx.ccx.tcx, lookup_local(fcx, sp, nid)); return no_params(typ); } - ast::def_ty(_) | ast::def_prim_ty(_) { + ast::def_ty(_) | ast::def_prim_ty(_) => { fcx.ccx.tcx.sess.span_fatal(sp, ~"expected value but found type"); } - ast::def_upvar(_, inner, _) { + ast::def_upvar(_, inner, _) => { return ty_param_bounds_and_ty_for_def(fcx, sp, *inner); } - ast::def_ty_param(did, n) { + ast::def_ty_param(did, n) => { return no_params(ty::mk_param(fcx.ccx.tcx, n, did)); } - ast::def_mod(*) | ast::def_foreign_mod(*) { + ast::def_mod(*) | ast::def_foreign_mod(*) => { fcx.ccx.tcx.sess.span_fatal(sp, ~"expected value but found module"); } - ast::def_use(*) { + ast::def_use(*) => { fcx.ccx.tcx.sess.span_fatal(sp, ~"expected value but found use"); } - ast::def_region(*) { + ast::def_region(*) => { fcx.ccx.tcx.sess.span_fatal(sp, ~"expected value but found region"); } - ast::def_typaram_binder(*) { + ast::def_typaram_binder(*) => { fcx.ccx.tcx.sess.span_fatal(sp, ~"expected value but found type \ parameter"); } @@ -2262,8 +2259,8 @@ fn instantiate_path(fcx: @fn_ctxt, // resolution is possible, then an error is reported. fn structurally_resolved_type(fcx: @fn_ctxt, sp: span, tp: ty::t) -> ty::t { alt infer::resolve_type(fcx.infcx, tp, force_tvar) { - result::ok(t_s) if !ty::type_is_var(t_s) { return t_s; } - _ { + result::ok(t_s) if !ty::type_is_var(t_s) => return t_s, + _ => { fcx.ccx.tcx.sess.span_fatal (sp, ~"the type of this value must be known in this context"); } @@ -2293,27 +2290,25 @@ fn type_is_c_like_enum(fcx: @fn_ctxt, sp: span, typ: ty::t) -> bool { fn ast_expr_vstore_to_vstore(fcx: @fn_ctxt, e: @ast::expr, n: uint, v: ast::vstore) -> ty::vstore { alt v { - ast::vstore_fixed(none) { ty::vstore_fixed(n) } - ast::vstore_fixed(some(u)) { + ast::vstore_fixed(none) => ty::vstore_fixed(n), + ast::vstore_fixed(some(u)) => { if n != u { let s = fmt!{"fixed-size sequence mismatch: %u vs. %u",u, n}; fcx.ccx.tcx.sess.span_err(e.span,s); } ty::vstore_fixed(u) } - ast::vstore_uniq { ty::vstore_uniq } - ast::vstore_box { ty::vstore_box } - ast::vstore_slice(a_r) { - alt fcx.block_region() { - result::ok(b_r) { + ast::vstore_uniq => ty::vstore_uniq, + ast::vstore_box => ty::vstore_box, + ast::vstore_slice(a_r) => alt fcx.block_region() { + result::ok(b_r) => { let rscope = in_anon_rscope(fcx, b_r); let r = astconv::ast_region_to_region(fcx, rscope, e.span, a_r); ty::vstore_slice(r) - } - result::err(msg) { + } + result::err(msg) => { fcx.ccx.tcx.sess.span_err(e.span, msg); ty::vstore_slice(ty::re_static) - } } } } @@ -2332,8 +2327,8 @@ fn check_bounds_are_used(ccx: @crate_ctxt, |_r| {}, |t| { alt ty::get(t).struct { - ty::ty_param({idx, _}) { tps_used[idx] = true; } - _ { } + ty::ty_param({idx, _}) => { tps_used[idx] = true; } + _ => () } true }); @@ -2356,34 +2351,34 @@ fn check_intrinsic_type(ccx: @crate_ctxt, it: @ast::foreign_item) { let tcx = ccx.tcx; let (n_tps, inputs, output) = alt *it.ident { ~"size_of" | - ~"pref_align_of" | ~"min_align_of" { (1u, ~[], ty::mk_uint(ccx.tcx)) } - ~"init" { (1u, ~[], param(ccx, 0u)) } - ~"forget" { (1u, ~[arg(ast::by_move, param(ccx, 0u))], - ty::mk_nil(tcx)) } - ~"reinterpret_cast" { (2u, ~[arg(ast::by_ref, param(ccx, 0u))], - param(ccx, 1u)) } - ~"addr_of" { (1u, ~[arg(ast::by_ref, param(ccx, 0u))], - ty::mk_imm_ptr(tcx, param(ccx, 0u))) } - ~"move_val" | ~"move_val_init" { + ~"pref_align_of" | ~"min_align_of" => (1u, ~[], ty::mk_uint(ccx.tcx)), + ~"init" => (1u, ~[], param(ccx, 0u)), + ~"forget" => (1u, ~[arg(ast::by_move, param(ccx, 0u))], + ty::mk_nil(tcx)), + ~"reinterpret_cast" => (2u, ~[arg(ast::by_ref, param(ccx, 0u))], + param(ccx, 1u)), + ~"addr_of" => (1u, ~[arg(ast::by_ref, param(ccx, 0u))], + ty::mk_imm_ptr(tcx, param(ccx, 0u))), + ~"move_val" | ~"move_val_init" => { (1u, ~[arg(ast::by_mutbl_ref, param(ccx, 0u)), - arg(ast::by_move, param(ccx, 0u))], + arg(ast::by_move, param(ccx, 0u))], ty::mk_nil(tcx)) } - ~"needs_drop" { (1u, ~[], ty::mk_bool(tcx)) } + ~"needs_drop" => (1u, ~[], ty::mk_bool(tcx)), ~"atomic_xchng" | ~"atomic_add" | ~"atomic_sub" | ~"atomic_xchng_acq" | ~"atomic_add_acq" | ~"atomic_sub_acq" | - ~"atomic_xchng_rel" | ~"atomic_add_rel" | ~"atomic_sub_rel" { + ~"atomic_xchng_rel" | ~"atomic_add_rel" | ~"atomic_sub_rel" => { (0u, ~[arg(ast::by_mutbl_ref, ty::mk_int(tcx)), arg(ast::by_val, ty::mk_int(tcx))], ty::mk_int(tcx)) } - ~"get_tydesc" { + ~"get_tydesc" => { // FIXME (#2712): return *intrinsic::tydesc, not *() (1u, ~[], ty::mk_nil_ptr(tcx)) } - ~"visit_tydesc" { + ~"visit_tydesc" => { assert ccx.tcx.intrinsic_defs.contains_key(@~"tydesc"); assert ccx.tcx.intrinsic_defs.contains_key(@~"ty_visitor"); let (_, tydesc_ty) = ccx.tcx.intrinsic_defs.get(@~"tydesc"); @@ -2393,7 +2388,7 @@ fn check_intrinsic_type(ccx: @crate_ctxt, it: @ast::foreign_item) { (0u, ~[arg(ast::by_val, td_ptr), arg(ast::by_ref, visitor_trait)], ty::mk_nil(tcx)) } - ~"frame_address" { + ~"frame_address" => { let fty = ty::mk_fn(ccx.tcx, { purity: ast::impure_fn, proto: ast::proto_block, @@ -2408,7 +2403,7 @@ fn check_intrinsic_type(ccx: @crate_ctxt, it: @ast::foreign_item) { }); (0u, ~[arg(ast::by_ref, fty)], ty::mk_nil(tcx)) } - other { + other => { tcx.sess.span_err(it.span, ~"unrecognized intrinsic function: `" + other + ~"`"); return; diff --git a/src/rustc/middle/typeck/check/alt.rs b/src/rustc/middle/typeck/check/alt.rs index 0863d82ef8c..316ef5a8927 100644 --- a/src/rustc/middle/typeck/check/alt.rs +++ b/src/rustc/middle/typeck/check/alt.rs @@ -30,8 +30,8 @@ fn check_alt(fcx: @fn_ctxt, let mut arm_non_bot = false; for arms.each |arm| { alt arm.guard { - some(e) { check_expr_with(fcx, e, ty::mk_bool(tcx)); } - none { } + some(e) => { check_expr_with(fcx, e, ty::mk_bool(tcx)); }, + none => () } if !check_block(fcx, arm.body) { arm_non_bot = true; } let bty = fcx.node_ty(arm.body.node.id); @@ -69,7 +69,7 @@ fn check_pat_variant(pcx: pat_ctxt, pat: @ast::pat, path: @ast::path, // Take the enum type params out of `expected`. alt structure_of(pcx.fcx, pat.span, expected) { - ty::ty_enum(_, expected_substs) { + ty::ty_enum(_, expected_substs) => { // check that the type of the value being matched is a subtype // of the type of the pattern: let pat_ty = fcx.node_ty(pat.id); @@ -83,8 +83,9 @@ fn check_pat_variant(pcx: pat_ctxt, pat: @ast::pat, path: @ast::path, vinfo.args.map(|t| { ty::subst(tcx, expected_substs, t) }) }; let arg_len = arg_types.len(), subpats_len = alt subpats { - none { arg_len } - some(ps) { ps.len() }}; + none => arg_len, + some(ps) => ps.len() + }; if arg_len > 0u { // N-ary variant. if arg_len != subpats_len { @@ -111,7 +112,7 @@ fn check_pat_variant(pcx: pat_ctxt, pat: @ast::pat, path: @ast::path, else { ~"s" }}); } } - _ { + _ => { tcx.sess.span_fatal (pat.span, fmt!{"mismatched types: expected enum but found `%s`", @@ -127,14 +128,14 @@ fn check_pat(pcx: pat_ctxt, pat: @ast::pat, expected: ty::t) { let tcx = pcx.fcx.ccx.tcx; alt pat.node { - ast::pat_wild { + ast::pat_wild => { fcx.write_ty(pat.id, expected); } - ast::pat_lit(lt) { + ast::pat_lit(lt) => { check_expr_with(fcx, lt, expected); fcx.write_ty(pat.id, fcx.expr_ty(lt)); } - ast::pat_range(begin, end) { + ast::pat_range(begin, end) => { check_expr_with(fcx, begin, expected); check_expr_with(fcx, end, expected); let b_ty = @@ -155,7 +156,7 @@ fn check_pat(pcx: pat_ctxt, pat: @ast::pat, expected: ty::t) { } fcx.write_ty(pat.id, b_ty); } - ast::pat_ident(_, name, sub) if !pat_is_variant(tcx.def_map, pat) { + ast::pat_ident(_, name, sub) if !pat_is_variant(tcx.def_map, pat) => { let vid = lookup_local(fcx, pat.span, pat.id); let mut typ = ty::mk_var(tcx, vid); demand::suptype(fcx, pat.span, expected, typ); @@ -167,20 +168,20 @@ fn check_pat(pcx: pat_ctxt, pat: @ast::pat, expected: ty::t) { } fcx.write_ty(pat.id, typ); alt sub { - some(p) { check_pat(pcx, p, expected); } - _ {} + some(p) => check_pat(pcx, p, expected), + _ => () } } - ast::pat_ident(_, path, c) { + ast::pat_ident(_, path, c) => { check_pat_variant(pcx, pat, path, some(~[]), expected); } - ast::pat_enum(path, subpats) { + ast::pat_enum(path, subpats) => { check_pat_variant(pcx, pat, path, subpats, expected); } - ast::pat_rec(fields, etc) { + ast::pat_rec(fields, etc) => { let ex_fields = alt structure_of(fcx, pat.span, expected) { - ty::ty_rec(fields) { fields } - _ { + ty::ty_rec(fields) => fields, + _ => { tcx.sess.span_fatal (pat.span, fmt!{"mismatched types: expected `%s` but found record", @@ -201,10 +202,10 @@ fn check_pat(pcx: pat_ctxt, pat: @ast::pat, expected: ty::t) { } for fields.each |f| { alt vec::find(ex_fields, |a| matches(f.ident, a)) { - some(field) { + some(field) => { check_pat(pcx, f.pat, field.mt.ty); } - none { + none => { tcx.sess.span_fatal(pat.span, fmt!{"mismatched types: did not \ expect a record with a field `%s`", @@ -214,10 +215,10 @@ fn check_pat(pcx: pat_ctxt, pat: @ast::pat, expected: ty::t) { } fcx.write_ty(pat.id, expected); } - ast::pat_tup(elts) { + ast::pat_tup(elts) => { let ex_elts = alt structure_of(fcx, pat.span, expected) { - ty::ty_tup(elts) { elts } - _ { + ty::ty_tup(elts) => elts, + _ => { tcx.sess.span_fatal (pat.span, fmt!{"mismatched types: expected `%s`, found tuple", @@ -239,13 +240,13 @@ fn check_pat(pcx: pat_ctxt, pat: @ast::pat, expected: ty::t) { fcx.write_ty(pat.id, expected); } - ast::pat_box(inner) { + ast::pat_box(inner) => { alt structure_of(fcx, pat.span, expected) { - ty::ty_box(e_inner) { + ty::ty_box(e_inner) => { check_pat(pcx, inner, e_inner.ty); fcx.write_ty(pat.id, expected); } - _ { + _ => { tcx.sess.span_fatal( pat.span, ~"mismatched types: expected `" + @@ -254,13 +255,13 @@ fn check_pat(pcx: pat_ctxt, pat: @ast::pat, expected: ty::t) { } } } - ast::pat_uniq(inner) { + ast::pat_uniq(inner) => { alt structure_of(fcx, pat.span, expected) { - ty::ty_uniq(e_inner) { + ty::ty_uniq(e_inner) => { check_pat(pcx, inner, e_inner.ty); fcx.write_ty(pat.id, expected); } - _ { + _ => { tcx.sess.span_fatal( pat.span, ~"mismatched types: expected `" + diff --git a/src/rustc/middle/typeck/check/demand.rs b/src/rustc/middle/typeck/check/demand.rs index 3718660472b..e1cf67e94e6 100644 --- a/src/rustc/middle/typeck/check/demand.rs +++ b/src/rustc/middle/typeck/check/demand.rs @@ -7,8 +7,8 @@ fn suptype(fcx: @fn_ctxt, sp: span, // n.b.: order of actual, expected is reversed alt infer::mk_subty(fcx.infcx, actual, expected) { - result::ok(()) { /* ok */ } - result::err(err) { + result::ok(()) => { /* ok */ } + result::err(err) => { fcx.report_mismatched_types(sp, expected, actual, err); } } @@ -18,8 +18,8 @@ fn eqtype(fcx: @fn_ctxt, sp: span, expected: ty::t, actual: ty::t) { alt infer::mk_eqty(fcx.infcx, actual, expected) { - result::ok(()) { /* ok */ } - result::err(err) { + result::ok(()) => { /* ok */ } + result::err(err) => { fcx.report_mismatched_types(sp, expected, actual, err); } } @@ -30,8 +30,8 @@ fn assign(fcx: @fn_ctxt, sp: span, borrow_lb: ast::node_id, expected: ty::t, expr: @ast::expr) { let expr_ty = fcx.expr_ty(expr); alt fcx.mk_assignty(expr, borrow_lb, expr_ty, expected) { - result::ok(()) { /* ok */ } - result::err(err) { + result::ok(()) => { /* ok */ } + result::err(err) => { fcx.report_mismatched_types(sp, expected, expr_ty, err); } } diff --git a/src/rustc/middle/typeck/check/method.rs b/src/rustc/middle/typeck/check/method.rs index efd2756a607..f86d5bf3a7a 100644 --- a/src/rustc/middle/typeck/check/method.rs +++ b/src/rustc/middle/typeck/check/method.rs @@ -91,10 +91,10 @@ class lookup { alt get_base_type_def_id(self.fcx.infcx, self.self_expr.span, self.self_ty) { - none { + none => { optional_inherent_methods = none; } - some(base_type_def_id) { + some(base_type_def_id) => { debug!{"(checking method) found base type"}; optional_inherent_methods = self.fcx.ccx.coherence_info.inherent_methods.find @@ -111,16 +111,16 @@ class lookup { loop { // First, see whether this is a bounded parameter. alt ty::get(self.self_ty).struct { - ty::ty_param(p) { + ty::ty_param(p) => { self.add_candidates_from_param(p.idx, p.def_id); } - ty::ty_trait(did, substs) { + ty::ty_trait(did, substs) => { self.add_candidates_from_trait(did, substs); } - ty::ty_class(did, substs) { + ty::ty_class(did, substs) => { self.add_candidates_from_class(did, substs); } - _ { } + _ => () } // if we found anything, stop now. otherwise continue to @@ -152,8 +152,8 @@ class lookup { // check whether we can autoderef and if so loop around again. alt ty::deref(self.tcx(), self.self_ty, false) { - none { break; } - some(mt) { + none => break, + some(mt) => { self.self_ty = mt.ty; self.derefs += 1u; } @@ -169,13 +169,13 @@ class lookup { for self.candidates.eachi |i, candidate| { alt candidate.entry.origin { - method_static(did) { + method_static(did) => { self.report_static_candidate(i, did); } - method_param(p) { + method_param(p) => { self.report_param_candidate(i, p.trait_id); } - method_trait(did, _) { + method_trait(did, _) => { self.report_trait_candidate(i, did); } } @@ -190,7 +190,7 @@ class lookup { fn report_static_candidate(idx: uint, did: ast::def_id) { let span = if did.crate == ast::local_crate { alt check self.tcx().items.get(did.node) { - ast_map::node_method(m, _, _) { m.span } + ast_map::node_method(m, _, _) => m.span, } } else { self.expr.span @@ -228,24 +228,24 @@ class lookup { for vec::each(*bounds) |bound| { let (iid, bound_substs) = alt bound { ty::bound_copy | ty::bound_send | ty::bound_const | - ty::bound_owned { + ty::bound_owned => { again; /* ok */ } - ty::bound_trait(bound_t) { + ty::bound_trait(bound_t) => { alt check ty::get(bound_t).struct { - ty::ty_trait(i, substs) { (i, substs) } + ty::ty_trait(i, substs) => (i, substs) } } }; let trt_methods = ty::trait_methods(tcx, iid); alt vec::position(*trt_methods, |m| m.ident == self.m_name) { - none { + none => { /* check next bound */ trait_bnd_idx += 1u; } - some(pos) { + some(pos) => { // Replace any appearance of `self` with the type of the // generic parameter itself. Note that this is the only case // where this replacement is necessary: in all other cases, we @@ -330,7 +330,7 @@ class lookup { fn ty_from_did(did: ast::def_id) -> ty::t { alt check ty::get(ty::lookup_item_type(self.tcx(), did).ty).struct { - ty::ty_fn(fty) { + ty::ty_fn(fty) => { ty::mk_fn(self.tcx(), {proto: ast::proto_box with fty}) } } @@ -409,8 +409,8 @@ class lookup { }; debug!{"matches = %?", matches}; alt matches { - result::err(_) { /* keep looking */ } - result::ok(_) { + result::err(_) => { /* keep looking */ } + result::ok(_) => { if !self.candidate_impls.contains_key(im.did) { let fty = self.ty_from_did(m.did); self.candidates.push( @@ -455,10 +455,10 @@ class lookup { // Add inherent methods. alt optional_inherent_methods { - none { + none => { // Continue. } - some(inherent_methods) { + some(inherent_methods) => { debug!{"(adding inherent and extension candidates) adding \ inherent candidates"}; for inherent_methods.each |implementation| { @@ -474,10 +474,10 @@ class lookup { // Add trait methods. alt self.fcx.ccx.trait_map.find(self.expr.id) { - none { + none => { // Should only happen for placement new right now. } - some(trait_ids) { + some(trait_ids) => { for (*trait_ids).each |trait_id| { debug!{"(adding inherent and extension candidates) \ trying trait: %s", @@ -485,10 +485,10 @@ class lookup { let coherence_info = self.fcx.ccx.coherence_info; alt coherence_info.extension_methods.find(trait_id) { - none { + none => { // Do nothing. } - some(extension_methods) { + some(extension_methods) => { for extension_methods.each |implementation| { debug!{"(adding inherent and extension \ candidates) adding impl %s", @@ -525,8 +525,8 @@ class lookup { // from an impl, this'll basically be a no-nop. alt self.fcx.mk_assignty(self.self_expr, self.borrow_lb, cand.self_ty, cand.rcvr_ty) { - result::ok(_) {} - result::err(_) { + result::ok(_) => (), + result::err(_) => { self.tcx().sess.span_bug( self.expr.span, fmt!{"%s was assignable to %s but now is not?", diff --git a/src/rustc/middle/typeck/check/regionck.rs b/src/rustc/middle/typeck/check/regionck.rs index 6e9293dd8e9..7871e1802ea 100644 --- a/src/rustc/middle/typeck/check/regionck.rs +++ b/src/rustc/middle/typeck/check/regionck.rs @@ -106,11 +106,11 @@ fn visit_pat(p: @ast::pat, &&rcx: @rcx, v: rvt) { let fcx = rcx.fcx; alt p.node { ast::pat_ident(_, path, _) - if !pat_util::pat_is_variant(fcx.ccx.tcx.def_map, p) { + if !pat_util::pat_is_variant(fcx.ccx.tcx.def_map, p) => { debug!{"visit_pat binding=%s", *path.idents[0]}; visit_node(p.id, p.span, rcx); } - _ {} + _ => () } visit::visit_pat(p, rcx, v); @@ -124,19 +124,19 @@ fn visit_expr(e: @ast::expr, &&rcx: @rcx, v: rvt) { debug!{"visit_expr(e=%s)", pprust::expr_to_str(e)}; alt e.node { - ast::expr_path(*) { + ast::expr_path(*) => { // Avoid checking the use of local variables, as we already // check their definitions. The def'n always encloses the // use. So if the def'n is enclosed by the region, then the // uses will also be enclosed (and otherwise, an error will // have been reported at the def'n site). alt lookup_def(rcx.fcx, e.span, e.id) { - ast::def_local(*) | ast::def_arg(*) | ast::def_upvar(*) { return; } - _ { } + ast::def_local(*) | ast::def_arg(*) | ast::def_upvar(*) => return, + _ => () } } - ast::expr_cast(source, _) { + ast::expr_cast(source, _) => { // Determine if we are casting `source` to an trait instance. // If so, we have to be sure that the type of the source obeys // the trait's region bound. @@ -154,7 +154,7 @@ fn visit_expr(e: @ast::expr, &&rcx: @rcx, v: rvt) { result::err(_) => { return; /* typeck will fail anyhow */ } result::ok(target_ty) => { alt ty::get(target_ty).struct { - ty::ty_trait(_, substs) { + ty::ty_trait(_, substs) => { let trait_region = alt substs.self_r { some(r) => {r} none => {ty::re_static} @@ -163,14 +163,14 @@ fn visit_expr(e: @ast::expr, &&rcx: @rcx, v: rvt) { constrain_regions_in_type(rcx, trait_region, e.span, source_ty); } - _ { } + _ => () } } }; } - _ { } + _ => () } if !visit_node(e.id, e.span, rcx) { return; } @@ -192,8 +192,8 @@ fn visit_node(id: ast::node_id, span: span, rcx: @rcx) -> bool { // is going to fail anyway, so just stop here and let typeck // report errors later on in the writeback phase. let ty = alt rcx.resolve_node_type(id) { - result::err(_) { return true; } - result::ok(ty) { ty } + result::err(_) => return true, + result::ok(ty) => ty }; // find the region where this expr evaluation is taking place @@ -233,18 +233,18 @@ fn constrain_regions_in_type( ppaux::region_to_str(tcx, region)}; alt region { - ty::re_bound(_) { + ty::re_bound(_) => { // a bound region is one which appears inside an fn type. // (e.g., the `&` in `fn(&T)`). Such regions need not be // constrained by `encl_region` as they are placeholders // for regions that are as-yet-unknown. return; } - _ {} + _ => () } alt rcx.fcx.mk_subr(encl_region, region) { - result::err(_) { + result::err(_) => { let region1 = rcx.fcx.infcx.resolve_region_if_possible(region); tcx.sess.span_err( span, @@ -253,7 +253,7 @@ fn constrain_regions_in_type( ppaux::region_to_str(tcx, region1)}); rcx.errors_reported += 1u; } - result::ok(()) { + result::ok(()) => { } } } diff --git a/src/rustc/middle/typeck/check/regionmanip.rs b/src/rustc/middle/typeck/check/regionmanip.rs index e50ec14ccf9..aee2a62d947 100644 --- a/src/rustc/middle/typeck/check/regionmanip.rs +++ b/src/rustc/middle/typeck/check/regionmanip.rs @@ -13,8 +13,8 @@ fn replace_bound_regions_in_fn_ty( // Take self_info apart; the self_ty part is the only one we want // to update here. let self_ty = alt self_info { - some(s) { some(s.self_ty) } - none { none } + some(s) => some(s.self_ty), + none => none }; let mut all_tys = ty::tys_in_fn_ty(fn_ty); @@ -45,20 +45,16 @@ fn replace_bound_regions_in_fn_ty( // Glue updated self_ty back together with its original node_id. let new_self_info = alt self_info { - some(s) { - alt check t_self { - some(t) { - some({self_ty: t, node_id: s.node_id}) - } - // this 'none' case shouldn't happen - } + some(s) => alt check t_self { + some(t) => some({self_ty: t, node_id: s.node_id}) + // this 'none' case shouldn't happen } - none { none } + none => none }; return {isr: isr, self_info: new_self_info, - fn_ty: alt check ty::get(t_fn).struct { ty::ty_fn(o) {o} }}; + fn_ty: alt check ty::get(t_fn).struct { ty::ty_fn(o) => o }}; // Takes `isr`, a (possibly empty) mapping from in-scope region @@ -88,13 +84,13 @@ fn replace_bound_regions_in_fn_ty( r: ty::region) -> isr_alist { alt r { ty::re_free(_, _) | ty::re_static | ty::re_scope(_) | - ty::re_var(_) { + ty::re_var(_) => { isr } - ty::re_bound(br) { + ty::re_bound(br) => { alt isr.find(br) { - some(_) { isr } - none { @cons((br, to_r(br)), isr) } + some(_) => isr, + none => @cons((br, to_r(br)), isr) } } } @@ -132,18 +128,18 @@ fn replace_bound_regions_in_fn_ty( // As long as we are not within a fn() type, `&T` is // mapped to the free region anon_r. But within a fn // type, it remains bound. - ty::re_bound(ty::br_anon) if in_fn { r } + ty::re_bound(ty::br_anon) if in_fn => r, - ty::re_bound(br) { + ty::re_bound(br) => { alt isr.find(br) { // In most cases, all named, bound regions will be // mapped to some free region. - some(fr) { fr } + some(fr) => fr, // But in the case of a fn() type, there may be // named regions within that remain bound: - none if in_fn { r } - none { + none if in_fn => r, + none => { tcx.sess.bug( fmt!{"Bound region not found in \ in_scope_regions list: %s", @@ -156,7 +152,7 @@ fn replace_bound_regions_in_fn_ty( ty::re_static | ty::re_scope(_) | ty::re_free(_, _) | - ty::re_var(_) { r } + ty::re_var(_) => r } } } diff --git a/src/rustc/middle/typeck/check/vtable.rs b/src/rustc/middle/typeck/check/vtable.rs index a4b8bf021e1..e1d85828c13 100644 --- a/src/rustc/middle/typeck/check/vtable.rs +++ b/src/rustc/middle/typeck/check/vtable.rs @@ -6,7 +6,7 @@ import dvec::extensions; fn has_trait_bounds(tps: ~[ty::param_bounds]) -> bool { vec::any(tps, |bs| { vec::any(*bs, |b| { - alt b { ty::bound_trait(_) { true } _ { false } } + alt b { ty::bound_trait(_) => true, _ => false } }) }) } @@ -19,12 +19,12 @@ fn lookup_vtables(fcx: @fn_ctxt, sp: span, for substs.tps.each |ty| { for vec::each(*bounds[i]) |bound| { alt bound { - ty::bound_trait(i_ty) { + ty::bound_trait(i_ty) => { let i_ty = ty::subst(tcx, substs, i_ty); vec::push(result, lookup_vtable(fcx, sp, ty, i_ty, allow_unsafe)); } - _ {} + _ => () } } i += 1u; @@ -39,7 +39,7 @@ fn fixup_substs(fcx: @fn_ctxt, sp: span, let t = ty::mk_trait(tcx, id, substs); let t_f = fixup_ty(fcx, sp, t); alt check ty::get(t_f).struct { - ty::ty_trait(_, substs_f) { substs_f } + ty::ty_trait(_, substs_f) => substs_f, } } @@ -62,21 +62,21 @@ fn lookup_vtable(fcx: @fn_ctxt, sp: span, ty: ty::t, trait_ty: ty::t, let tcx = fcx.ccx.tcx; let (trait_id, trait_substs) = alt check ty::get(trait_ty).struct { - ty::ty_trait(did, substs) { (did, substs) } + ty::ty_trait(did, substs) => (did, substs) }; let ty = fixup_ty(fcx, sp, ty); alt ty::get(ty).struct { - ty::ty_param({idx: n, def_id: did}) { + ty::ty_param({idx: n, def_id: did}) => { let mut n_bound = 0u; for vec::each(*tcx.ty_param_bounds.get(did.node)) |bound| { alt bound { ty::bound_send | ty::bound_copy | ty::bound_const | - ty::bound_owned { + ty::bound_owned => { /* ignore */ } - ty::bound_trait(ity) { + ty::bound_trait(ity) => { alt check ty::get(ity).struct { - ty::ty_trait(idid, substs) { + ty::ty_trait(idid, substs) => { if trait_id == idid { debug!{"(checking vtable) @0 relating ty to trait ty with did %?", idid}; @@ -91,7 +91,7 @@ fn lookup_vtable(fcx: @fn_ctxt, sp: span, ty: ty::t, trait_ty: ty::t, } } - ty::ty_trait(did, substs) if trait_id == did { + ty::ty_trait(did, substs) if trait_id == did => { debug!{"(checking vtable) @1 relating ty to trait ty with did %?", did}; @@ -113,16 +113,16 @@ fn lookup_vtable(fcx: @fn_ctxt, sp: span, ty: ty::t, trait_ty: ty::t, return vtable_trait(did, substs.tps); } - _ { + _ => { let mut found = ~[]; let mut impls_seen = new_def_hash(); alt fcx.ccx.coherence_info.extension_methods.find(trait_id) { - none { + none => { // Nothing found. Continue. } - some(implementations) { + some(implementations) => { for uint::range(0, implementations.len()) |i| { let im = implementations[i]; @@ -138,8 +138,8 @@ fn lookup_vtable(fcx: @fn_ctxt, sp: span, ty: ty::t, trait_ty: ty::t, for vec::each(ty::impl_traits(tcx, im.did)) |of_ty| { // it must have the same id as the expected one alt ty::get(of_ty).struct { - ty::ty_trait(id, _) if id != trait_id { again; } - _ { /* ok */ } + ty::ty_trait(id, _) if id != trait_id => again, + _ => { /* ok */ } } // check whether the type unifies with the type @@ -148,8 +148,8 @@ fn lookup_vtable(fcx: @fn_ctxt, sp: span, ty: ty::t, trait_ty: ty::t, impl_self_ty(fcx, im.did); let im_bs = ty::lookup_item_type(tcx, im.did).bounds; alt fcx.mk_subty(ty, for_ty) { - result::err(_) { again; } - result::ok(()) { } + result::err(_) => again, + result::ok(()) => () } // check that desired trait type unifies @@ -177,9 +177,9 @@ fn lookup_vtable(fcx: @fn_ctxt, sp: span, ty: ty::t, trait_ty: ty::t, } alt found.len() { - 0u { /* fallthrough */ } - 1u { return found[0]; } - _ { + 0u => { /* fallthrough */ } + 1u => { return found[0]; } + _ => { fcx.ccx.tcx.sess.span_err( sp, ~"multiple applicable methods in scope"); return found[0]; @@ -197,8 +197,8 @@ fn lookup_vtable(fcx: @fn_ctxt, sp: span, ty: ty::t, trait_ty: ty::t, fn fixup_ty(fcx: @fn_ctxt, sp: span, ty: ty::t) -> ty::t { let tcx = fcx.ccx.tcx; alt resolve_type(fcx.infcx, ty, resolve_all | force_all) { - result::ok(new_type) { new_type } - result::err(e) { + result::ok(new_type) => new_type, + result::err(e) => { tcx.sess.span_fatal( sp, fmt!{"cannot determine a type \ @@ -218,7 +218,7 @@ fn connect_trait_tps(fcx: @fn_ctxt, sp: span, impl_tys: ~[ty::t], debug!{"(connect trait tps) trait type is %?, impl did is %?", ty::get(trait_ty).struct, impl_did}; alt check ty::get(trait_ty).struct { - ty::ty_trait(_, substs) { + ty::ty_trait(_, substs) => { vec::iter2(substs.tps, trait_tys, |a, b| demand::suptype(fcx, sp, a, b)); } @@ -228,9 +228,9 @@ fn connect_trait_tps(fcx: @fn_ctxt, sp: span, impl_tys: ~[ty::t], fn resolve_expr(ex: @ast::expr, &&fcx: @fn_ctxt, v: visit::vt<@fn_ctxt>) { let cx = fcx.ccx; alt ex.node { - ast::expr_path(*) { + ast::expr_path(*) => { alt fcx.opt_node_ty_substs(ex.id) { - some(substs) { + some(substs) => { let did = ast_util::def_id_of_def(cx.tcx.def_map.get(ex.id)); let item_ty = ty::lookup_item_type(cx.tcx, did); if has_trait_bounds(*item_ty.bounds) { @@ -241,20 +241,20 @@ fn resolve_expr(ex: @ast::expr, &&fcx: @fn_ctxt, v: visit::vt<@fn_ctxt>) { false)); } } - _ {} + _ => () } } // Must resolve bounds on methods with bounded params ast::expr_field(*) | ast::expr_binary(*) | ast::expr_unary(*) | ast::expr_assign_op(*) | - ast::expr_index(*) { + ast::expr_index(*) => { alt cx.method_map.find(ex.id) { - some({origin: method_static(did), _}) { + some({origin: method_static(did), _}) => { let bounds = ty::lookup_item_type(cx.tcx, did).bounds; if has_trait_bounds(*bounds) { let callee_id = alt ex.node { - ast::expr_field(_, _, _) { ex.id } - _ { ex.callee_id } + ast::expr_field(_, _, _) => ex.id, + _ => ex.callee_id }; let substs = fcx.node_ty_substs(callee_id); cx.vtable_map.insert(callee_id, lookup_vtables(fcx, @@ -264,13 +264,13 @@ fn resolve_expr(ex: @ast::expr, &&fcx: @fn_ctxt, v: visit::vt<@fn_ctxt>) { false)); } } - _ {} + _ => () } } - ast::expr_cast(src, _) { + ast::expr_cast(src, _) => { let target_ty = fcx.expr_ty(ex); alt ty::get(target_ty).struct { - ty::ty_trait(*) { + ty::ty_trait(*) => { /* Look up vtables for the type we're casting to, passing in the source and target type @@ -283,10 +283,10 @@ fn resolve_expr(ex: @ast::expr, &&fcx: @fn_ctxt, v: visit::vt<@fn_ctxt>) { */ cx.vtable_map.insert(ex.id, @~[vtable]); } - _ {} + _ => () } } - _ {} + _ => () } visit::visit_expr(ex, fcx, v); } diff --git a/src/rustc/middle/typeck/check/writeback.rs b/src/rustc/middle/typeck/check/writeback.rs index 84d05a8aee2..bafcfc4855d 100644 --- a/src/rustc/middle/typeck/check/writeback.rs +++ b/src/rustc/middle/typeck/check/writeback.rs @@ -11,8 +11,8 @@ fn resolve_type_vars_in_type(fcx: @fn_ctxt, sp: span, typ: ty::t) -> option<ty::t> { if !ty::type_needs_infer(typ) { return some(typ); } alt resolve_type(fcx.infcx, typ, resolve_all | force_all) { - result::ok(new_type) { return some(new_type); } - result::err(e) { + result::ok(new_type) => return some(new_type), + result::err(e) => { if !fcx.ccx.tcx.sess.has_errors() { fcx.ccx.tcx.sess.span_err( sp, @@ -29,27 +29,27 @@ fn resolve_type_vars_for_node(wbcx: wb_ctxt, sp: span, id: ast::node_id) let fcx = wbcx.fcx, tcx = fcx.ccx.tcx; let n_ty = fcx.node_ty(id); alt resolve_type_vars_in_type(fcx, sp, n_ty) { - none { + none => { wbcx.success = false; return none; } - some(t) { + some(t) => { debug!{"resolve_type_vars_for_node(id=%d, n_ty=%s, t=%s)", id, ty_to_str(tcx, n_ty), ty_to_str(tcx, t)}; write_ty_to_tcx(tcx, id, t); alt fcx.opt_node_ty_substs(id) { - some(substs) { + some(substs) => { let mut new_tps = ~[]; for substs.tps.each |subst| { alt resolve_type_vars_in_type(fcx, sp, subst) { - some(t) { vec::push(new_tps, t); } - none { wbcx.success = false; return none; } + some(t) => vec::push(new_tps, t), + none => { wbcx.success = false; return none; } } } write_substs_to_tcx(tcx, id, new_tps); } - none {} + none => () } return some(t); } @@ -82,29 +82,29 @@ fn visit_expr(e: @ast::expr, wbcx: wb_ctxt, v: wb_vt) { resolve_type_vars_for_node(wbcx, e.span, e.id); alt e.node { ast::expr_fn(_, decl, _, _) | - ast::expr_fn_block(decl, _, _) { + ast::expr_fn_block(decl, _, _) => { do vec::iter(decl.inputs) |input| { let r_ty = resolve_type_vars_for_node(wbcx, e.span, input.id); // Just in case we never constrained the mode to anything, // constrain it to the default for the type in question. alt (r_ty, input.mode) { - (some(t), ast::infer(_)) { + (some(t), ast::infer(_)) => { let tcx = wbcx.fcx.ccx.tcx; let m_def = ty::default_arg_mode_for_ty(t); ty::set_default_mode(tcx, input.mode, m_def); } - _ {} + _ => () } } } ast::expr_binary(*) | ast::expr_unary(*) | ast::expr_assign_op(*) - | ast::expr_index(*) { + | ast::expr_index(*) => { maybe_resolve_type_vars_for_node(wbcx, e.span, e.callee_id); } - _ { } + _ => () } visit::visit_expr(e, wbcx, v); } @@ -128,13 +128,13 @@ fn visit_local(l: @ast::local, wbcx: wb_ctxt, v: wb_vt) { let var_id = lookup_local(wbcx.fcx, l.span, l.node.id); let var_ty = ty::mk_var(wbcx.fcx.tcx(), var_id); alt resolve_type(wbcx.fcx.infcx, var_ty, resolve_all | force_all) { - result::ok(lty) { + result::ok(lty) => { debug!{"Type for local %s (id %d) resolved to %s", pat_to_str(l.node.pat), l.node.id, wbcx.fcx.infcx.ty_to_str(lty)}; write_ty_to_tcx(wbcx.fcx.ccx.tcx, l.node.id, lty); } - result::err(e) { + result::err(e) => { wbcx.fcx.ccx.tcx.sess.span_err( l.span, fmt!{"cannot determine a type \ diff --git a/src/rustc/middle/typeck/coherence.rs b/src/rustc/middle/typeck/coherence.rs index 4de713030d9..74f9b6c3061 100644 --- a/src/rustc/middle/typeck/coherence.rs +++ b/src/rustc/middle/typeck/coherence.rs @@ -43,10 +43,10 @@ fn get_base_type(inference_context: infer_ctxt, span: span, original_type: t) alt resolve_type(inference_context, original_type, resolve_ivar) { - ok(resulting_type) if !type_is_var(resulting_type) { + ok(resulting_type) if !type_is_var(resulting_type) => { resolved_type = resulting_type; } - _ { + _ => { inference_context.tcx.sess.span_fatal(span, ~"the type of this value \ must be known in order \ @@ -59,13 +59,13 @@ fn get_base_type(inference_context: infer_ctxt, span: span, original_type: t) ty_box(base_mutability_and_type) | ty_uniq(base_mutability_and_type) | ty_ptr(base_mutability_and_type) | - ty_rptr(_, base_mutability_and_type) { + ty_rptr(_, base_mutability_and_type) => { debug!{"(getting base type) recurring"}; get_base_type(inference_context, span, base_mutability_and_type.ty) } - ty_enum(*) | ty_trait(*) | ty_class(*) { + ty_enum(*) | ty_trait(*) | ty_class(*) => { debug!{"(getting base type) found base type"}; some(resolved_type) } @@ -74,7 +74,7 @@ fn get_base_type(inference_context: infer_ctxt, span: span, original_type: t) ty_estr(*) | ty_evec(*) | ty_rec(*) | ty_fn(*) | ty_tup(*) | ty_var(*) | ty_var_integral(*) | ty_param(*) | ty_self | ty_type | ty_opaque_box | - ty_opaque_closure_ptr(*) | ty_unboxed_vec(*) { + ty_opaque_closure_ptr(*) | ty_unboxed_vec(*) => { debug!{"(getting base type) no base type; found %?", get(original_type).struct}; none @@ -89,17 +89,17 @@ fn get_base_type_def_id(inference_context: infer_ctxt, -> option<def_id> { alt get_base_type(inference_context, span, original_type) { - none { + none => { return none; } - some(base_type) { + some(base_type) => { alt get(base_type).struct { ty_enum(def_id, _) | ty_class(def_id, _) | - ty_trait(def_id, _) { + ty_trait(def_id, _) => { return some(def_id); } - _ { + _ => { fail ~"get_base_type() returned a type that wasn't an \ enum, class, or trait"; } @@ -161,13 +161,13 @@ class CoherenceChecker { debug!{"(checking coherence) item '%s'", *item.ident}; alt item.node { - item_impl(_, associated_traits, _, _) { + item_impl(_, associated_traits, _, _) => { self.check_implementation(item, associated_traits); } - item_class(_, associated_traits, _, _, _) { + item_class(_, associated_traits, _, _, _) => { self.check_implementation(item, associated_traits); } - _ { + _ => { // Nothing to do. } }; @@ -206,14 +206,14 @@ class CoherenceChecker { alt get_base_type_def_id(self.inference_context, item.span, self_type.ty) { - none { + none => { let session = self.crate_context.tcx.sess; session.span_err(item.span, ~"no base type found for inherent \ implementation; implement a \ trait instead"); } - some(_) { + some(_) => { // Nothing to do. } } @@ -238,10 +238,10 @@ class CoherenceChecker { alt get_base_type_def_id(self.inference_context, item.span, self_type.ty) { - none { + none => { // Nothing to do. } - some(base_type_def_id) { + some(base_type_def_id) => { let implementation = self.create_impl_from_item(item); self.add_inherent_method(base_type_def_id, implementation); @@ -256,12 +256,12 @@ class CoherenceChecker { alt self.crate_context.coherence_info.inherent_methods .find(base_def_id) { - none { + none => { implementation_list = @dvec(); self.crate_context.coherence_info.inherent_methods .insert(base_def_id, implementation_list); } - some(existing_implementation_list) { + some(existing_implementation_list) => { implementation_list = existing_implementation_list; } } @@ -274,12 +274,12 @@ class CoherenceChecker { alt self.crate_context.coherence_info.extension_methods .find(trait_id) { - none { + none => { implementation_list = @dvec(); self.crate_context.coherence_info.extension_methods .insert(trait_id, implementation_list); } - some(existing_implementation_list) { + some(existing_implementation_list) => { implementation_list = existing_implementation_list; } } @@ -364,7 +364,7 @@ class CoherenceChecker { visit_crate(*crate, (), mk_vt(@{ visit_item: |item, _context, visitor| { alt item.node { - item_mod(module_) { + item_mod(module_) => { // First, gather up all privileged types. let privileged_types = self.gather_privileged_types(module_.items); @@ -385,12 +385,12 @@ class CoherenceChecker { self.privileged_types.remove(privileged_type); } } - item_impl(_, associated_traits, _, _) { + item_impl(_, associated_traits, _, _) => { alt self.base_type_def_ids.find(local_def(item.id)) { - none { + none => { // Nothing to do. } - some(base_type_def_id) { + some(base_type_def_id) => { // Check to see whether the implementation is // in the scope of its base type. @@ -456,7 +456,7 @@ class CoherenceChecker { visit_item(item, (), visitor); } - _ { + _ => { visit_item(item, (), visitor); } } @@ -469,13 +469,13 @@ class CoherenceChecker { let results = @dvec(); for items.each |item| { alt item.node { - item_class(*) | item_enum(*) | item_trait(*) { + item_class(*) | item_enum(*) | item_trait(*) => { results.push(local_def(item.id)); } item_const(*) | item_fn(*) | item_mod(*) | item_foreign_mod(*) | item_ty(*) | item_impl(*) | - item_mac(*) { + item_mac(*) => { // Nothing to do. } } @@ -487,7 +487,7 @@ class CoherenceChecker { // Converts an implementation in the AST to an Impl structure. fn create_impl_from_item(item: @item) -> @Impl { alt item.node { - item_impl(ty_params, _, _, ast_methods) { + item_impl(ty_params, _, _, ast_methods) => { let mut methods = ~[]; for ast_methods.each |ast_method| { push(methods, @{ @@ -504,14 +504,14 @@ class CoherenceChecker { methods: methods }; } - item_class(ty_params, _, class_members, _, _) { + item_class(ty_params, _, class_members, _, _) => { let mut methods = ~[]; for class_members.each |class_member| { alt class_member.node { - instance_var(*) { + instance_var(*) => { // Nothing to do. } - class_method(ast_method) { + class_method(ast_method) => { push(methods, @{ did: local_def(ast_method.id), n_tps: ast_method.tps.len(), @@ -528,7 +528,7 @@ class CoherenceChecker { methods: methods }; } - _ { + _ => { self.crate_context.tcx.sess.span_bug(item.span, ~"can't convert a \ non-impl to an impl"); @@ -539,10 +539,10 @@ class CoherenceChecker { fn span_of_impl(implementation: @Impl) -> span { assert implementation.did.crate == local_crate; alt self.crate_context.tcx.items.find(implementation.did.node) { - some(node_item(item, _)) { + some(node_item(item, _)) => { return item.span; } - _ { + _ => { self.crate_context.tcx.sess.bug(~"span_of_impl() called on \ something that wasn't an \ impl!"); @@ -563,11 +563,11 @@ class CoherenceChecker { // Make sure we don't visit the same implementation // multiple times. alt impls_seen.find(implementation.did) { - none { + none => { // Good. Continue. impls_seen.insert(implementation.did, ()); } - some(_) { + some(_) => { // Skip this one. again; } @@ -585,7 +585,7 @@ class CoherenceChecker { alt get_base_type_def_id(self.inference_context, dummy_sp(), self_type.ty) { - none { + none => { let session = self.crate_context.tcx.sess; session.bug(fmt!{"no base type for external impl \ with no trait: %s (type %s)!", @@ -593,7 +593,7 @@ class CoherenceChecker { ty_to_str(self.crate_context.tcx, self_type.ty)}); } - some(_) { + some(_) => { // Nothing to do. } } @@ -602,10 +602,10 @@ class CoherenceChecker { // Record all the trait methods. for associated_traits.each |trait_type| { alt get(trait_type).struct { - ty_trait(trait_id, _) { + ty_trait(trait_id, _) => { self.add_trait_method(trait_id, implementation); } - _ { + _ => { self.crate_context.tcx.sess.bug(~"trait type \ returned is not a \ trait"); @@ -620,10 +620,10 @@ class CoherenceChecker { alt get_base_type_def_id(self.inference_context, dummy_sp(), self_type.ty) { - none { + none => { // Nothing to do. } - some(base_type_def_id) { + some(base_type_def_id) => { self.add_inherent_method(base_type_def_id, implementation); @@ -646,10 +646,10 @@ class CoherenceChecker { for each_path(crate_store, crate_number) |path_entry| { let module_def_id; alt path_entry.def_like { - dl_def(def_mod(def_id)) { + dl_def(def_mod(def_id)) => { module_def_id = def_id; } - dl_def(_) | dl_impl(_) | dl_field { + dl_def(_) | dl_impl(_) | dl_field => { // Skip this. again; } diff --git a/src/rustc/middle/typeck/collect.rs b/src/rustc/middle/typeck/collect.rs index 2a357decd2e..5a13d1d8efc 100644 --- a/src/rustc/middle/typeck/collect.rs +++ b/src/rustc/middle/typeck/collect.rs @@ -31,7 +31,7 @@ fn collect_item_types(ccx: @crate_ctxt, crate: @ast::crate) { for crate.node.module.items.each |crate_item| { if *crate_item.ident == ~"intrinsic" { alt crate_item.node { - ast::item_mod(m) { + ast::item_mod(m) => { for m.items.each |intrinsic_item| { let def_id = { crate: ast::local_crate, node: intrinsic_item.id }; @@ -54,7 +54,7 @@ fn collect_item_types(ccx: @crate_ctxt, crate: @ast::crate) { } } } - _ { } + _ => { } } break; } @@ -84,13 +84,13 @@ impl of ast_conv for @crate_ctxt { csearch::get_type(self.tcx, id) } else { alt self.tcx.items.find(id.node) { - some(ast_map::node_item(item, _)) { + some(ast_map::node_item(item, _)) => { ty_of_item(self, item) } - some(ast_map::node_foreign_item(foreign_item, _, _)) { + some(ast_map::node_foreign_item(foreign_item, _, _)) => { ty_of_foreign_item(self, foreign_item) } - x { + x => { self.tcx.sess.bug(fmt!{"unexpected sort of item \ in get_item_ty(): %?", x}); } @@ -146,19 +146,19 @@ fn ensure_trait_methods(ccx: @crate_ctxt, id: ast::node_id) { let tcx = ccx.tcx; let rp = tcx.region_paramd_items.contains_key(id); alt check tcx.items.get(id) { - ast_map::node_item(@{node: ast::item_trait(_, _, ms), _}, _) { + ast_map::node_item(@{node: ast::item_trait(_, _, ms), _}, _) => { store_methods::<ast::trait_method>(ccx, id, ms, |m| { alt m { - required(ty_m) { + required(ty_m) => { ty_of_ty_method(ccx, ty_m, rp) } - provided(m) { + provided(m) => { ty_of_method(ccx, m, rp) } } }); } - ast_map::node_item(@{node: ast::item_class(_,_,its,_,_), _}, _) { + ast_map::node_item(@{node: ast::item_class(_,_,its,_,_), _}, _) => { let (_,ms) = split_class_items(its); // All methods need to be stored, since lookup_method // relies on the same method cache for self-calls @@ -254,7 +254,7 @@ fn check_methods_against_trait(ccx: @crate_ctxt, } for vec::each(*ty::trait_methods(tcx, did)) |trait_m| { alt vec::find(impl_ms, |impl_m| trait_m.ident == impl_m.mty.ident) { - some({mty: impl_m, id, span}) { + some({mty: impl_m, id, span}) => { if impl_m.purity != trait_m.purity { ccx.tcx.sess.span_err( span, fmt!{"method `%s`'s purity does \ @@ -265,7 +265,7 @@ fn check_methods_against_trait(ccx: @crate_ctxt, ccx.tcx, span, impl_m, vec::len(tps), trait_m, tpt.substs, selfty); } - none { + none => { // If we couldn't find an implementation for trait_m in // the impl, then see if there was a default // implementation in the trait itself. If not, raise a @@ -273,24 +273,24 @@ fn check_methods_against_trait(ccx: @crate_ctxt, alt tcx.items.get(did.node) { ast_map::node_item( - @{node: ast::item_trait(_, _, trait_methods), _}, _) { + @{node: ast::item_trait(_, _, trait_methods), _}, _) => { let (_, provided_methods) = split_trait_methods(trait_methods); alt vec::find(provided_methods, |provided_method| provided_method.ident == trait_m.ident) { - some(m) { + some(m) => { // If there's a provided method with the name we // want, then we're fine; nothing else to do. } - none { + none => { tcx.sess.span_err( a_trait_ty.path.span, fmt!{"missing method `%s`", *trait_m.ident}); } } } - _ { + _ => { tcx.sess.bug(~"check_methods_against_trait(): trait_ref \ didn't refer to a trait"); } @@ -341,13 +341,13 @@ fn convert(ccx: @crate_ctxt, it: @ast::item) { debug!{"convert: item %s with id %d rp %b", *it.ident, it.id, rp}; alt it.node { // These don't define types. - ast::item_foreign_mod(_) | ast::item_mod(_) {} - ast::item_enum(variants, ty_params) { + ast::item_foreign_mod(_) | ast::item_mod(_) => {} + ast::item_enum(variants, ty_params) => { let tpt = ty_of_item(ccx, it); write_ty_to_tcx(tcx, it.id, tpt.ty); get_enum_variant_types(ccx, tpt.ty, variants, ty_params, rp); } - ast::item_impl(tps, trait_ref, selfty, ms) { + ast::item_impl(tps, trait_ref, selfty, ms) => { let i_bounds = ty_param_bounds(ccx, tps); let selfty = ccx.to_ty(type_rscope(rp), selfty); write_ty_to_tcx(tcx, it.id, selfty); @@ -361,7 +361,7 @@ fn convert(ccx: @crate_ctxt, it: @ast::item) { check_methods_against_trait(ccx, tps, rp, selfty, t, cms); } } - ast::item_trait(tps, _, trait_methods) { + ast::item_trait(tps, _, trait_methods) => { let tpt = ty_of_item(ccx, it); debug!{"item_trait(it.id=%d, tpt.ty=%s)", it.id, ty_to_str(tcx, tpt.ty)}; @@ -378,7 +378,7 @@ fn convert(ccx: @crate_ctxt, it: @ast::item) { // check_methods_against_trait(ccx, tps, rp, selfty, t, cms); // } } - ast::item_class(tps, trait_refs, members, m_ctor, m_dtor) { + ast::item_class(tps, trait_refs, members, m_ctor, m_dtor) => { // Write the class type let tpt = ty_of_item(ccx, it); write_ty_to_tcx(tcx, it.id, tpt.ty); @@ -435,7 +435,7 @@ fn convert(ccx: @crate_ctxt, it: @ast::item) { tcx.tcache.insert(local_def(trait_ref.impl_id), tpt); } } - _ { + _ => { // This call populates the type cache with the converted type // of the item in passing. All we have to do here is to write // it into the node type table. @@ -450,7 +450,7 @@ fn convert_foreign(ccx: @crate_ctxt, i: @ast::foreign_item) { // table. let tpt = ty_of_foreign_item(ccx, i); alt i.node { - ast::foreign_item_fn(_, _) { + ast::foreign_item_fn(_, _) => { write_ty_to_tcx(ccx.tcx, i.id, tpt.ty); ccx.tcx.tcache.insert(local_def(i.id), tpt); } @@ -495,19 +495,17 @@ fn instantiate_trait_ref(ccx: @crate_ctxt, t: @ast::trait_ref, rp: bool) let rscope = type_rscope(rp); alt lookup_def_tcx(ccx.tcx, t.path.span, t.ref_id) { - ast::def_ty(t_id) { + ast::def_ty(t_id) => { let tpt = astconv::ast_path_to_ty(ccx, rscope, t_id, t.path, t.ref_id); alt ty::get(tpt.ty).struct { - ty::ty_trait(*) { + ty::ty_trait(*) => { (t_id, tpt) } - _ { sess.span_fatal(sp, err); } + _ => sess.span_fatal(sp, err), } } - _ { - sess.span_fatal(sp, err); - } + _ => sess.span_fatal(sp, err) } } @@ -517,18 +515,18 @@ fn ty_of_item(ccx: @crate_ctxt, it: @ast::item) let def_id = local_def(it.id); let tcx = ccx.tcx; alt tcx.tcache.find(def_id) { - some(tpt) { return tpt; } - _ {} + some(tpt) => return tpt, + _ => {} } let rp = tcx.region_paramd_items.contains_key(it.id); alt it.node { - ast::item_const(t, _) { + ast::item_const(t, _) => { let typ = ccx.to_ty(empty_rscope, t); let tpt = no_params(typ); tcx.tcache.insert(local_def(it.id), tpt); return tpt; } - ast::item_fn(decl, tps, _) { + ast::item_fn(decl, tps, _) => { let bounds = ty_param_bounds(ccx, tps); let tofd = ty_of_fn_decl(ccx, empty_rscope, ast::proto_bare, decl, none); @@ -540,10 +538,10 @@ fn ty_of_item(ccx: @crate_ctxt, it: @ast::item) ccx.tcx.tcache.insert(local_def(it.id), tpt); return tpt; } - ast::item_ty(t, tps) { + ast::item_ty(t, tps) => { alt tcx.tcache.find(local_def(it.id)) { - some(tpt) { return tpt; } - none { } + some(tpt) => return tpt, + none => { } } let rp = tcx.region_paramd_items.contains_key(it.id); @@ -564,7 +562,7 @@ fn ty_of_item(ccx: @crate_ctxt, it: @ast::item) tcx.tcache.insert(local_def(it.id), tpt); return tpt; } - ast::item_enum(_, tps) { + ast::item_enum(_, tps) => { // Create a new generic polytype. let {bounds, substs} = mk_substs(ccx, tps, rp); let t = ty::mk_enum(tcx, local_def(it.id), substs); @@ -572,14 +570,14 @@ fn ty_of_item(ccx: @crate_ctxt, it: @ast::item) tcx.tcache.insert(local_def(it.id), tpt); return tpt; } - ast::item_trait(tps, _, ms) { + ast::item_trait(tps, _, ms) => { let {bounds, substs} = mk_substs(ccx, tps, rp); let t = ty::mk_trait(tcx, local_def(it.id), substs); let tpt = {bounds: bounds, rp: rp, ty: t}; tcx.tcache.insert(local_def(it.id), tpt); return tpt; } - ast::item_class(tps, _, _, _, _) { + ast::item_class(tps, _, _, _, _) => { let {bounds,substs} = mk_substs(ccx, tps, rp); let t = ty::mk_class(tcx, local_def(it.id), substs); let tpt = {bounds: bounds, rp: rp, ty: t}; @@ -587,15 +585,15 @@ fn ty_of_item(ccx: @crate_ctxt, it: @ast::item) return tpt; } ast::item_impl(*) | ast::item_mod(_) | - ast::item_foreign_mod(_) { fail; } - ast::item_mac(*) { fail ~"item macros unimplemented" } + ast::item_foreign_mod(_) => fail, + ast::item_mac(*) => fail ~"item macros unimplemented" } } fn ty_of_foreign_item(ccx: @crate_ctxt, it: @ast::foreign_item) -> ty::ty_param_bounds_and_ty { alt it.node { - ast::foreign_item_fn(fn_decl, params) { + ast::foreign_item_fn(fn_decl, params) => { return ty_of_foreign_fn_decl(ccx, fn_decl, params, local_def(it.id)); } @@ -608,17 +606,17 @@ fn ty_param_bounds(ccx: @crate_ctxt, param: ast::ty_param) -> ty::param_bounds { @do vec::flat_map(*param.bounds) |b| { alt b { - ast::bound_send { ~[ty::bound_send] } - ast::bound_copy { ~[ty::bound_copy] } - ast::bound_const { ~[ty::bound_const] } - ast::bound_owned { ~[ty::bound_owned] } - ast::bound_trait(t) { + ast::bound_send => ~[ty::bound_send], + ast::bound_copy => ~[ty::bound_copy], + ast::bound_const => ~[ty::bound_const], + ast::bound_owned => ~[ty::bound_owned], + ast::bound_trait(t) => { let ity = ast_ty_to_ty(ccx, empty_rscope, t); alt ty::get(ity).struct { - ty::ty_trait(*) { + ty::ty_trait(*) => { ~[ty::bound_trait(ity)] } - _ { + _ => { ccx.tcx.sess.span_err( t.span, ~"type parameter bounds must be \ trait types"); @@ -632,8 +630,8 @@ fn ty_param_bounds(ccx: @crate_ctxt, @do params.map |param| { alt ccx.tcx.ty_param_bounds.find(param.id) { - some(bs) { bs } - none { + some(bs) => bs, + none => { let bounds = compute_bounds(ccx, param); ccx.tcx.ty_param_bounds.insert(param.id, bounds); bounds diff --git a/src/rustc/middle/typeck/infer.rs b/src/rustc/middle/typeck/infer.rs index 4dec95eee30..d13a18dfcc6 100644 --- a/src/rustc/middle/typeck/infer.rs +++ b/src/rustc/middle/typeck/infer.rs @@ -250,28 +250,24 @@ fn convert_integral_ty_to_int_ty_set(tcx: ty::ctxt, t: ty::t) -> int_ty_set { alt get(t).struct { - ty_int(int_ty) { - alt int_ty { - ast::ty_i8 { int_ty_set(INT_TY_SET_i8) } - ast::ty_i16 { int_ty_set(INT_TY_SET_i16) } - ast::ty_i32 { int_ty_set(INT_TY_SET_i32) } - ast::ty_i64 { int_ty_set(INT_TY_SET_i64) } - ast::ty_i { int_ty_set(INT_TY_SET_i) } - ast::ty_char { tcx.sess.bug( - ~"char type passed to convert_integral_ty_to_int_ty_set()"); } - } + ty_int(int_ty) => alt int_ty { + ast::ty_i8 => int_ty_set(INT_TY_SET_i8), + ast::ty_i16 => int_ty_set(INT_TY_SET_i16), + ast::ty_i32 => int_ty_set(INT_TY_SET_i32), + ast::ty_i64 => int_ty_set(INT_TY_SET_i64), + ast::ty_i => int_ty_set(INT_TY_SET_i), + ast::ty_char => tcx.sess.bug( + ~"char type passed to convert_integral_ty_to_int_ty_set()") } - ty_uint(uint_ty) { - alt uint_ty { - ast::ty_u8 { int_ty_set(INT_TY_SET_u8) } - ast::ty_u16 { int_ty_set(INT_TY_SET_u16) } - ast::ty_u32 { int_ty_set(INT_TY_SET_u32) } - ast::ty_u64 { int_ty_set(INT_TY_SET_u64) } - ast::ty_u { int_ty_set(INT_TY_SET_u) } - } + ty_uint(uint_ty) => alt uint_ty { + ast::ty_u8 => int_ty_set(INT_TY_SET_u8), + ast::ty_u16 => int_ty_set(INT_TY_SET_u16), + ast::ty_u32 => int_ty_set(INT_TY_SET_u32), + ast::ty_u64 => int_ty_set(INT_TY_SET_u64), + ast::ty_u => int_ty_set(INT_TY_SET_u) } - _ { tcx.sess.bug(~"non-integral type passed to \ - convert_integral_ty_to_int_ty_set()"); } + _ => tcx.sess.bug(~"non-integral type passed to \ + convert_integral_ty_to_int_ty_set()") } } @@ -340,11 +336,11 @@ enum fixup_err { fn fixup_err_to_str(f: fixup_err) -> ~str { alt f { - unresolved_int_ty(_) { ~"unconstrained integral type" } - unresolved_ty(_) { ~"unconstrained type" } - cyclic_ty(_) { ~"cyclic type of infinite size" } - unresolved_region(_) { ~"unconstrained region" } - region_var_bound_by_region_var(r1, r2) { + unresolved_int_ty(_) => ~"unconstrained integral type", + unresolved_ty(_) => ~"unconstrained type", + cyclic_ty(_) => ~"cyclic type of infinite size", + unresolved_region(_) => ~"unconstrained region", + region_var_bound_by_region_var(r1, r2) => { fmt!{"region var %? bound by another region var %?; this is \ a bug in rustc", r1, r2} } @@ -460,8 +456,8 @@ trait cres_helpers<T> { impl methods<T:copy> of cres_helpers<T> for cres<T> { fn to_ures() -> ures { alt self { - ok(_v) { ok(()) } - err(e) { err(e) } + ok(_v) => ok(()), + err(e) => err(e) } } @@ -501,8 +497,8 @@ impl of to_str for ty::region { impl<V:copy to_str> of to_str for bound<V> { fn to_str(cx: infer_ctxt) -> ~str { alt self { - some(v) { v.to_str(cx) } - none { ~"none" } + some(v) => v.to_str(cx), + none => ~"none" } } } @@ -518,7 +514,7 @@ impl<T:copy to_str> of to_str for bounds<T> { impl of to_str for int_ty_set { fn to_str(_cx: infer_ctxt) -> ~str { alt self { - int_ty_set(v) { uint::to_str(v, 10u) } + int_ty_set(v) => uint::to_str(v, 10u) } } } @@ -526,9 +522,9 @@ impl of to_str for int_ty_set { impl<V:copy vid, T:copy to_str> of to_str for var_value<V,T> { fn to_str(cx: infer_ctxt) -> ~str { alt self { - redirect(vid) { fmt!{"redirect(%s)", vid.to_str()} } - root(pt, rk) { fmt!{"root(%s, %s)", pt.to_str(cx), - uint::to_str(rk, 10u)} } + redirect(vid) => fmt!{"redirect(%s)", vid.to_str()}, + root(pt, rk) => fmt!{"root(%s, %s)", pt.to_str(cx), + uint::to_str(rk, 10u)} } } } @@ -607,8 +603,8 @@ impl transaction_methods for infer_ctxt { debug!{"try(tvbl=%u, rbl=%u)", tvbl, rbl}; let r <- f(); alt r { - result::ok(_) { debug!{"try--ok"}; } - result::err(_) { + result::ok(_) => debug!{"try--ok"}, + result::err(_) => { debug!{"try--rollback"}; rollback_to(self.tvb, tvbl); rollback_to(self.rb, rbl); @@ -686,15 +682,15 @@ impl methods for infer_ctxt { fn resolve_type_vars_if_possible(typ: ty::t) -> ty::t { alt resolve_type(self, typ, resolve_all) { - result::ok(new_type) { return new_type; } - result::err(_) { return typ; } + result::ok(new_type) => return new_type, + result::err(_) => return typ } } fn resolve_region_if_possible(oldr: ty::region) -> ty::region { alt resolve_region(self, oldr, resolve_all) { - result::ok(newr) { return newr; } - result::err(_) { return oldr; } + result::ok(newr) => return newr, + result::err(_) => return oldr } } } @@ -719,12 +715,12 @@ impl unify_methods for infer_ctxt { let vid_u = vid.to_uint(); alt vb.vals.find(vid_u) { - none { + none => { self.tcx.sess.bug(fmt!{"failed lookup of vid `%u`", vid_u}); } - some(var_val) { + some(var_val) => { alt var_val { - redirect(vid) { + redirect(vid) => { let nde = self.get(vb, vid); if nde.root != vid { // Path compression @@ -732,7 +728,7 @@ impl unify_methods for infer_ctxt { } nde } - root(pt, rk) { + root(pt, rk) => { node({root: vid, possible_types: pt, rank: rk}) } } @@ -749,16 +745,10 @@ impl unify_methods for infer_ctxt { let _r = indenter(); alt (a, b) { - (none, none) { - ok(none) - } - (some(_), none) { - ok(a) - } - (none, some(_)) { - ok(b) - } - (some(v_a), some(v_b)) { + (none, none) => ok(none), + (some(_), none) => ok(a), + (none, some(_)) => ok(b), + (some(v_a), some(v_b)) => { do merge_op(v_a, v_b).chain |v| { ok(some(v)) } @@ -864,14 +854,14 @@ impl unify_methods for infer_ctxt { // If both A's UB and B's LB have already been bound to types, // see if we can make those types subtypes. alt (a_bounds.ub, b_bounds.lb) { - (some(a_ub), some(b_lb)) { + (some(a_ub), some(b_lb)) => { let r = self.try(|| a_ub.sub(self, b_lb)); alt r { - ok(()) { return result::ok(()); } - err(_) { /*fallthrough */ } + ok(()) => return result::ok(()), + err(_) => { /*fallthrough */ } } } - _ { /*fallthrough*/ } + _ => { /*fallthrough*/ } } // Otherwise, we need to merge A and B so as to guarantee that @@ -1035,10 +1025,10 @@ impl unify_methods for infer_ctxt { alt (a, b) { (none, none) | (some(_), none) | - (none, some(_)) { + (none, some(_)) => { uok() } - (some(t_a), some(t_b)) { + (some(t_a), some(t_b)) => { t_a.sub(self, t_b) } } @@ -1152,13 +1142,13 @@ impl methods for resolve_state { let rty = indent(|| self.resolve_type(typ) ); assert vec::is_empty(self.v_seen); alt self.err { - none { + none => { debug!{"Resolved to %s (modes=%x)", ty_to_str(self.infcx.tcx, rty), self.modes}; return ok(rty); } - some(e) { return err(e); } + some(e) => return err(e) } } @@ -1166,8 +1156,8 @@ impl methods for resolve_state { self.err = none; let resolved = indent(|| self.resolve_region(orig) ); alt self.err { - none {ok(resolved)} - some(e) {err(e)} + none => ok(resolved), + some(e) => err(e) } } @@ -1177,13 +1167,13 @@ impl methods for resolve_state { if !ty::type_needs_infer(typ) { return typ; } alt ty::get(typ).struct { - ty::ty_var(vid) { + ty::ty_var(vid) => { self.resolve_ty_var(vid) } - ty::ty_var_integral(vid) { + ty::ty_var_integral(vid) => { self.resolve_ty_var_integral(vid) } - _ { + _ => { if !self.should(resolve_rvar) && !self.should(resolve_nested_tvar) { // shortcircuit for efficiency @@ -1212,8 +1202,8 @@ impl methods for resolve_state { fn resolve_region(orig: ty::region) -> ty::region { debug!{"Resolve_region(%s)", orig.to_str(self.infcx)}; alt orig { - ty::re_var(rid) { self.resolve_region_var(rid) } - _ { orig } + ty::re_var(rid) => self.resolve_region_var(rid), + _ => orig } } @@ -1262,10 +1252,10 @@ impl methods for resolve_state { let bounds = nde.possible_types; let t1 = alt bounds { - { ub:_, lb:some(t) } if !type_is_bot(t) { self.resolve_type(t) } - { ub:some(t), lb:_ } { self.resolve_type(t) } - { ub:_, lb:some(t) } { self.resolve_type(t) } - { ub:none, lb:none } { + { ub:_, lb:some(t) } if !type_is_bot(t) => self.resolve_type(t), + { ub:some(t), lb:_ } => self.resolve_type(t), + { ub:_, lb:some(t) } => self.resolve_type(t), + { ub:none, lb:none } => { if self.should(force_tvar) { self.err = some(unresolved_ty(vid)); } @@ -1288,8 +1278,8 @@ impl methods for resolve_state { // If there's only one type in the set of possible types, then // that's the answer. alt single_type_contained_in(self.infcx.tcx, pt) { - some(t) { t } - none { + some(t) => t, + none => { if self.should(force_ivar) { // As a last resort, default to int. let ty = ty::mk_int(self.infcx.tcx); @@ -1362,12 +1352,10 @@ impl assignment for infer_ctxt { fn select(fst: option<ty::t>, snd: option<ty::t>) -> option<ty::t> { alt fst { - some(t) { some(t) } - none { - alt snd { - some(t) { some(t) } - none { none } - } + some(t) => some(t), + none => alt snd { + some(t) => some(t), + none => none } } } @@ -1377,11 +1365,11 @@ impl assignment for infer_ctxt { let _r = indenter(); alt (ty::get(a).struct, ty::get(b).struct) { - (ty::ty_bot, _) { + (ty::ty_bot, _) => { uok() } - (ty::ty_var(a_id), ty::ty_var(b_id)) { + (ty::ty_var(a_id), ty::ty_var(b_id)) => { let nde_a = self.get(self.tvb, a_id); let nde_b = self.get(self.tvb, b_id); let a_bounds = nde_a.possible_types; @@ -1392,7 +1380,7 @@ impl assignment for infer_ctxt { self.assign_tys_or_sub(anmnt, a, b, a_bnd, b_bnd) } - (ty::ty_var(a_id), _) { + (ty::ty_var(a_id), _) => { let nde_a = self.get(self.tvb, a_id); let a_bounds = nde_a.possible_types; @@ -1400,7 +1388,7 @@ impl assignment for infer_ctxt { self.assign_tys_or_sub(anmnt, a, b, a_bnd, some(b)) } - (_, ty::ty_var(b_id)) { + (_, ty::ty_var(b_id)) => { let nde_b = self.get(self.tvb, b_id); let b_bounds = nde_b.possible_types; @@ -1408,7 +1396,7 @@ impl assignment for infer_ctxt { self.assign_tys_or_sub(anmnt, a, b, some(a), b_bnd) } - (_, _) { + (_, _) => { self.assign_tys_or_sub(anmnt, a, b, some(a), some(b)) } } @@ -1426,44 +1414,44 @@ impl assignment for infer_ctxt { fn is_borrowable(v: ty::vstore) -> bool { alt v { - ty::vstore_fixed(_) | ty::vstore_uniq | ty::vstore_box { true } - ty::vstore_slice(_) { false } + ty::vstore_fixed(_) | ty::vstore_uniq | ty::vstore_box => true, + ty::vstore_slice(_) => false } } alt (a_bnd, b_bnd) { - (some(a_bnd), some(b_bnd)) { + (some(a_bnd), some(b_bnd)) => { alt (ty::get(a_bnd).struct, ty::get(b_bnd).struct) { - (ty::ty_box(mt_a), ty::ty_rptr(r_b, mt_b)) { + (ty::ty_box(mt_a), ty::ty_rptr(r_b, mt_b)) => { let nr_b = ty::mk_box(self.tcx, {ty: mt_b.ty, mutbl: m_const}); self.crosspollinate(anmnt, a, nr_b, mt_b.mutbl, r_b) } - (ty::ty_uniq(mt_a), ty::ty_rptr(r_b, mt_b)) { + (ty::ty_uniq(mt_a), ty::ty_rptr(r_b, mt_b)) => { let nr_b = ty::mk_uniq(self.tcx, {ty: mt_b.ty, mutbl: m_const}); self.crosspollinate(anmnt, a, nr_b, mt_b.mutbl, r_b) } (ty::ty_estr(vs_a), ty::ty_estr(ty::vstore_slice(r_b))) - if is_borrowable(vs_a) { + if is_borrowable(vs_a) => { let nr_b = ty::mk_estr(self.tcx, vs_a); self.crosspollinate(anmnt, a, nr_b, m_imm, r_b) } (ty::ty_evec(mt_a, vs_a), ty::ty_evec(mt_b, ty::vstore_slice(r_b))) - if is_borrowable(vs_a) { + if is_borrowable(vs_a) => { let nr_b = ty::mk_evec(self.tcx, {ty: mt_b.ty, mutbl: m_const}, vs_a); self.crosspollinate(anmnt, a, nr_b, mt_b.mutbl, r_b) } - _ { + _ => { self.sub_tys(a, b) } } } - _ { + _ => { self.sub_tys(a, b) } } @@ -1582,15 +1570,15 @@ fn super_substs<C:combine>( a: option<ty::region>, b: option<ty::region>) -> cres<option<ty::region>> { alt (a, b) { - (none, none) { + (none, none) => { ok(none) } - (some(a), some(b)) { + (some(a), some(b)) => { do infcx.eq_regions(a, b).then { ok(some(a)) } } - (_, _) { + (_, _) => { // If these two substitutions are for the same type (and // they should be), then the type should either // consistently have a region parameter or not have a @@ -1638,14 +1626,14 @@ fn super_self_tys<C:combine>( // *invariant* (otherwise the type system would be unsound). alt (a, b) { - (none, none) { + (none, none) => { ok(none) } - (some(a), some(b)) { + (some(a), some(b)) => { self.infcx().eq_tys(a, b).then(|| ok(some(a)) ) } (none, some(_)) | - (some(_), none) { + (some(_), none) => { // I think it should never happen that we unify two substs and // one of them has a self_ty and one doesn't...? I could be // wrong about this. @@ -1690,17 +1678,17 @@ fn super_vstores<C:combine>( a: ty::vstore, b: ty::vstore) -> cres<ty::vstore> { alt (a, b) { - (ty::vstore_slice(a_r), ty::vstore_slice(b_r)) { + (ty::vstore_slice(a_r), ty::vstore_slice(b_r)) => { do self.contraregions(a_r, b_r).chain |r| { ok(ty::vstore_slice(r)) } } - _ if a == b { + _ if a == b => { ok(a) } - _ { + _ => { err(ty::terr_vstores_differ(vk, b, a)) } } @@ -1749,7 +1737,7 @@ fn super_tys<C:combine>( (ty::ty_bot, _) | (_, ty::ty_bot) | (ty::ty_var(_), _) | - (_, ty::ty_var(_)) { + (_, ty::ty_var(_)) => { tcx.sess.bug( fmt!{"%s: bot and var types should have been handled (%s,%s)", self.tag(), @@ -1758,24 +1746,24 @@ fn super_tys<C:combine>( } // Have to handle these first - (ty::ty_var_integral(a_id), ty::ty_var_integral(b_id)) { + (ty::ty_var_integral(a_id), ty::ty_var_integral(b_id)) => { self.infcx().vars_integral(self.infcx().tvib, a_id, b_id) .then(|| ok(a) ) } (ty::ty_var_integral(a_id), ty::ty_int(_)) | - (ty::ty_var_integral(a_id), ty::ty_uint(_)) { + (ty::ty_var_integral(a_id), ty::ty_uint(_)) => { self.infcx().vart_integral(self.infcx().tvib, a_id, b) .then(|| ok(a) ) } (ty::ty_int(_), ty::ty_var_integral(b_id)) | - (ty::ty_uint(_), ty::ty_var_integral(b_id)) { + (ty::ty_uint(_), ty::ty_var_integral(b_id)) => { self.infcx().tvar_integral(self.infcx().tvib, a, b_id) .then(|| ok(a) ) } (ty::ty_int(_), _) | (ty::ty_uint(_), _) | - (ty::ty_float(_), _) { + (ty::ty_float(_), _) => { let as = ty::get(a).struct; let bs = ty::get(b).struct; if as == bs { @@ -1786,7 +1774,7 @@ fn super_tys<C:combine>( } (ty::ty_nil, _) | - (ty::ty_bool, _) { + (ty::ty_bool, _) => { let cfg = tcx.sess.targ_cfg; if ty::mach_sty(cfg, a) == ty::mach_sty(cfg, b) { ok(a) @@ -1795,50 +1783,50 @@ fn super_tys<C:combine>( } } - (ty::ty_param(a_p), ty::ty_param(b_p)) if a_p.idx == b_p.idx { + (ty::ty_param(a_p), ty::ty_param(b_p)) if a_p.idx == b_p.idx => { ok(a) } (ty::ty_enum(a_id, a_substs), ty::ty_enum(b_id, b_substs)) - if a_id == b_id { + if a_id == b_id => { do self.substs(a_substs, b_substs).chain |tps| { ok(ty::mk_enum(tcx, a_id, tps)) } } (ty::ty_trait(a_id, a_substs), ty::ty_trait(b_id, b_substs)) - if a_id == b_id { + if a_id == b_id => { do self.substs(a_substs, b_substs).chain |substs| { ok(ty::mk_trait(tcx, a_id, substs)) } } (ty::ty_class(a_id, a_substs), ty::ty_class(b_id, b_substs)) - if a_id == b_id { + if a_id == b_id => { do self.substs(a_substs, b_substs).chain |substs| { ok(ty::mk_class(tcx, a_id, substs)) } } - (ty::ty_box(a_mt), ty::ty_box(b_mt)) { + (ty::ty_box(a_mt), ty::ty_box(b_mt)) => { do self.mts(a_mt, b_mt).chain |mt| { ok(ty::mk_box(tcx, mt)) } } - (ty::ty_uniq(a_mt), ty::ty_uniq(b_mt)) { + (ty::ty_uniq(a_mt), ty::ty_uniq(b_mt)) => { do self.mts(a_mt, b_mt).chain |mt| { ok(ty::mk_uniq(tcx, mt)) } } - (ty::ty_ptr(a_mt), ty::ty_ptr(b_mt)) { + (ty::ty_ptr(a_mt), ty::ty_ptr(b_mt)) => { do self.mts(a_mt, b_mt).chain |mt| { ok(ty::mk_ptr(tcx, mt)) } } - (ty::ty_rptr(a_r, a_mt), ty::ty_rptr(b_r, b_mt)) { + (ty::ty_rptr(a_r, a_mt), ty::ty_rptr(b_r, b_mt)) => { do self.contraregions(a_r, b_r).chain |r| { do self.mts(a_mt, b_mt).chain |mt| { ok(ty::mk_rptr(tcx, r, mt)) @@ -1846,7 +1834,7 @@ fn super_tys<C:combine>( } } - (ty::ty_evec(a_mt, vs_a), ty::ty_evec(b_mt, vs_b)) { + (ty::ty_evec(a_mt, vs_a), ty::ty_evec(b_mt, vs_b)) => { do self.mts(a_mt, b_mt).chain |mt| { do self.vstores(ty::terr_vec, vs_a, vs_b).chain |vs| { ok(ty::mk_evec(tcx, mt, vs)) @@ -1854,13 +1842,13 @@ fn super_tys<C:combine>( } } - (ty::ty_estr(vs_a), ty::ty_estr(vs_b)) { + (ty::ty_estr(vs_a), ty::ty_estr(vs_b)) => { do self.vstores(ty::terr_str, vs_a, vs_b).chain |vs| { ok(ty::mk_estr(tcx,vs)) } } - (ty::ty_rec(as), ty::ty_rec(bs)) { + (ty::ty_rec(as), ty::ty_rec(bs)) => { if vec::same_length(as, bs) { map_vec2(as, bs, |a,b| { self.flds(a, b) @@ -1870,7 +1858,7 @@ fn super_tys<C:combine>( } } - (ty::ty_tup(as), ty::ty_tup(bs)) { + (ty::ty_tup(as), ty::ty_tup(bs)) => { if vec::same_length(as, bs) { map_vec2(as, bs, |a, b| self.tys(a, b) ) .chain(|ts| ok(ty::mk_tup(tcx, ts)) ) @@ -1879,13 +1867,13 @@ fn super_tys<C:combine>( } } - (ty::ty_fn(a_fty), ty::ty_fn(b_fty)) { + (ty::ty_fn(a_fty), ty::ty_fn(b_fty)) => { do self.fns(a_fty, b_fty).chain |fty| { ok(ty::mk_fn(tcx, fty)) } } - _ { err(ty::terr_sorts(b, a)) } + _ => err(ty::terr_sorts(b, a)) } } @@ -1910,22 +1898,22 @@ impl of combine for sub { b.to_str(self.infcx())}; do indent { alt (a, b) { - (ty::re_var(a_id), ty::re_var(b_id)) { + (ty::re_var(a_id), ty::re_var(b_id)) => { do self.infcx().vars(self.rb, a_id, b_id).then { ok(a) } } - (ty::re_var(a_id), _) { + (ty::re_var(a_id), _) => { do self.infcx().vart(self.rb, a_id, b).then { ok(a) } } - (_, ty::re_var(b_id)) { + (_, ty::re_var(b_id)) => { do self.infcx().tvar(self.rb, a, b_id).then { ok(a) } } - _ { + _ => { do self.lub().regions(a, b).compare(b) { ty::terr_regions_differ(b, a) } @@ -1942,12 +1930,12 @@ impl of combine for sub { } alt b.mutbl { - m_mutbl { + m_mutbl => { // If supertype is mut, subtype must match exactly // (i.e., invariant if mut): self.infcx().eq_tys(a.ty, b.ty).then(|| ok(a) ) } - m_imm | m_const { + m_imm | m_const => { // Otherwise we can be covariant: self.tys(a.ty, b.ty).chain(|_t| ok(a) ) } @@ -1978,22 +1966,22 @@ impl of combine for sub { if a == b { return ok(a); } do indent { alt (ty::get(a).struct, ty::get(b).struct) { - (ty::ty_bot, _) { + (ty::ty_bot, _) => { ok(a) } - (ty::ty_var(a_id), ty::ty_var(b_id)) { + (ty::ty_var(a_id), ty::ty_var(b_id)) => { self.infcx().vars(self.tvb, a_id, b_id).then(|| ok(a) ) } - (ty::ty_var(a_id), _) { + (ty::ty_var(a_id), _) => { self.infcx().vart(self.tvb, a_id, b).then(|| ok(a) ) } - (_, ty::ty_var(b_id)) { + (_, ty::ty_var(b_id)) => { self.infcx().tvar(self.tvb, a, b_id).then(|| ok(a) ) } - (_, ty::ty_bot) { + (_, ty::ty_bot) => { err(ty::terr_sorts(b, a)) } - _ { + _ => { super_tys(self, a, b) } } @@ -2090,11 +2078,11 @@ impl of combine for lub { }; alt m { - m_imm | m_const { + m_imm | m_const => { self.tys(a.ty, b.ty).chain(|t| ok({ty: t, mutbl: m}) ) } - m_mutbl { + m_mutbl => { self.infcx().try(|| { self.infcx().eq_tys(a.ty, b.ty).then(|| { ok({ty: a.ty, mutbl: m}) @@ -2126,22 +2114,18 @@ impl of combine for lub { fn purities(f1: purity, f2: purity) -> cres<purity> { alt (f1, f2) { - (unsafe_fn, _) | (_, unsafe_fn) {ok(unsafe_fn)} - (impure_fn, _) | (_, impure_fn) {ok(impure_fn)} - (extern_fn, _) | (_, extern_fn) {ok(extern_fn)} - (pure_fn, pure_fn) {ok(pure_fn)} + (unsafe_fn, _) | (_, unsafe_fn) => ok(unsafe_fn), + (impure_fn, _) | (_, impure_fn) => ok(impure_fn), + (extern_fn, _) | (_, extern_fn) => ok(extern_fn), + (pure_fn, pure_fn) => ok(pure_fn) } } fn ret_styles(r1: ret_style, r2: ret_style) -> cres<ret_style> { alt (r1, r2) { (ast::return_val, _) | - (_, ast::return_val) { - ok(ast::return_val) - } - (ast::noreturn, ast::noreturn) { - ok(ast::noreturn) - } + (_, ast::return_val) => ok(ast::return_val), + (ast::noreturn, ast::noreturn) => ok(ast::noreturn) } } @@ -2157,16 +2141,16 @@ impl of combine for lub { do indent { alt (a, b) { - (ty::re_static, _) | (_, ty::re_static) { + (ty::re_static, _) | (_, ty::re_static) => { ok(ty::re_static) // nothing lives longer than static } - (ty::re_var(_), _) | (_, ty::re_var(_)) { + (ty::re_var(_), _) | (_, ty::re_var(_)) => { lattice_rvars(self, a, b) } (f @ ty::re_free(f_id, _), ty::re_scope(s_id)) | - (ty::re_scope(s_id), f @ ty::re_free(f_id, _)) { + (ty::re_scope(s_id), f @ ty::re_free(f_id, _)) => { // A "free" region can be interpreted as "some region // at least as big as the block f_id". So, we can // reasonably compare free regions and scopes: @@ -2175,22 +2159,22 @@ impl of combine for lub { // if the free region's scope `f_id` is bigger than // the scope region `s_id`, then the LUB is the free // region itself: - some(r_id) if r_id == f_id { ok(f) } + some(r_id) if r_id == f_id => ok(f), // otherwise, we don't know what the free region is, // so we must conservatively say the LUB is static: - _ { ok(ty::re_static) } + _ => ok(ty::re_static) } } - (ty::re_scope(a_id), ty::re_scope(b_id)) { + (ty::re_scope(a_id), ty::re_scope(b_id)) => { // The region corresponding to an outer block is a // subtype of the region corresponding to an inner // block. let rm = self.infcx().tcx.region_map; alt region::nearest_common_ancestor(rm, a_id, b_id) { - some(r_id) { ok(ty::re_scope(r_id)) } - _ { ok(ty::re_static) } + some(r_id) => ok(ty::re_scope(r_id)), + _ => ok(ty::re_static) } } @@ -2201,7 +2185,7 @@ impl of combine for lub { (ty::re_bound(_), ty::re_free(_, _)) | (ty::re_bound(_), ty::re_scope(_)) | (ty::re_free(_, _), ty::re_bound(_)) | - (ty::re_scope(_), ty::re_bound(_)) { + (ty::re_scope(_), ty::re_bound(_)) => { if a == b { ok(a) } else { @@ -2267,17 +2251,17 @@ impl of combine for glb { alt (a.mutbl, b.mutbl) { // If one side or both is mut, then the GLB must use // the precise type from the mut side. - (m_mutbl, m_const) { + (m_mutbl, m_const) => { sub(*self).tys(a.ty, b.ty).chain(|_t| { ok({ty: a.ty, mutbl: m_mutbl}) }) } - (m_const, m_mutbl) { + (m_const, m_mutbl) => { sub(*self).tys(b.ty, a.ty).chain(|_t| { ok({ty: b.ty, mutbl: m_mutbl}) }) } - (m_mutbl, m_mutbl) { + (m_mutbl, m_mutbl) => { self.infcx().eq_tys(a.ty, b.ty).then(|| { ok({ty: a.ty, mutbl: m_mutbl}) }) @@ -2287,7 +2271,7 @@ impl of combine for glb { // both sides but mutbl must be `m_imm`. (m_imm, m_const) | (m_const, m_imm) | - (m_imm, m_imm) { + (m_imm, m_imm) => { self.tys(a.ty, b.ty).chain(|t| { ok({ty: t, mutbl: m_imm}) }) @@ -2295,7 +2279,7 @@ impl of combine for glb { // If both sides are const, then we can use GLB of both // sides and mutbl of only `m_const`. - (m_const, m_const) { + (m_const, m_const) => { self.tys(a.ty, b.ty).chain(|t| { ok({ty: t, mutbl: m_const}) }) @@ -2303,7 +2287,7 @@ impl of combine for glb { // There is no mutual subtype of these combinations. (m_mutbl, m_imm) | - (m_imm, m_mutbl) { + (m_imm, m_mutbl) => { err(ty::terr_mutability) } } @@ -2327,20 +2311,20 @@ impl of combine for glb { fn purities(f1: purity, f2: purity) -> cres<purity> { alt (f1, f2) { - (pure_fn, _) | (_, pure_fn) {ok(pure_fn)} - (extern_fn, _) | (_, extern_fn) {ok(extern_fn)} - (impure_fn, _) | (_, impure_fn) {ok(impure_fn)} - (unsafe_fn, unsafe_fn) {ok(unsafe_fn)} + (pure_fn, _) | (_, pure_fn) => ok(pure_fn), + (extern_fn, _) | (_, extern_fn) => ok(extern_fn), + (impure_fn, _) | (_, impure_fn) => ok(impure_fn), + (unsafe_fn, unsafe_fn) => ok(unsafe_fn) } } fn ret_styles(r1: ret_style, r2: ret_style) -> cres<ret_style> { alt (r1, r2) { - (ast::return_val, ast::return_val) { + (ast::return_val, ast::return_val) => { ok(ast::return_val) } (ast::noreturn, _) | - (_, ast::noreturn) { + (_, ast::noreturn) => { ok(ast::noreturn) } } @@ -2354,17 +2338,17 @@ impl of combine for glb { do indent { alt (a, b) { - (ty::re_static, r) | (r, ty::re_static) { + (ty::re_static, r) | (r, ty::re_static) => { // static lives longer than everything else ok(r) } - (ty::re_var(_), _) | (_, ty::re_var(_)) { + (ty::re_var(_), _) | (_, ty::re_var(_)) => { lattice_rvars(self, a, b) } (ty::re_free(f_id, _), s @ ty::re_scope(s_id)) | - (s @ ty::re_scope(s_id), ty::re_free(f_id, _)) { + (s @ ty::re_scope(s_id), ty::re_free(f_id, _)) => { // Free region is something "at least as big as // `f_id`." If we find that the scope `f_id` is bigger // than the scope `s_id`, then we can say that the GLB @@ -2372,21 +2356,21 @@ impl of combine for glb { // big the free region is precisely, the GLB is undefined. let rm = self.infcx().tcx.region_map; alt region::nearest_common_ancestor(rm, f_id, s_id) { - some(r_id) if r_id == f_id { ok(s) } - _ { err(ty::terr_regions_differ(b, a)) } + some(r_id) if r_id == f_id => ok(s), + _ => err(ty::terr_regions_differ(b, a)) } } (ty::re_scope(a_id), ty::re_scope(b_id)) | - (ty::re_free(a_id, _), ty::re_free(b_id, _)) { + (ty::re_free(a_id, _), ty::re_free(b_id, _)) => { // We want to generate a region that is contained by both of // these: so, if one of these scopes is a subscope of the // other, return it. Otherwise fail. let rm = self.infcx().tcx.region_map; alt region::nearest_common_ancestor(rm, a_id, b_id) { - some(r_id) if a_id == r_id { ok(b) } - some(r_id) if b_id == r_id { ok(a) } - _ { err(ty::terr_regions_differ(b, a)) } + some(r_id) if a_id == r_id => ok(b), + some(r_id) if b_id == r_id => ok(a), + _ => err(ty::terr_regions_differ(b, a)) } } @@ -2396,7 +2380,7 @@ impl of combine for glb { (ty::re_bound(_), ty::re_free(_, _)) | (ty::re_bound(_), ty::re_scope(_)) | (ty::re_free(_, _), ty::re_bound(_)) | - (ty::re_scope(_), ty::re_bound(_)) { + (ty::re_scope(_), ty::re_bound(_)) => { if a == b { ok(a) } else { @@ -2492,25 +2476,25 @@ fn lattice_tys<L:lattice_ops combine>( if a == b { return ok(a); } do indent { alt (ty::get(a).struct, ty::get(b).struct) { - (ty::ty_bot, _) { self.ty_bot(b) } - (_, ty::ty_bot) { self.ty_bot(a) } + (ty::ty_bot, _) => self.ty_bot(b), + (_, ty::ty_bot) => self.ty_bot(a), - (ty::ty_var(a_id), ty::ty_var(b_id)) { + (ty::ty_var(a_id), ty::ty_var(b_id)) => { lattice_vars(self, self.infcx().tvb, a, a_id, b_id, |x, y| self.tys(x, y) ) } - (ty::ty_var(a_id), _) { + (ty::ty_var(a_id), _) => { lattice_var_t(self, self.infcx().tvb, a_id, b, |x, y| self.tys(x, y) ) } - (_, ty::ty_var(b_id)) { + (_, ty::ty_var(b_id)) => { lattice_var_t(self, self.infcx().tvb, b_id, a, |x, y| self.tys(x, y) ) } - _ { + _ => { super_tys(self, a, b) } } @@ -2522,19 +2506,19 @@ fn lattice_rvars<L:lattice_ops combine>( self: L, a: ty::region, b: ty::region) -> cres<ty::region> { alt (a, b) { - (ty::re_var(a_id), ty::re_var(b_id)) { + (ty::re_var(a_id), ty::re_var(b_id)) => { lattice_vars(self, self.infcx().rb, a, a_id, b_id, |x, y| self.regions(x, y) ) } - (ty::re_var(v_id), r) | (r, ty::re_var(v_id)) { + (ty::re_var(v_id), r) | (r, ty::re_var(v_id)) => { lattice_var_t(self, self.infcx().rb, v_id, r, |x, y| self.regions(x, y) ) } - _ { + _ => { self.infcx().tcx.sess.bug( fmt!{"%s: lattice_rvars invoked with a=%s and b=%s, \ neither of which are region variables", @@ -2575,13 +2559,13 @@ fn lattice_vars<V:copy vid, T:copy to_str st, L:lattice_ops combine>( // LUB of those types: let a_bnd = self.bnd(a_bounds), b_bnd = self.bnd(b_bounds); alt (a_bnd, b_bnd) { - (some(a_ty), some(b_ty)) { + (some(a_ty), some(b_ty)) => { alt self.infcx().try(|| c_ts(a_ty, b_ty) ) { - ok(t) { return ok(t); } - err(_) { /*fallthrough */ } + ok(t) => return ok(t), + err(_) => { /*fallthrough */ } } } - _ {/*fallthrough*/} + _ => {/*fallthrough*/} } // Otherwise, we need to merge A and B into one variable. We can @@ -2607,12 +2591,12 @@ fn lattice_var_t<V:copy vid, T:copy to_str st, L:lattice_ops combine>( b.to_str(self.infcx())}; alt self.bnd(a_bounds) { - some(a_bnd) { + some(a_bnd) => { // If a has an upper bound, return the LUB(a.ub, b) debug!{"bnd=some(%s)", a_bnd.to_str(self.infcx())}; return c_ts(a_bnd, b); } - none { + none => { // If a does not have an upper bound, make b the upper bound of a // and then return b. debug!{"bnd=none"}; diff --git a/src/rustc/util/common.rs b/src/rustc/util/common.rs index ff4baccc42e..d471ba677b5 100644 --- a/src/rustc/util/common.rs +++ b/src/rustc/util/common.rs @@ -45,8 +45,9 @@ fn loop_query(b: ast::blk, p: fn@(ast::expr_) -> bool) -> bool { alt e.node { // Skip inner loops, since a break in the inner loop isn't a // break inside the outer loop - ast::expr_loop(*) | ast::expr_while(*) | ast::expr_loop_body(*) {} - _ { visit::visit_expr(e, flag, v); } + ast::expr_loop(*) | ast::expr_while(*) + | ast::expr_loop_body(*) => {} + _ => visit::visit_expr(e, flag, v) } }; let v = visit::mk_vt(@{visit_expr: visit_expr @@ -56,19 +57,28 @@ fn loop_query(b: ast::blk, p: fn@(ast::expr_) -> bool) -> bool { } fn has_nonlocal_exits(b: ast::blk) -> bool { - do loop_query(b) |e| { alt e { - ast::expr_break | ast::expr_again { true } - _ { false }}} + do loop_query(b) |e| { + alt e { + ast::expr_break | ast::expr_again => true, + _ => false + } + } } fn may_break(b: ast::blk) -> bool { - do loop_query(b) |e| { alt e { - ast::expr_break { true } - _ { false }}} + do loop_query(b) |e| { + alt e { + ast::expr_break => true, + _ => false + } + } } fn local_rhs_span(l: @ast::local, def: span) -> span { - alt l.node.init { some(i) { return i.expr.span; } _ { return def; } } + alt l.node.init { + some(i) => return i.expr.span, + _ => return def + } } fn is_main_name(path: syntax::ast_map::path) -> bool { diff --git a/src/rustc/util/ppaux.rs b/src/rustc/util/ppaux.rs index 7fb7d4c83cb..571da9db069 100644 --- a/src/rustc/util/ppaux.rs +++ b/src/rustc/util/ppaux.rs @@ -96,17 +96,17 @@ fn bound_region_to_str(cx: ctxt, br: bound_region) -> ~str { fn re_scope_id_to_str(cx: ctxt, node_id: ast::node_id) -> ~str { alt cx.items.find(node_id) { - some(ast_map::node_block(blk)) { + some(ast_map::node_block(blk)) => { fmt!{"<block at %s>", codemap::span_to_str(blk.span, cx.sess.codemap)} } - some(ast_map::node_expr(expr)) { + some(ast_map::node_expr(expr)) => { alt expr.node { - ast::expr_call(*) { + ast::expr_call(*) => { fmt!{"<call at %s>", codemap::span_to_str(expr.span, cx.sess.codemap)} } - ast::expr_alt(*) { + ast::expr_alt(*) => { fmt!{"<alt at %s>", codemap::span_to_str(expr.span, cx.sess.codemap)} } @@ -114,20 +114,20 @@ fn re_scope_id_to_str(cx: ctxt, node_id: ast::node_id) -> ~str { ast::expr_field(*) | ast::expr_unary(*) | ast::expr_binary(*) | - ast::expr_index(*) { + ast::expr_index(*) => { fmt!{"<method at %s>", codemap::span_to_str(expr.span, cx.sess.codemap)} } - _ { + _ => { fmt!{"<expression at %s>", codemap::span_to_str(expr.span, cx.sess.codemap)} } } } - none { + none => { fmt!{"<unknown-%d>", node_id} } - _ { cx.sess.bug( + _ => { cx.sess.bug( fmt!{"re_scope refers to %s", ast_map::node_id_to_str(cx.items, node_id)}) } } @@ -135,17 +135,17 @@ fn re_scope_id_to_str(cx: ctxt, node_id: ast::node_id) -> ~str { fn region_to_str(cx: ctxt, region: region) -> ~str { alt region { - re_scope(node_id) { + re_scope(node_id) => { if cx.sess.ppregions() { fmt!{"&%s", re_scope_id_to_str(cx, node_id)} } else { ~"&" } } - re_bound(br) { + re_bound(br) => { bound_region_to_str(cx, br) } - re_free(id, br) { + re_free(id, br) => { if cx.sess.ppregions() { // For debugging, this version is sometimes helpful: fmt!{"{%d} %s", id, bound_region_to_str(cx, br)} @@ -156,35 +156,35 @@ fn region_to_str(cx: ctxt, region: region) -> ~str { } // These two should not be seen by end-users (very often, anyhow): - re_var(id) { fmt!{"&%s", id.to_str()} } - re_static { ~"&static" } + re_var(id) => fmt!{"&%s", id.to_str()}, + re_static => ~"&static" } } fn mt_to_str(cx: ctxt, m: mt) -> ~str { let mstr = alt m.mutbl { - ast::m_mutbl { ~"mut " } - ast::m_imm { ~"" } - ast::m_const { ~"const " } + ast::m_mutbl => ~"mut ", + ast::m_imm => ~"", + ast::m_const => ~"const " }; return mstr + ty_to_str(cx, m.ty); } fn vstore_to_str(cx: ctxt, vs: ty::vstore) -> ~str { alt vs { - ty::vstore_fixed(n) { fmt!{"%u", n} } - ty::vstore_uniq { ~"~" } - ty::vstore_box { ~"@" } - ty::vstore_slice(r) { region_to_str(cx, r) } + ty::vstore_fixed(n) => fmt!{"%u", n}, + ty::vstore_uniq => ~"~", + ty::vstore_box => ~"@", + ty::vstore_slice(r) => region_to_str(cx, r) } } fn vstore_ty_to_str(cx: ctxt, ty: ~str, vs: ty::vstore) -> ~str { alt vs { - ty::vstore_fixed(_) { + ty::vstore_fixed(_) => { fmt!{"%s/%s", ty, vstore_to_str(cx, vs)} } - _ { fmt!{"%s%s", vstore_to_str(cx, vs), ty} } + _ => fmt!{"%s%s", vstore_to_str(cx, vs), ty} } } @@ -199,8 +199,8 @@ fn ty_to_str(cx: ctxt, typ: t) -> ~str { ~str { let {mode, ty} = input; let modestr = alt canon_mode(cx, mode) { - ast::infer(_) { ~"" } - ast::expl(m) { + ast::infer(_) => ~"", + ast::expl(m) => { if !ty::type_needs_infer(ty) && m == ty::default_arg_mode_for_ty(ty) { ~"" @@ -217,11 +217,14 @@ fn ty_to_str(cx: ctxt, typ: t) -> ~str { let mut s; s = alt purity { - ast::impure_fn {~""} - _ {purity_to_str(purity) + ~" "} + ast::impure_fn => ~"", + _ => purity_to_str(purity) + ~" " }; s += proto_to_str(proto); - alt ident { some(i) { s += ~" "; s += *i; } _ { } } + alt ident { + some(i) => { s += ~" "; s += *i; } + _ => { } + } s += ~"("; let mut strs = ~[]; for inputs.each |a| { vec::push(strs, fn_input_to_str(cx, a)); } @@ -230,8 +233,8 @@ fn ty_to_str(cx: ctxt, typ: t) -> ~str { if ty::get(output).struct != ty_nil { s += ~" -> "; alt cf { - ast::noreturn { s += ~"!"; } - ast::return_val { s += ty_to_str(cx, output); } + ast::noreturn => { s += ~"!"; } + ast::return_val => { s += ty_to_str(cx, output); } } } return s; @@ -253,20 +256,20 @@ fn ty_to_str(cx: ctxt, typ: t) -> ~str { // pretty print the structural type representation: return alt ty::get(typ).struct { - ty_nil { ~"()" } - ty_bot { ~"_|_" } - ty_bool { ~"bool" } - ty_int(ast::ty_i) { ~"int" } - ty_int(ast::ty_char) { ~"char" } - ty_int(t) { ast_util::int_ty_to_str(t) } - ty_uint(ast::ty_u) { ~"uint" } - ty_uint(t) { ast_util::uint_ty_to_str(t) } - ty_float(ast::ty_f) { ~"float" } - ty_float(t) { ast_util::float_ty_to_str(t) } - ty_box(tm) { ~"@" + mt_to_str(cx, tm) } - ty_uniq(tm) { ~"~" + mt_to_str(cx, tm) } - ty_ptr(tm) { ~"*" + mt_to_str(cx, tm) } - ty_rptr(r, tm) { + ty_nil => ~"()", + ty_bot => ~"_|_", + ty_bool => ~"bool", + ty_int(ast::ty_i) => ~"int", + ty_int(ast::ty_char) => ~"char", + ty_int(t) => ast_util::int_ty_to_str(t), + ty_uint(ast::ty_u) => ~"uint", + ty_uint(t) => ast_util::uint_ty_to_str(t), + ty_float(ast::ty_f) => ~"float", + ty_float(t) => ast_util::float_ty_to_str(t), + ty_box(tm) => ~"@" + mt_to_str(cx, tm), + ty_uniq(tm) => ~"~" + mt_to_str(cx, tm), + ty_ptr(tm) => ~"*" + mt_to_str(cx, tm), + ty_rptr(r, tm) => { let rs = region_to_str(cx, r); if rs == ~"&" { rs + mt_to_str(cx, tm) @@ -274,46 +277,46 @@ fn ty_to_str(cx: ctxt, typ: t) -> ~str { rs + ~"/" + mt_to_str(cx, tm) } } - ty_unboxed_vec(tm) { ~"unboxed_vec<" + mt_to_str(cx, tm) + ~">" } - ty_type { ~"type" } - ty_rec(elems) { + ty_unboxed_vec(tm) => { ~"unboxed_vec<" + mt_to_str(cx, tm) + ~">" } + ty_type => ~"type", + ty_rec(elems) => { let mut strs: ~[~str] = ~[]; for elems.each |fld| { vec::push(strs, field_to_str(cx, fld)); } ~"{" + str::connect(strs, ~",") + ~"}" } - ty_tup(elems) { + ty_tup(elems) => { let mut strs = ~[]; for elems.each |elem| { vec::push(strs, ty_to_str(cx, elem)); } ~"(" + str::connect(strs, ~",") + ~")" } - ty_fn(f) { + ty_fn(f) => { fn_to_str(cx, f.purity, f.proto, none, f.inputs, f.output, f.ret_style) } - ty_var(v) { v.to_str() } - ty_var_integral(v) { v.to_str() } - ty_param({idx: id, _}) { + ty_var(v) => v.to_str(), + ty_var_integral(v) => v.to_str(), + ty_param({idx: id, _}) => { ~"'" + str::from_bytes(~[('a' as u8) + (id as u8)]) } - ty_self { ~"self" } - ty_enum(did, substs) | ty_class(did, substs) { + ty_self => ~"self", + ty_enum(did, substs) | ty_class(did, substs) => { let path = ty::item_path(cx, did); let base = ast_map::path_to_str(path); parameterized(cx, base, substs.self_r, substs.tps) } - ty_trait(did, substs) { + ty_trait(did, substs) => { let path = ty::item_path(cx, did); let base = ast_map::path_to_str(path); parameterized(cx, base, substs.self_r, substs.tps) } - ty_evec(mt, vs) { + ty_evec(mt, vs) => { vstore_ty_to_str(cx, fmt!{"[%s]", mt_to_str(cx, mt)}, vs) } - ty_estr(vs) { vstore_ty_to_str(cx, ~"str", vs) } - ty_opaque_box { ~"@?" } - ty_opaque_closure_ptr(ck_block) { ~"closure&" } - ty_opaque_closure_ptr(ck_box) { ~"closure@" } - ty_opaque_closure_ptr(ck_uniq) { ~"closure~" } + ty_estr(vs) => vstore_ty_to_str(cx, ~"str", vs), + ty_opaque_box => ~"@?", + ty_opaque_closure_ptr(ck_block) => ~"closure&", + ty_opaque_closure_ptr(ck_box) => ~"closure@", + ty_opaque_closure_ptr(ck_uniq) => ~"closure~" } } @@ -323,8 +326,8 @@ fn parameterized(cx: ctxt, tps: ~[ty::t]) -> ~str { let r_str = alt self_r { - none { ~"" } - some(r) { + none => ~"", + some(r) => { fmt!{"/%s", region_to_str(cx, r)} } }; diff --git a/src/rustdoc/astsrv.rs b/src/rustdoc/astsrv.rs index cd931578c32..58341e2152d 100644 --- a/src/rustdoc/astsrv.rs +++ b/src/rustdoc/astsrv.rs @@ -78,10 +78,10 @@ fn act(po: comm::port<msg>, source: ~str, parse: parser) { let mut keep_going = true; while keep_going { alt comm::recv(po) { - handle_request(f) { + handle_request(f) => { f(ctxt); } - exit { + exit => { keep_going = false; } } diff --git a/src/rustdoc/attr_parser.rs b/src/rustdoc/attr_parser.rs index 97f6ae2e81f..ba633111a6a 100644 --- a/src/rustdoc/attr_parser.rs +++ b/src/rustdoc/attr_parser.rs @@ -94,10 +94,10 @@ fn should_not_extract_crate_name_if_no_name_value_in_link_attribute() { fn parse_desc(attrs: ~[ast::attribute]) -> option<~str> { alt doc_meta(attrs) { - some(meta) { + some(meta) => { attr::get_meta_item_value_str(meta).map(|x| *x ) } - none { none } + none => none } } @@ -119,16 +119,16 @@ fn parse_desc_should_parse_simple_doc_attributes() { fn parse_hidden(attrs: ~[ast::attribute]) -> bool { alt doc_meta(attrs) { - some(meta) { + some(meta) => { alt attr::get_meta_item_list(meta) { - some(metas) { + some(metas) => { let hiddens = attr::find_meta_items_by_name(metas, ~"hidden"); vec::is_not_empty(hiddens) } - none { false } + none => false } } - none { false } + none => false } } diff --git a/src/rustdoc/attr_pass.rs b/src/rustdoc/attr_pass.rs index e22f3a1c9bb..9c55ebc4a95 100644 --- a/src/rustdoc/attr_pass.rs +++ b/src/rustdoc/attr_pass.rs @@ -94,11 +94,9 @@ fn parse_item_attrs<T:send>( +parse_attrs: fn~(~[ast::attribute]) -> T) -> T { do astsrv::exec(srv) |ctxt| { let attrs = alt ctxt.ast_map.get(id) { - ast_map::node_item(item, _) { item.attrs } - ast_map::node_foreign_item(item, _, _) { item.attrs } - _ { - fail ~"parse_item_attrs: not an item"; - } + ast_map::node_item(item, _) => item.attrs, + ast_map::node_foreign_item(item, _, _) => item.attrs, + _ => fail ~"parse_item_attrs: not an item" }; parse_attrs(attrs) } @@ -149,7 +147,7 @@ fn fold_enum( alt check ctxt.ast_map.get(doc_id) { ast_map::node_item(@{ node: ast::item_enum(ast_variants, _), _ - }, _) { + }, _) => { let ast_variant = option::get( vec::find(ast_variants, |v| { *v.node.name == variant.name @@ -206,13 +204,13 @@ fn merge_method_attrs( alt ctxt.ast_map.get(item_id) { ast_map::node_item(@{ node: ast::item_trait(_, _, methods), _ - }, _) { + }, _) => { vec::map(methods, |method| { alt method { - ast::required(ty_m) { + ast::required(ty_m) => { (*ty_m.ident, attr_parser::parse_desc(ty_m.attrs)) } - ast::provided(m) { + ast::provided(m) => { (*m.ident, attr_parser::parse_desc(m.attrs)) } } @@ -220,12 +218,12 @@ fn merge_method_attrs( } ast_map::node_item(@{ node: ast::item_impl(_, _, _, methods), _ - }, _) { + }, _) => { vec::map(methods, |method| { (*method.ident, attr_parser::parse_desc(method.attrs)) }) } - _ { fail ~"unexpected item" } + _ => fail ~"unexpected item" } }; diff --git a/src/rustdoc/config.rs b/src/rustdoc/config.rs index 5300ebe1a3b..398892d715f 100644 --- a/src/rustdoc/config.rs +++ b/src/rustdoc/config.rs @@ -101,7 +101,7 @@ fn parse_config_( let args = vec::tail(args); let opts = vec::unzip(opts()).first(); alt getopts::getopts(args, opts) { - result::ok(matches) { + result::ok(matches) => { if vec::len(matches.free) == 1u { let input_crate = vec::head(matches.free); config_from_opts(input_crate, matches, program_output) @@ -111,7 +111,7 @@ fn parse_config_( result::err(~"multiple crates specified") } } - result::err(f) { + result::err(f) => { result::err(getopts::fail_str(f)) } } @@ -177,17 +177,17 @@ fn config_from_opts( fn parse_output_format(output_format: ~str) -> result<output_format, ~str> { alt output_format { - ~"markdown" { result::ok(markdown) } - ~"html" { result::ok(pandoc_html) } - _ { result::err(fmt!{"unknown output format '%s'", output_format}) } + ~"markdown" => result::ok(markdown), + ~"html" => result::ok(pandoc_html), + _ => result::err(fmt!{"unknown output format '%s'", output_format}) } } fn parse_output_style(output_style: ~str) -> result<output_style, ~str> { alt output_style { - ~"doc-per-crate" { result::ok(doc_per_crate) } - ~"doc-per-mod" { result::ok(doc_per_mod) } - _ { result::err(fmt!{"unknown output style '%s'", output_style}) } + ~"doc-per-crate" => result::ok(doc_per_crate), + ~"doc-per-mod" => result::ok(doc_per_mod), + _ => result::err(fmt!{"unknown output style '%s'", output_style}) } } @@ -201,13 +201,13 @@ fn maybe_find_pandoc( } let possible_pandocs = alt maybe_pandoc_cmd { - some(pandoc_cmd) { ~[pandoc_cmd] } - none { + some(pandoc_cmd) => ~[pandoc_cmd], + none => { ~[~"pandoc"] + alt os::homedir() { - some(dir) { + some(dir) => { ~[path::connect(dir, ~".cabal/bin/pandoc")] } - none { ~[] } + none => ~[] } } }; diff --git a/src/rustdoc/desc_to_brief_pass.rs b/src/rustdoc/desc_to_brief_pass.rs index 37a76f936d2..76c74c71ef4 100644 --- a/src/rustdoc/desc_to_brief_pass.rs +++ b/src/rustdoc/desc_to_brief_pass.rs @@ -105,14 +105,14 @@ fn parse_desc(desc: ~str) -> option<~str> { const max_brief_len: uint = 120u; alt first_sentence(desc) { - some(first_sentence) { + some(first_sentence) => { if str::len(first_sentence) <= max_brief_len { some(first_sentence) } else { none } } - none { none } + none => none } } @@ -144,10 +144,10 @@ fn first_sentence_(s: ~str) -> ~str { } }; alt idx { - some(idx) if idx > 2u { + some(idx) if idx > 2u => { str::slice(s, 0u, idx - 1u) } - _ { + _ => { if str::ends_with(s, ~".") { str::slice(s, 0u, str::len(s)) } else { diff --git a/src/rustdoc/doc.rs b/src/rustdoc/doc.rs index 9e1fd812fc3..723bcff5fb0 100644 --- a/src/rustdoc/doc.rs +++ b/src/rustdoc/doc.rs @@ -142,8 +142,8 @@ impl util for doc { fn cratedoc() -> cratedoc { option::get(vec::foldl(none, self.pages, |_m, page| { alt page { - doc::cratepage(doc) { some(doc) } - _ { none } + doc::cratepage(doc) => some(doc), + _ => none } })) } @@ -159,8 +159,8 @@ impl util for moddoc { fn mods() -> ~[moddoc] { do vec::filter_map(self.items) |itemtag| { alt itemtag { - modtag(moddoc) { some(moddoc) } - _ { none } + modtag(moddoc) => some(moddoc), + _ => none } } } @@ -168,8 +168,8 @@ impl util for moddoc { fn nmods() -> ~[nmoddoc] { do vec::filter_map(self.items) |itemtag| { alt itemtag { - nmodtag(nmoddoc) { some(nmoddoc) } - _ { none } + nmodtag(nmoddoc) => some(nmoddoc), + _ => none } } } @@ -177,8 +177,8 @@ impl util for moddoc { fn fns() -> ~[fndoc] { do vec::filter_map(self.items) |itemtag| { alt itemtag { - fntag(fndoc) { some(fndoc) } - _ { none } + fntag(fndoc) => some(fndoc), + _ => none } } } @@ -186,8 +186,8 @@ impl util for moddoc { fn consts() -> ~[constdoc] { do vec::filter_map(self.items) |itemtag| { alt itemtag { - consttag(constdoc) { some(constdoc) } - _ { none } + consttag(constdoc) => some(constdoc), + _ => none } } } @@ -195,8 +195,8 @@ impl util for moddoc { fn enums() -> ~[enumdoc] { do vec::filter_map(self.items) |itemtag| { alt itemtag { - enumtag(enumdoc) { some(enumdoc) } - _ { none } + enumtag(enumdoc) => some(enumdoc), + _ => none } } } @@ -204,8 +204,8 @@ impl util for moddoc { fn traits() -> ~[traitdoc] { do vec::filter_map(self.items) |itemtag| { alt itemtag { - traittag(traitdoc) { some(traitdoc) } - _ { none } + traittag(traitdoc) => some(traitdoc), + _ => none } } } @@ -213,8 +213,8 @@ impl util for moddoc { fn impls() -> ~[impldoc] { do vec::filter_map(self.items) |itemtag| { alt itemtag { - impltag(impldoc) { some(impldoc) } - _ { none } + impltag(impldoc) => some(impldoc), + _ => none } } } @@ -222,8 +222,8 @@ impl util for moddoc { fn types() -> ~[tydoc] { do vec::filter_map(self.items) |itemtag| { alt itemtag { - tytag(tydoc) { some(tydoc) } - _ { none } + tytag(tydoc) => some(tydoc), + _ => none } } } @@ -245,8 +245,8 @@ impl util of page_utils for ~[page] { fn mods() -> ~[moddoc] { do vec::filter_map(self) |page| { alt page { - itempage(modtag(moddoc)) { some(moddoc) } - _ { none } + itempage(modtag(moddoc)) => some(moddoc), + _ => none } } } @@ -254,8 +254,8 @@ impl util of page_utils for ~[page] { fn nmods() -> ~[nmoddoc] { do vec::filter_map(self) |page| { alt page { - itempage(nmodtag(nmoddoc)) { some(nmoddoc) } - _ { none } + itempage(nmodtag(nmoddoc)) => some(nmoddoc), + _ => none } } } @@ -263,8 +263,8 @@ impl util of page_utils for ~[page] { fn fns() -> ~[fndoc] { do vec::filter_map(self) |page| { alt page { - itempage(fntag(fndoc)) { some(fndoc) } - _ { none } + itempage(fntag(fndoc)) => some(fndoc), + _ => none } } } @@ -272,8 +272,8 @@ impl util of page_utils for ~[page] { fn consts() -> ~[constdoc] { do vec::filter_map(self) |page| { alt page { - itempage(consttag(constdoc)) { some(constdoc) } - _ { none } + itempage(consttag(constdoc)) => some(constdoc), + _ => none } } } @@ -281,8 +281,8 @@ impl util of page_utils for ~[page] { fn enums() -> ~[enumdoc] { do vec::filter_map(self) |page| { alt page { - itempage(enumtag(enumdoc)) { some(enumdoc) } - _ { none } + itempage(enumtag(enumdoc)) => some(enumdoc), + _ => none } } } @@ -290,8 +290,8 @@ impl util of page_utils for ~[page] { fn traits() -> ~[traitdoc] { do vec::filter_map(self) |page| { alt page { - itempage(traittag(traitdoc)) { some(traitdoc) } - _ { none } + itempage(traittag(traitdoc)) => some(traitdoc), + _ => none } } } @@ -299,8 +299,8 @@ impl util of page_utils for ~[page] { fn impls() -> ~[impldoc] { do vec::filter_map(self) |page| { alt page { - itempage(impltag(impldoc)) { some(impldoc) } - _ { none } + itempage(impltag(impldoc)) => some(impldoc), + _ => none } } } @@ -308,8 +308,8 @@ impl util of page_utils for ~[page] { fn types() -> ~[tydoc] { do vec::filter_map(self) |page| { alt page { - itempage(tytag(tydoc)) { some(tydoc) } - _ { none } + itempage(tytag(tydoc)) => some(tydoc), + _ => none } } } @@ -322,14 +322,14 @@ trait item { impl of item for itemtag { pure fn item() -> itemdoc { alt self { - doc::modtag(doc) { doc.item } - doc::nmodtag(doc) { doc.item } - doc::fntag(doc) { doc.item } - doc::consttag(doc) { doc.item } - doc::enumtag(doc) { doc.item } - doc::traittag(doc) { doc.item } - doc::impltag(doc) { doc.item } - doc::tytag(doc) { doc.item } + doc::modtag(doc) => doc.item, + doc::nmodtag(doc) => doc.item, + doc::fntag(doc) => doc.item, + doc::consttag(doc) => doc.item, + doc::enumtag(doc) => doc.item, + doc::traittag(doc) => doc.item, + doc::impltag(doc) => doc.item, + doc::tytag(doc) => doc.item } } } diff --git a/src/rustdoc/extract.rs b/src/rustdoc/extract.rs index a6c653de326..7d56efcc4ee 100644 --- a/src/rustdoc/extract.rs +++ b/src/rustdoc/extract.rs @@ -59,49 +59,47 @@ fn moddoc_from_mod( items: do vec::filter_map(module_.items) |item| { let itemdoc = mk_itemdoc(item.id, item.ident); alt item.node { - ast::item_mod(m) { + ast::item_mod(m) => { some(doc::modtag( moddoc_from_mod(itemdoc, m) )) } - ast::item_foreign_mod(nm) { + ast::item_foreign_mod(nm) => { some(doc::nmodtag( nmoddoc_from_mod(itemdoc, nm) )) } - ast::item_fn(_, _, _) { + ast::item_fn(_, _, _) => { some(doc::fntag( fndoc_from_fn(itemdoc) )) } - ast::item_const(_, _) { + ast::item_const(_, _) => { some(doc::consttag( constdoc_from_const(itemdoc) )) } - ast::item_enum(variants, _) { + ast::item_enum(variants, _) => { some(doc::enumtag( enumdoc_from_enum(itemdoc, variants) )) } - ast::item_trait(_, _, methods) { + ast::item_trait(_, _, methods) => { some(doc::traittag( traitdoc_from_trait(itemdoc, methods) )) } - ast::item_impl(_, _, _, methods) { + ast::item_impl(_, _, _, methods) => { some(doc::impltag( impldoc_from_impl(itemdoc, methods) )) } - ast::item_ty(_, _) { + ast::item_ty(_, _) => { some(doc::tytag( tydoc_from_ty(itemdoc) )) } - _ { - none - } + _ => none } }, index: none @@ -117,7 +115,7 @@ fn nmoddoc_from_mod( fns: do vec::map(module_.items) |item| { let itemdoc = mk_itemdoc(item.id, item.ident); alt item.node { - ast::foreign_item_fn(_, _) { + ast::foreign_item_fn(_, _) => { fndoc_from_fn(itemdoc) } } @@ -192,7 +190,7 @@ fn traitdoc_from_trait( item: itemdoc, methods: do vec::map(methods) |method| { alt method { - ast::required(ty_m) { + ast::required(ty_m) => { { name: *ty_m.ident, brief: none, @@ -202,7 +200,7 @@ fn traitdoc_from_trait( implementation: doc::required, } } - ast::provided(m) { + ast::provided(m) => { { name: *m.ident, brief: none, diff --git a/src/rustdoc/fold.rs b/src/rustdoc/fold.rs index 11b90deecbd..b848c6b8899 100644 --- a/src/rustdoc/fold.rs +++ b/src/rustdoc/fold.rs @@ -135,10 +135,10 @@ fn default_seq_fold_doc<T>(fold: fold<T>, doc: doc::doc) -> doc::doc { doc::doc_({ pages: do vec::map(doc.pages) |page| { alt page { - doc::cratepage(doc) { + doc::cratepage(doc) => { doc::cratepage(fold.fold_crate(fold, doc)) } - doc::itempage(doc) { + doc::itempage(doc) => { doc::itempage(fold_itemtag(fold, doc)) } } @@ -243,28 +243,28 @@ fn default_par_fold_nmod<T:send copy>( fn fold_itemtag<T>(fold: fold<T>, doc: doc::itemtag) -> doc::itemtag { alt doc { - doc::modtag(moddoc) { + doc::modtag(moddoc) => { doc::modtag(fold.fold_mod(fold, moddoc)) } - doc::nmodtag(nmoddoc) { + doc::nmodtag(nmoddoc) => { doc::nmodtag(fold.fold_nmod(fold, nmoddoc)) } - doc::fntag(fndoc) { + doc::fntag(fndoc) => { doc::fntag(fold.fold_fn(fold, fndoc)) } - doc::consttag(constdoc) { + doc::consttag(constdoc) => { doc::consttag(fold.fold_const(fold, constdoc)) } - doc::enumtag(enumdoc) { + doc::enumtag(enumdoc) => { doc::enumtag(fold.fold_enum(fold, enumdoc)) } - doc::traittag(traitdoc) { + doc::traittag(traitdoc) => { doc::traittag(fold.fold_trait(fold, traitdoc)) } - doc::impltag(impldoc) { + doc::impltag(impldoc) => { doc::impltag(fold.fold_impl(fold, impldoc)) } - doc::tytag(tydoc) { + doc::tytag(tydoc) => { doc::tytag(fold.fold_type(fold, tydoc)) } } diff --git a/src/rustdoc/markdown_index_pass.rs b/src/rustdoc/markdown_index_pass.rs index 7280786db7e..123ad89ecd4 100644 --- a/src/rustdoc/markdown_index_pass.rs +++ b/src/rustdoc/markdown_index_pass.rs @@ -80,10 +80,10 @@ fn item_to_entry( ) -> doc::index_entry { let link = alt doc { doc::modtag(_) | doc::nmodtag(_) - if config.output_style == config::doc_per_mod { + if config.output_style == config::doc_per_mod => { markdown_writer::make_filename(config, doc::itempage(doc)) } - _ { + _ => { ~"#" + pandoc_header_id(markdown_pass::header_text(doc)) } }; diff --git a/src/rustdoc/markdown_pass.rs b/src/rustdoc/markdown_pass.rs index c8f767bf716..90d00d292b1 100644 --- a/src/rustdoc/markdown_pass.rs +++ b/src/rustdoc/markdown_pass.rs @@ -29,8 +29,8 @@ fn run( pure fn mods_last(item1: &doc::itemtag, item2: &doc::itemtag) -> bool { pure fn is_mod(item: &doc::itemtag) -> bool { alt *item { - doc::modtag(_) { true } - _ { false } + doc::modtag(_) => true, + _ => false } } @@ -95,10 +95,10 @@ fn write_markdown( fn write_page(ctxt: ctxt, page: doc::page) { write_title(ctxt, page); alt page { - doc::cratepage(doc) { + doc::cratepage(doc) => { write_crate(ctxt, doc); } - doc::itempage(doc) { + doc::itempage(doc) => { // We don't write a header for item's pages because their // header in the html output is created by the page title write_item_no_header(ctxt, doc); @@ -129,10 +129,10 @@ fn write_title(ctxt: ctxt, page: doc::page) { fn make_title(page: doc::page) -> ~str { let item = alt page { - doc::cratepage(cratedoc) { + doc::cratepage(cratedoc) => { doc::modtag(cratedoc.topmod) } - doc::itempage(itemtag) { + doc::itempage(itemtag) => { itemtag } }; @@ -151,10 +151,10 @@ fn should_write_title_for_each_page() { for iter::repeat(2u) { let (page, markdown) = comm::recv(po); alt page { - doc::cratepage(_) { + doc::cratepage(_) => { assert str::contains(markdown, ~"% Crate core"); } - doc::itempage(_) { + doc::itempage(_) => { assert str::contains(markdown, ~"% Module a"); } } @@ -181,32 +181,32 @@ fn write_header_(ctxt: ctxt, lvl: hlvl, title: ~str) { fn header_kind(doc: doc::itemtag) -> ~str { alt doc { - doc::modtag(_) { + doc::modtag(_) => { if doc.id() == syntax::ast::crate_node_id { ~"Crate" } else { ~"Module" } } - doc::nmodtag(_) { + doc::nmodtag(_) => { ~"Foreign module" } - doc::fntag(_) { + doc::fntag(_) => { ~"Function" } - doc::consttag(_) { + doc::consttag(_) => { ~"Const" } - doc::enumtag(_) { + doc::enumtag(_) => { ~"Enum" } - doc::traittag(_) { + doc::traittag(_) => { ~"Interface" } - doc::impltag(doc) { + doc::impltag(doc) => { ~"Implementation" } - doc::tytag(_) { + doc::tytag(_) => { ~"Type" } } @@ -215,13 +215,13 @@ fn header_kind(doc: doc::itemtag) -> ~str { fn header_name(doc: doc::itemtag) -> ~str { let fullpath = str::connect(doc.path() + ~[doc.name()], ~"::"); alt doc { - doc::modtag(_) if doc.id() != syntax::ast::crate_node_id { + doc::modtag(_) if doc.id() != syntax::ast::crate_node_id => { fullpath } - doc::nmodtag(_) { + doc::nmodtag(_) => { fullpath } - doc::impltag(doc) { + doc::impltag(doc) => { assert option::is_some(doc.self_ty); let self_ty = option::get(doc.self_ty); let mut trait_part = ~""; @@ -235,7 +235,7 @@ fn header_name(doc: doc::itemtag) -> ~str { } fmt!{"%s%s for %s", doc.name(), trait_part, self_ty} } - _ { + _ => { doc.name() } } @@ -290,11 +290,11 @@ fn write_desc( desc: option<~str> ) { alt desc { - some(desc) { + some(desc) => { ctxt.w.write_line(desc); ctxt.w.write_line(~""); } - none { } + none => () } } @@ -348,14 +348,14 @@ fn write_item_(ctxt: ctxt, doc: doc::itemtag, write_header: bool) { } alt doc { - doc::modtag(moddoc) { write_mod(ctxt, moddoc) } - doc::nmodtag(nmoddoc) { write_nmod(ctxt, nmoddoc) } - doc::fntag(fndoc) { write_fn(ctxt, fndoc) } - doc::consttag(constdoc) { write_const(ctxt, constdoc) } - doc::enumtag(enumdoc) { write_enum(ctxt, enumdoc) } - doc::traittag(traitdoc) { write_trait(ctxt, traitdoc) } - doc::impltag(impldoc) { write_impl(ctxt, impldoc) } - doc::tytag(tydoc) { write_type(ctxt, tydoc) } + doc::modtag(moddoc) => write_mod(ctxt, moddoc), + doc::nmodtag(nmoddoc) => write_nmod(ctxt, nmoddoc), + doc::fntag(fndoc) => write_fn(ctxt, fndoc), + doc::consttag(constdoc) => write_const(ctxt, constdoc), + doc::enumtag(enumdoc) => write_enum(ctxt, enumdoc), + doc::traittag(traitdoc) => write_trait(ctxt, traitdoc), + doc::impltag(impldoc) => write_impl(ctxt, impldoc), + doc::tytag(tydoc) => write_type(ctxt, tydoc) } } @@ -365,8 +365,8 @@ fn write_item_header(ctxt: ctxt, doc: doc::itemtag) { fn item_header_lvl(doc: doc::itemtag) -> hlvl { alt doc { - doc::modtag(_) | doc::nmodtag(_) { h1 } - _ { h2 } + doc::modtag(_) | doc::nmodtag(_) => h1, + _ => h2 } } @@ -482,11 +482,11 @@ fn write_fnlike( fn write_sig(ctxt: ctxt, sig: option<~str>) { alt sig { - some(sig) { + some(sig) => { ctxt.w.write_line(code_block_indent(sig)); ctxt.w.write_line(~""); } - none { fail ~"unimplemented" } + none => fail ~"unimplemented" } } @@ -603,10 +603,10 @@ fn write_variant(ctxt: ctxt, doc: doc::variantdoc) { assert option::is_some(doc.sig); let sig = option::get(doc.sig); alt doc.desc { - some(desc) { + some(desc) => { ctxt.w.write_line(fmt!{"* `%s` - %s", sig, desc}); } - none { + none => { ctxt.w.write_line(fmt!{"* `%s`", sig}); } } diff --git a/src/rustdoc/markdown_writer.rs b/src/rustdoc/markdown_writer.rs index 08e39ba53da..3f46f8f3d5b 100644 --- a/src/rustdoc/markdown_writer.rs +++ b/src/rustdoc/markdown_writer.rs @@ -39,10 +39,10 @@ impl writer_util of writer_utils for writer { fn make_writer_factory(config: config::config) -> writer_factory { alt config.output_format { - config::markdown { + config::markdown => { markdown_writer_factory(config) } - config::pandoc_html { + config::pandoc_html => { pandoc_writer_factory(config) } } @@ -151,8 +151,8 @@ fn generic_writer(+process: fn~(markdown: ~str)) -> writer { let mut keep_going = true; while keep_going { alt comm::recv(po) { - write(s) { markdown += s; } - done { keep_going = false; } + write(s) => markdown += s, + done => keep_going = false } } process(markdown); @@ -177,7 +177,7 @@ fn make_filename( ) -> ~str { let filename = { alt page { - doc::cratepage(doc) { + doc::cratepage(doc) => { if config.output_format == config::pandoc_html && config.output_style == config::doc_per_mod { ~"index" @@ -186,14 +186,14 @@ fn make_filename( doc.topmod.name() } } - doc::itempage(doc) { + doc::itempage(doc) => { str::connect(doc.path() + ~[doc.name()], ~"_") } } }; let ext = alt config.output_format { - config::markdown { ~"md" } - config::pandoc_html { ~"html" } + config::markdown => ~"md", + config::pandoc_html => ~"html" }; filename + ~"." + ext @@ -257,10 +257,10 @@ fn write_file(path: ~str, s: ~str) { import io::writer_util; alt io::file_writer(path, ~[io::create, io::truncate]) { - result::ok(writer) { + result::ok(writer) => { writer.write_str(s); } - result::err(e) { fail e } + result::err(e) => fail e } } @@ -293,8 +293,8 @@ fn future_writer() -> (writer, future::future<~str>) { let mut res = ~""; loop { alt comm::recv(port) { - write(s) { res += s } - done { break; } + write(s) => res += s, + done => break } } res diff --git a/src/rustdoc/page_pass.rs b/src/rustdoc/page_pass.rs index eed559367d3..11cf4f735cf 100644 --- a/src/rustdoc/page_pass.rs +++ b/src/rustdoc/page_pass.rs @@ -107,9 +107,9 @@ fn strip_mod(doc: doc::moddoc) -> doc::moddoc { doc::moddoc_({ items: do vec::filter(doc.items) |item| { alt item { - doc::modtag(_) { false } - doc::nmodtag(_) { false } - _ { true } + doc::modtag(_) => false, + doc::nmodtag(_) => false, + _ => true } } with *doc diff --git a/src/rustdoc/prune_hidden_pass.rs b/src/rustdoc/prune_hidden_pass.rs index dbb65f0e2d1..d8060257a63 100644 --- a/src/rustdoc/prune_hidden_pass.rs +++ b/src/rustdoc/prune_hidden_pass.rs @@ -39,8 +39,8 @@ fn is_hidden(srv: astsrv::srv, doc: doc::itemdoc) -> bool { let id = doc.id; do astsrv::exec(srv) |ctxt| { let attrs = alt ctxt.ast_map.get(id) { - ast_map::node_item(item, _) { item.attrs } - _ { ~[] } + ast_map::node_item(item, _) => item.attrs, + _ => ~[] }; attr_parser::parse_hidden(attrs) } diff --git a/src/rustdoc/rustdoc.rs b/src/rustdoc/rustdoc.rs index b6d225df98e..015da4b52d8 100755 --- a/src/rustdoc/rustdoc.rs +++ b/src/rustdoc/rustdoc.rs @@ -108,8 +108,8 @@ fn main(args: ~[~str]) { } let config = alt config::parse_config(args) { - result::ok(config) { config } - result::err(err) { + result::ok(config) => config, + result::err(err) => { io::println(fmt!{"error: %s", err}); return; } diff --git a/src/rustdoc/sectionalize_pass.rs b/src/rustdoc/sectionalize_pass.rs index 41771966881..29bebdf10e5 100644 --- a/src/rustdoc/sectionalize_pass.rs +++ b/src/rustdoc/sectionalize_pass.rs @@ -96,7 +96,7 @@ fn sectionalize(desc: option<~str>) -> (option<~str>, ~[doc::section]) { for lines.each |line| { alt parse_header(line) { - some(header) { + some(header) => { if option::is_some(current_section) { sections += ~[option::get(current_section)]; } @@ -105,20 +105,20 @@ fn sectionalize(desc: option<~str>) -> (option<~str>, ~[doc::section]) { body: ~"" }); } - none { + none => { alt copy current_section { - some(section) { + some(section) => { current_section = some({ body: section.body + ~"\n" + line with section }); } - none { + none => { new_desc = alt new_desc { - some(desc) { + some(desc) => { some(desc + ~"\n" + line) } - none { + none => { some(line) } }; diff --git a/src/rustdoc/sort_item_type_pass.rs b/src/rustdoc/sort_item_type_pass.rs index c7d185fb8a3..afa299345dc 100644 --- a/src/rustdoc/sort_item_type_pass.rs +++ b/src/rustdoc/sort_item_type_pass.rs @@ -8,14 +8,14 @@ fn mk_pass() -> pass { pure fn by_score(item1: &doc::itemtag, item2: &doc::itemtag) -> bool { pure fn score(item: &doc::itemtag) -> int { alt *item { - doc::consttag(_) { 0 } - doc::tytag(_) { 1 } - doc::enumtag(_) { 2 } - doc::traittag(_) { 3 } - doc::impltag(_) { 4 } - doc::fntag(_) { 5 } - doc::modtag(_) { 6 } - doc::nmodtag(_) { 7 } + doc::consttag(_) => 0, + doc::tytag(_) => 1, + doc::enumtag(_) => 2, + doc::traittag(_) => 3, + doc::impltag(_) => 4, + doc::fntag(_) => 5, + doc::modtag(_) => 6, + doc::nmodtag(_) => 7 } } diff --git a/src/rustdoc/tystr_pass.rs b/src/rustdoc/tystr_pass.rs index ce1f921af27..a2ae6d5eba4 100644 --- a/src/rustdoc/tystr_pass.rs +++ b/src/rustdoc/tystr_pass.rs @@ -54,7 +54,7 @@ fn get_fn_sig(srv: astsrv::srv, fn_id: doc::ast_id) -> option<~str> { ast_map::node_foreign_item(@{ ident: ident, node: ast::foreign_item_fn(decl, tys), _ - }, _, _) { + }, _, _) => { some(pprust::fun_to_str(decl, ident, tys)) } } @@ -84,7 +84,7 @@ fn fold_const( alt check ctxt.ast_map.get(doc.id()) { ast_map::node_item(@{ node: ast::item_const(ty, _), _ - }, _) { + }, _) => { pprust::ty_to_str(ty) } } @@ -112,7 +112,7 @@ fn fold_enum( alt check ctxt.ast_map.get(doc_id) { ast_map::node_item(@{ node: ast::item_enum(ast_variants, _), _ - }, _) { + }, _) => { let ast_variant = option::get( do vec::find(ast_variants) |v| { *v.node.name == variant.name @@ -170,23 +170,23 @@ fn get_method_sig( alt check ctxt.ast_map.get(item_id) { ast_map::node_item(@{ node: ast::item_trait(_, _, methods), _ - }, _) { + }, _) => { alt check vec::find(methods, |method| { alt method { - ast::required(ty_m) { *ty_m.ident == method_name } - ast::provided(m) { *m.ident == method_name } + ast::required(ty_m) => *ty_m.ident == method_name, + ast::provided(m) => *m.ident == method_name, } }) { - some(method) { + some(method) => { alt method { - ast::required(ty_m) { + ast::required(ty_m) => { some(pprust::fun_to_str( ty_m.decl, ty_m.ident, ty_m.tps )) } - ast::provided(m) { + ast::provided(m) => { some(pprust::fun_to_str( m.decl, m.ident, @@ -199,11 +199,11 @@ fn get_method_sig( } ast_map::node_item(@{ node: ast::item_impl(_, _, _, methods), _ - }, _) { + }, _) => { alt check vec::find(methods, |method| { *method.ident == method_name }) { - some(method) { + some(method) => { some(pprust::fun_to_str( method.decl, method.ident, @@ -234,13 +234,13 @@ fn fold_impl( alt ctxt.ast_map.get(doc.id()) { ast_map::node_item(@{ node: ast::item_impl(_, trait_types, self_ty, _), _ - }, _) { + }, _) => { let trait_types = vec::map(trait_types, |p| { pprust::path_to_str(p.path) }); (trait_types, some(pprust::ty_to_str(self_ty))) } - _ { fail ~"expected impl" } + _ => fail ~"expected impl" } }; @@ -290,7 +290,7 @@ fn fold_type( ast_map::node_item(@{ ident: ident, node: ast::item_ty(ty, params), _ - }, _) { + }, _) => { some(fmt!{ "type %s%s = %s", *ident, @@ -298,7 +298,7 @@ fn fold_type( pprust::ty_to_str(ty) }) } - _ { fail ~"expected type" } + _ => fail ~"expected type" } } with doc diff --git a/src/test/bench/core-std.rs b/src/test/bench/core-std.rs index b32047755ee..3c7057320ec 100644 --- a/src/test/bench/core-std.rs +++ b/src/test/bench/core-std.rs @@ -77,8 +77,8 @@ fn str_set() { let mut found = 0; for int::range(0, 1000) |_i| { alt s.find(r.gen_str(10)) { - some(_) { found += 1; } - none { } + some(_) => { found += 1; } + none => { } } } } diff --git a/src/test/bench/graph500-bfs.rs b/src/test/bench/graph500-bfs.rs index 1dc6c4ab064..dfc74f12cef 100644 --- a/src/test/bench/graph500-bfs.rs +++ b/src/test/bench/graph500-bfs.rs @@ -158,8 +158,8 @@ fn bfs2(graph: graph, key: node_id) -> bfs_result { fn is_gray(c: color) -> bool { alt c { - gray(_) { true } - _ { false } + gray(_) => { true } + _ => { false } } } @@ -171,7 +171,7 @@ fn bfs2(graph: graph, key: node_id) -> bfs_result { colors = do colors.mapi() |i, c| { let c : color = c; alt c { - white { + white => { let i = i as node_id; let neighbors = graph[i]; @@ -188,8 +188,8 @@ fn bfs2(graph: graph, key: node_id) -> bfs_result { color } - gray(parent) { black(parent) } - black(parent) { black(parent) } + gray(parent) => { black(parent) } + black(parent) => { black(parent) } } } } @@ -197,9 +197,9 @@ fn bfs2(graph: graph, key: node_id) -> bfs_result { // Convert the results. do vec::map(colors) |c| { alt c { - white { -1i64 } - black(parent) { parent } - _ { fail ~"Found remaining gray nodes in BFS" } + white => { -1i64 } + black(parent) => { parent } + _ => { fail ~"Found remaining gray nodes in BFS" } } } } @@ -228,8 +228,8 @@ fn pbfs(&&graph: arc::arc<graph>, key: node_id) -> bfs_result { #[inline(always)] fn is_gray(c: color) -> bool { alt c { - gray(_) { true } - _ { false } + gray(_) => { true } + _ => { false } } } @@ -250,7 +250,7 @@ fn pbfs(&&graph: arc::arc<graph>, key: node_id) -> bfs_result { let colors = arc::get(&colors); let graph = arc::get(&graph); alt c { - white { + white => { let i = i as node_id; let neighbors = graph[i]; @@ -266,8 +266,8 @@ fn pbfs(&&graph: arc::arc<graph>, key: node_id) -> bfs_result { }; color } - gray(parent) { black(parent) } - black(parent) { black(parent) } + gray(parent) => { black(parent) } + black(parent) => { black(parent) } } } }; @@ -277,9 +277,9 @@ fn pbfs(&&graph: arc::arc<graph>, key: node_id) -> bfs_result { // Convert the results. do par::map(colors) |c| { alt c { - white { -1i64 } - black(parent) { parent } - _ { fail ~"Found remaining gray nodes in BFS" } + white => { -1i64 } + black(parent) => { parent } + _ => { fail ~"Found remaining gray nodes in BFS" } } } } diff --git a/src/test/bench/msgsend-pipes-shared.rs b/src/test/bench/msgsend-pipes-shared.rs index 82f4c1bef28..e0ebda079f7 100644 --- a/src/test/bench/msgsend-pipes-shared.rs +++ b/src/test/bench/msgsend-pipes-shared.rs @@ -32,13 +32,13 @@ fn server(requests: port<request>, responses: pipes::chan<uint>) { let mut done = false; while !done { alt requests.try_recv() { - some(get_count) { responses.send(copy count); } - some(bytes(b)) { + some(get_count) => { responses.send(copy count); } + some(bytes(b)) => { //error!{"server: received %? bytes", b}; count += b; } - none { done = true; } - _ { } + none => { done = true; } + _ => { } } } responses.send(count); diff --git a/src/test/bench/msgsend-pipes.rs b/src/test/bench/msgsend-pipes.rs index a9b45ef776f..067bd710b3d 100644 --- a/src/test/bench/msgsend-pipes.rs +++ b/src/test/bench/msgsend-pipes.rs @@ -27,13 +27,13 @@ fn server(requests: port_set<request>, responses: pipes::chan<uint>) { let mut done = false; while !done { alt requests.try_recv() { - some(get_count) { responses.send(copy count); } - some(bytes(b)) { + some(get_count) => { responses.send(copy count); } + some(bytes(b)) => { //error!{"server: received %? bytes", b}; count += b; } - none { done = true; } - _ { } + none => { done = true; } + _ => { } } } responses.send(count); diff --git a/src/test/bench/msgsend-ring-pipes.rs b/src/test/bench/msgsend-ring-pipes.rs index 493d98c6a59..c494bfc485a 100644 --- a/src/test/bench/msgsend-ring-pipes.rs +++ b/src/test/bench/msgsend-ring-pipes.rs @@ -44,7 +44,7 @@ fn thread_ring(i: uint, num_chan = some(ring::client::num(option::unwrap(num_chan2), i * j)); let port = option::unwrap(num_port2); alt recv(port) { - ring::num(_n, p) { + ring::num(_n, p) => { //log(error, _n); num_port = some(move_out!{p}); } diff --git a/src/test/bench/msgsend.rs b/src/test/bench/msgsend.rs index 606f33936c1..5b2488efa2f 100644 --- a/src/test/bench/msgsend.rs +++ b/src/test/bench/msgsend.rs @@ -19,9 +19,9 @@ fn server(requests: comm::port<request>, responses: comm::chan<uint>) { let mut done = false; while !done { alt comm::recv(requests) { - get_count { comm::send(responses, copy count); } - bytes(b) { count += b; } - stop { done = true; } + get_count => { comm::send(responses, copy count); } + bytes(b) => { count += b; } + stop => { done = true; } } } comm::send(responses, count); diff --git a/src/test/bench/shootout-binarytrees.rs b/src/test/bench/shootout-binarytrees.rs index 8ccb2e61d41..be3a868beb2 100644 --- a/src/test/bench/shootout-binarytrees.rs +++ b/src/test/bench/shootout-binarytrees.rs @@ -6,8 +6,8 @@ enum tree/& { nil, node(&tree, &tree, int), } fn item_check(t: &tree) -> int { alt *t { - nil { return 0; } - node(left, right, item) { + nil => { return 0; } + node(left, right, item) => { return item + item_check(left) - item_check(right); } } diff --git a/src/test/bench/shootout-chameneos-redux.rs b/src/test/bench/shootout-chameneos-redux.rs index 8882b5ae7c7..7adc176bcff 100644 --- a/src/test/bench/shootout-chameneos-redux.rs +++ b/src/test/bench/shootout-chameneos-redux.rs @@ -23,9 +23,9 @@ type creature_info = { name: uint, color: color }; fn show_color(cc: color) -> ~str { alt (cc) { - Red {~"red"} - Yellow {~"yellow"} - Blue {~"blue"} + Red => {~"red"} + Yellow => {~"yellow"} + Blue => {~"blue"} } } @@ -40,17 +40,17 @@ fn show_color_list(set: ~[color]) -> ~str { fn show_digit(nn: uint) -> ~str { alt (nn) { - 0 {~"zero"} - 1 {~"one"} - 2 {~"two"} - 3 {~"three"} - 4 {~"four"} - 5 {~"five"} - 6 {~"six"} - 7 {~"seven"} - 8 {~"eight"} - 9 {~"nine"} - _ {fail ~"expected digits from 0 to 9..."} + 0 => {~"zero"} + 1 => {~"one"} + 2 => {~"two"} + 3 => {~"three"} + 4 => {~"four"} + 5 => {~"five"} + 6 => {~"six"} + 7 => {~"seven"} + 8 => {~"eight"} + 9 => {~"nine"} + _ => {fail ~"expected digits from 0 to 9..."} } } @@ -72,15 +72,15 @@ fn show_number(nn: uint) -> ~str { fn transform(aa: color, bb: color) -> color { alt (aa, bb) { - (Red, Red ) { Red } - (Red, Yellow) { Blue } - (Red, Blue ) { Yellow } - (Yellow, Red ) { Blue } - (Yellow, Yellow) { Yellow } - (Yellow, Blue ) { Red } - (Blue, Red ) { Yellow } - (Blue, Yellow) { Red } - (Blue, Blue ) { Blue } + (Red, Red ) => { Red } + (Red, Yellow) => { Blue } + (Red, Blue ) => { Yellow } + (Yellow, Red ) => { Blue } + (Yellow, Yellow) => { Yellow } + (Yellow, Blue ) => { Red } + (Blue, Red ) => { Yellow } + (Blue, Yellow) => { Red } + (Blue, Blue ) => { Blue } } } @@ -102,7 +102,7 @@ fn creature( // log and change, or print and quit alt resp { - option::some(other_creature) { + option::some(other_creature) => { color = transform(color, other_creature.color); // track some statistics @@ -111,7 +111,7 @@ fn creature( evil_clones_met += 1; } } - option::none { + option::none => { // log creatures met and evil clones of self let report = fmt!{"%u", creatures_met} + ~" " + show_number(evil_clones_met); diff --git a/src/test/bench/shootout-k-nucleotide-pipes.rs b/src/test/bench/shootout-k-nucleotide-pipes.rs index cebd36a1569..ca014b61455 100644 --- a/src/test/bench/shootout-k-nucleotide-pipes.rs +++ b/src/test/bench/shootout-k-nucleotide-pipes.rs @@ -60,8 +60,8 @@ fn sort_and_fmt(mm: hashmap<~[u8], uint>, total: uint) -> ~str { // given a map, search for the frequency of a pattern fn find(mm: hashmap<~[u8], uint>, key: ~str) -> uint { alt mm.find(str::bytes(str::to_lower(key))) { - option::none { return 0u; } - option::some(num) { return num; } + option::none => { return 0u; } + option::some(num) => { return num; } } } @@ -69,8 +69,8 @@ fn find(mm: hashmap<~[u8], uint>, key: ~str) -> uint { fn update_freq(mm: hashmap<~[u8], uint>, key: &[u8]) { let key = vec::slice(key, 0, key.len()); alt mm.find(key) { - option::none { mm.insert(key, 1u ); } - option::some(val) { mm.insert(key, 1u + val); } + option::none => { mm.insert(key, 1u ); } + option::some(val) => { mm.insert(key, 1u + val); } } } @@ -111,14 +111,14 @@ fn make_sequence_processor(sz: uint, from_parent: pipes::port<~[u8]>, } let buffer = alt sz { - 1u { sort_and_fmt(freqs, total) } - 2u { sort_and_fmt(freqs, total) } - 3u { fmt!{"%u\t%s", find(freqs, ~"GGT"), ~"GGT"} } - 4u { fmt!{"%u\t%s", find(freqs, ~"GGTA"), ~"GGTA"} } - 6u { fmt!{"%u\t%s", find(freqs, ~"GGTATT"), ~"GGTATT"} } - 12u { fmt!{"%u\t%s", find(freqs, ~"GGTATTTTAATT"), ~"GGTATTTTAATT"} } - 18u { fmt!{"%u\t%s", find(freqs, ~"GGTATTTTAATTTATAGT"), ~"GGTATTTTAATTTATAGT"} } - _ { ~"" } + 1u => { sort_and_fmt(freqs, total) } + 2u => { sort_and_fmt(freqs, total) } + 3u => { fmt!{"%u\t%s", find(freqs, ~"GGT"), ~"GGT"} } + 4u => { fmt!{"%u\t%s", find(freqs, ~"GGTA"), ~"GGTA"} } + 6u => { fmt!{"%u\t%s", find(freqs, ~"GGTATT"), ~"GGTATT"} } + 12u => { fmt!{"%u\t%s", find(freqs, ~"GGTATTTTAATT"), ~"GGTATTTTAATT"} } + 18u => { fmt!{"%u\t%s", find(freqs, ~"GGTATTTTAATTTATAGT"), ~"GGTATTTTAATTTATAGT"} } + _ => { ~"" } }; //comm::send(to_parent, fmt!{"yay{%u}", sz}); @@ -175,18 +175,18 @@ fn main(args: ~[~str]) { alt (line[0], proc_mode) { // start processing if this is the one - ('>' as u8, false) { + ('>' as u8, false) => { alt str::find_str_from(line, ~"THREE", 1u) { - option::some(_) { proc_mode = true; } - option::none { } + option::some(_) => { proc_mode = true; } + option::none => { } } } // break our processing - ('>' as u8, true) { break; } + ('>' as u8, true) => { break; } // process the sequence for k-mers - (_, true) { + (_, true) => { let line_bytes = str::bytes(line); for sizes.eachi |ii, _sz| { @@ -196,7 +196,7 @@ fn main(args: ~[~str]) { } // whatever - _ { } + _ => { } } } diff --git a/src/test/bench/shootout-k-nucleotide.rs b/src/test/bench/shootout-k-nucleotide.rs index 6f026cd6258..5ffa7cc4f26 100644 --- a/src/test/bench/shootout-k-nucleotide.rs +++ b/src/test/bench/shootout-k-nucleotide.rs @@ -58,8 +58,8 @@ fn sort_and_fmt(mm: hashmap<~[u8], uint>, total: uint) -> ~str { // given a map, search for the frequency of a pattern fn find(mm: hashmap<~[u8], uint>, key: ~str) -> uint { alt mm.find(str::bytes(str::to_lower(key))) { - option::none { return 0u; } - option::some(num) { return num; } + option::none => { return 0u; } + option::some(num) => { return num; } } } @@ -67,8 +67,8 @@ fn find(mm: hashmap<~[u8], uint>, key: ~str) -> uint { fn update_freq(mm: hashmap<~[u8], uint>, key: &[u8]) { let key = vec::slice(key, 0, key.len()); alt mm.find(key) { - option::none { mm.insert(key, 1u ); } - option::some(val) { mm.insert(key, 1u + val); } + option::none => { mm.insert(key, 1u ); } + option::some(val) => { mm.insert(key, 1u + val); } } } @@ -109,14 +109,14 @@ fn make_sequence_processor(sz: uint, from_parent: comm::port<~[u8]>, } let buffer = alt sz { - 1u { sort_and_fmt(freqs, total) } - 2u { sort_and_fmt(freqs, total) } - 3u { fmt!{"%u\t%s", find(freqs, ~"GGT"), ~"GGT"} } - 4u { fmt!{"%u\t%s", find(freqs, ~"GGTA"), ~"GGTA"} } - 6u { fmt!{"%u\t%s", find(freqs, ~"GGTATT"), ~"GGTATT"} } - 12u { fmt!{"%u\t%s", find(freqs, ~"GGTATTTTAATT"), ~"GGTATTTTAATT"} } - 18u { fmt!{"%u\t%s", find(freqs, ~"GGTATTTTAATTTATAGT"), ~"GGTATTTTAATTTATAGT"} } - _ { ~"" } + 1u => { sort_and_fmt(freqs, total) } + 2u => { sort_and_fmt(freqs, total) } + 3u => { fmt!{"%u\t%s", find(freqs, ~"GGT"), ~"GGT"} } + 4u => { fmt!{"%u\t%s", find(freqs, ~"GGTA"), ~"GGTA"} } + 6u => { fmt!{"%u\t%s", find(freqs, ~"GGTATT"), ~"GGTATT"} } + 12u => { fmt!{"%u\t%s", find(freqs, ~"GGTATTTTAATT"), ~"GGTATTTTAATT"} } + 18u => { fmt!{"%u\t%s", find(freqs, ~"GGTATTTTAATTTATAGT"), ~"GGTATTTTAATTTATAGT"} } + _ => { ~"" } }; //comm::send(to_parent, fmt!{"yay{%u}", sz}); @@ -162,18 +162,18 @@ fn main(args: ~[~str]) { alt (line[0], proc_mode) { // start processing if this is the one - ('>' as u8, false) { + ('>' as u8, false) => { alt str::find_str_from(line, ~"THREE", 1u) { - option::some(_) { proc_mode = true; } - option::none { } + option::some(_) => proc_mode = true, + option::none => () } } // break our processing - ('>' as u8, true) { break; } + ('>' as u8, true) => { break; } // process the sequence for k-mers - (_, true) { + (_, true) => { let line_bytes = str::bytes(line); for sizes.eachi |ii, _sz| { @@ -183,7 +183,7 @@ fn main(args: ~[~str]) { } // whatever - _ { } + _ => { } } } diff --git a/src/test/bench/shootout-mandelbrot.rs b/src/test/bench/shootout-mandelbrot.rs index c752dc4050d..f00396f9b14 100644 --- a/src/test/bench/shootout-mandelbrot.rs +++ b/src/test/bench/shootout-mandelbrot.rs @@ -104,13 +104,13 @@ fn writer(path: ~str, writech: comm::chan<comm::chan<line>>, size: uint) let ch = comm::chan(p); comm::send(writech, ch); let cout: io::writer = alt path { - ~"" { + ~"" => { {dn: 0} as io::writer } - ~"-" { + ~"-" => { io::stdout() } - _ { + _ => { result::get( io::file_writer(path, ~[io::create, io::truncate])) diff --git a/src/test/bench/shootout-threadring.rs b/src/test/bench/shootout-threadring.rs index 36df950a2b7..e99d2946e81 100644 --- a/src/test/bench/shootout-threadring.rs +++ b/src/test/bench/shootout-threadring.rs @@ -22,11 +22,11 @@ fn start(+token: int) { fn roundtrip(id: int, p: comm::port<int>, ch: comm::chan<int>) { while (true) { alt comm::recv(p) { - 1 { + 1 => { io::println(fmt!{"%d\n", id}); return; } - token { + token => { debug!{"%d %d", id, token}; comm::send(ch, token - 1); if token <= n_threads { diff --git a/src/test/bench/task-perf-alloc-unwind.rs b/src/test/bench/task-perf-alloc-unwind.rs index e24b7bf5fa4..2a8750b64bd 100644 --- a/src/test/bench/task-perf-alloc-unwind.rs +++ b/src/test/bench/task-perf-alloc-unwind.rs @@ -54,7 +54,7 @@ fn recurse_or_fail(depth: int, st: option<st>) { let depth = depth - 1; let st = alt st { - none { + none => { st_({ box: @nil, unique: ~nil, @@ -65,7 +65,7 @@ fn recurse_or_fail(depth: int, st: option<st>) { res: r(@nil) }) } - some(st) { + some(st) => { let fn_box = st.fn_box; let fn_unique = st.fn_unique; diff --git a/src/test/bench/task-perf-one-million.rs b/src/test/bench/task-perf-one-million.rs index 8dd6f957ffa..85008b0daf9 100644 --- a/src/test/bench/task-perf-one-million.rs +++ b/src/test/bench/task-perf-one-million.rs @@ -20,7 +20,7 @@ fn calc(children: uint, parent_ch: comm::chan<msg>) { for iter::repeat (children) { alt check comm::recv(port) { - ready(child_ch) { + ready(child_ch) => { vec::push(child_chs, child_ch); } } @@ -29,7 +29,7 @@ fn calc(children: uint, parent_ch: comm::chan<msg>) { comm::send(parent_ch, ready(chan)); alt check comm::recv(port) { - start { + start => { do vec::iter (child_chs) |child_ch| { comm::send(child_ch, start); } @@ -38,7 +38,7 @@ fn calc(children: uint, parent_ch: comm::chan<msg>) { for iter::repeat (children) { alt check comm::recv(port) { - done(child_sum) { sum += child_sum; } + done(child_sum) => { sum += child_sum; } } } @@ -61,12 +61,12 @@ fn main(args: ~[~str]) { calc(children, chan); }; alt check comm::recv(port) { - ready(chan) { + ready(chan) => { comm::send(chan, start); } } let sum = alt check comm::recv(port) { - done(sum) { sum } + done(sum) => { sum } }; error!{"How many tasks? %d tasks.", sum}; } diff --git a/src/test/bench/task-perf-word-count-generic.rs b/src/test/bench/task-perf-word-count-generic.rs index c939da509bc..c31ccde2ca6 100644 --- a/src/test/bench/task-perf-word-count-generic.rs +++ b/src/test/bench/task-perf-word-count-generic.rs @@ -80,8 +80,8 @@ impl of word_reader for io::reader { fn file_word_reader(filename: ~str) -> word_reader { alt io::file_reader(filename) { - result::ok(f) { f as word_reader } - result::err(e) { fail fmt!{"%?", e} } + result::ok(f) => { f as word_reader } + result::err(e) => { fail fmt!{"%?", e} } } } @@ -89,8 +89,8 @@ fn map(f: fn~() -> word_reader, emit: map_reduce::putter<~str, int>) { let f = f(); loop { alt f.read_word() { - some(w) { emit(w, 1); } - none { break; } + some(w) => { emit(w, 1); } + none => { break; } } } } @@ -98,7 +98,7 @@ fn map(f: fn~() -> word_reader, emit: map_reduce::putter<~str, int>) { fn reduce(&&word: ~str, get: map_reduce::getter<int>) { let mut count = 0; - loop { alt get() { some(_) { count += 1; } none { break; } } } + loop { alt get() { some(_) => { count += 1; } none => { break; } } } io::println(fmt!{"%s\t%?", word, count}); } @@ -182,12 +182,12 @@ mod map_reduce { do map(input) |key, val| { let mut c = none; alt intermediates.find(key) { - some(_c) { c = some(_c); } - none { + some(_c) => { c = some(_c); } + none => { do ctrl.swap |ctrl| { let ctrl = ctrl_proto::client::find_reducer(ctrl, key); alt pipes::recv(ctrl) { - ctrl_proto::reducer(c_, ctrl) { + ctrl_proto::reducer(c_, ctrl) => { c = some(c_); move_out!{ctrl} } @@ -225,16 +225,16 @@ mod map_reduce { -> option<V> { while !is_done || ref_count > 0 { alt recv(p) { - emit_val(v) { + emit_val(v) => { // error!{"received %d", v}; return some(v); } - done { + done => { // error!{"all done"}; is_done = true; } - addref { ref_count += 1; } - release { ref_count -= 1; } + addref => { ref_count += 1; } + release => { ref_count -= 1; } } } return none; @@ -260,21 +260,21 @@ mod map_reduce { while num_mappers > 0 { let (_ready, message, ctrls) = pipes::select(ctrl); alt option::unwrap(message) { - ctrl_proto::mapper_done { + ctrl_proto::mapper_done => { // error!{"received mapper terminated."}; num_mappers -= 1; ctrl = ctrls; } - ctrl_proto::find_reducer(k, cc) { + ctrl_proto::find_reducer(k, cc) => { let c; // log(error, "finding reducer for " + k); alt reducers.find(k) { - some(_c) { + some(_c) => { // log(error, // "reusing existing reducer for " + k); c = _c; } - none { + none => { // log(error, "creating new reducer for " + k); let p = port(); let ch = chan(p); diff --git a/src/test/compile-fail/alt-join.rs b/src/test/compile-fail/alt-join.rs index cd39d90b9bd..1557ff12090 100644 --- a/src/test/compile-fail/alt-join.rs +++ b/src/test/compile-fail/alt-join.rs @@ -4,7 +4,7 @@ fn my_fail() -> ! { fail; } fn main() { - alt true { false { my_fail(); } true { } } + alt true { false => { my_fail(); } true => { } } log(debug, x); //~ ERROR unresolved name: x let x: int; diff --git a/src/test/compile-fail/alt-pattern-field-mismatch-2.rs b/src/test/compile-fail/alt-pattern-field-mismatch-2.rs index b8d4dab9539..6ba942decfc 100644 --- a/src/test/compile-fail/alt-pattern-field-mismatch-2.rs +++ b/src/test/compile-fail/alt-pattern-field-mismatch-2.rs @@ -7,9 +7,9 @@ fn main() { fn foo(c: color) { alt c { - rgb(_, _, _) { } - cmyk(_, _, _, _) { } - no_color(_) { } + rgb(_, _, _) => { } + cmyk(_, _, _, _) => { } + no_color(_) => { } //~^ ERROR this pattern has 1 field, but the corresponding variant has no fields } } diff --git a/src/test/compile-fail/alt-pattern-field-mismatch.rs b/src/test/compile-fail/alt-pattern-field-mismatch.rs index 2e24f6a5c89..71f44764e14 100644 --- a/src/test/compile-fail/alt-pattern-field-mismatch.rs +++ b/src/test/compile-fail/alt-pattern-field-mismatch.rs @@ -7,10 +7,10 @@ fn main() { fn foo(c: color) { alt c { - rgb(_, _) { } + rgb(_, _) => { } //~^ ERROR this pattern has 2 fields, but the corresponding variant has 3 fields - cmyk(_, _, _, _) { } - no_color { } + cmyk(_, _, _, _) => { } + no_color => { } } } } diff --git a/src/test/compile-fail/alt-range-fail-dominate.rs b/src/test/compile-fail/alt-range-fail-dominate.rs index b04e787d660..d1ba0f625b1 100644 --- a/src/test/compile-fail/alt-range-fail-dominate.rs +++ b/src/test/compile-fail/alt-range-fail-dominate.rs @@ -6,27 +6,27 @@ fn main() { alt check 5u { - 1u to 10u { } - 5u to 6u { } + 1u to 10u => { } + 5u to 6u => { } }; alt check 5u { - 3u to 6u { } - 4u to 6u { } + 3u to 6u => { } + 4u to 6u => { } }; alt check 5u { - 4u to 6u { } - 4u to 6u { } + 4u to 6u => { } + 4u to 6u => { } }; alt check 'c' { - 'A' to 'z' {} - 'a' to 'z' {} + 'A' to 'z' => {} + 'a' to 'z' => {} }; alt check 1.0 { - 0.01 to 6.5 {} - 0.02 {} + 0.01 to 6.5 => {} + 0.02 => {} }; } \ No newline at end of file diff --git a/src/test/compile-fail/alt-range-fail.rs b/src/test/compile-fail/alt-range-fail.rs index b9c1c6f0a1e..afda6d7015e 100644 --- a/src/test/compile-fail/alt-range-fail.rs +++ b/src/test/compile-fail/alt-range-fail.rs @@ -4,16 +4,16 @@ fn main() { alt 5u { - 6u to 1u { } - _ { } + 6u to 1u => { } + _ => { } }; alt "wow" { - "bar" to "foo" { } + "bar" to "foo" => { } }; alt 5u { - 'c' to 100u { } - _ { } + 'c' to 100u => { } + _ => { } }; } diff --git a/src/test/compile-fail/alt-tag-nullary.rs b/src/test/compile-fail/alt-tag-nullary.rs index 878b872978e..4f34c675cef 100644 --- a/src/test/compile-fail/alt-tag-nullary.rs +++ b/src/test/compile-fail/alt-tag-nullary.rs @@ -3,5 +3,5 @@ enum a { A, } enum b { B, } -fn main() { let x: a = A; alt x { B { } } } +fn main() { let x: a = A; alt x { B => { } } } diff --git a/src/test/compile-fail/alt-tag-unary.rs b/src/test/compile-fail/alt-tag-unary.rs index b3aec729053..f0546574912 100644 --- a/src/test/compile-fail/alt-tag-unary.rs +++ b/src/test/compile-fail/alt-tag-unary.rs @@ -3,5 +3,5 @@ enum a { A(int), } enum b { B(int), } -fn main() { let x: a = A(0); alt x { B(y) { } } } +fn main() { let x: a = A(0); alt x { B(y) => { } } } diff --git a/src/test/compile-fail/bad-record-pat-2.rs b/src/test/compile-fail/bad-record-pat-2.rs index 5647fef472b..4c8d72444c1 100644 --- a/src/test/compile-fail/bad-record-pat-2.rs +++ b/src/test/compile-fail/bad-record-pat-2.rs @@ -1,3 +1,3 @@ // error-pattern:did not expect a record with a field `q` -fn main() { alt {x: 1, y: 2} { {x: x, q: q} { } } } +fn main() { alt {x: 1, y: 2} { {x: x, q: q} => { } } } diff --git a/src/test/compile-fail/bad-record-pat.rs b/src/test/compile-fail/bad-record-pat.rs index 1b12d274ce8..48155a0b529 100644 --- a/src/test/compile-fail/bad-record-pat.rs +++ b/src/test/compile-fail/bad-record-pat.rs @@ -1,3 +1,3 @@ // error-pattern:expected a record with 2 fields, found one with 1 -fn main() { alt {x: 1, y: 2} { {x: x} { } } } +fn main() { alt {x: 1, y: 2} { {x: x} => { } } } diff --git a/src/test/compile-fail/bogus-tag.rs b/src/test/compile-fail/bogus-tag.rs index e578816c0e3..0414bb5e867 100644 --- a/src/test/compile-fail/bogus-tag.rs +++ b/src/test/compile-fail/bogus-tag.rs @@ -7,8 +7,8 @@ enum color { rgb(int, int, int), rgba(int, int, int, int), } fn main() { let red: color = rgb(255, 0, 0); alt red { - rgb(r, g, b) { debug!{"rgb"}; } - hsl(h, s, l) { debug!{"hsl"}; } + rgb(r, g, b) => { debug!{"rgb"}; } + hsl(h, s, l) => { debug!{"hsl"}; } } } diff --git a/src/test/compile-fail/borrowck-issue-2657-1.rs b/src/test/compile-fail/borrowck-issue-2657-1.rs index 520ae1bf646..2d396bd591c 100644 --- a/src/test/compile-fail/borrowck-issue-2657-1.rs +++ b/src/test/compile-fail/borrowck-issue-2657-1.rs @@ -1,9 +1,9 @@ fn main() { let x = some(~1); alt x { //~ NOTE loan of immutable local variable granted here - some(y) { + some(y) => { let _a <- x; //~ ERROR moving out of immutable local variable prohibited due to outstanding loan } - _ {} + _ => {} } } diff --git a/src/test/compile-fail/borrowck-issue-2657-2.rs b/src/test/compile-fail/borrowck-issue-2657-2.rs index 07e4ca8229b..85d062dd98c 100644 --- a/src/test/compile-fail/borrowck-issue-2657-2.rs +++ b/src/test/compile-fail/borrowck-issue-2657-2.rs @@ -1,9 +1,9 @@ fn main() { let x = some(~1); alt x { - some(y) { + some(y) => { let _b <- y; //~ ERROR moving out of pattern binding } - _ {} + _ => {} } } diff --git a/src/test/compile-fail/borrowck-no-cycle-in-exchange-heap.rs b/src/test/compile-fail/borrowck-no-cycle-in-exchange-heap.rs index a4aeb976e95..acb018dbb2d 100644 --- a/src/test/compile-fail/borrowck-no-cycle-in-exchange-heap.rs +++ b/src/test/compile-fail/borrowck-no-cycle-in-exchange-heap.rs @@ -6,7 +6,7 @@ fn main() { let x = ~node({mut a: ~empty}); // Create a cycle! alt check *x { //~ NOTE loan of immutable local variable granted here - node(y) { + node(y) => { y.a <- x; //~ ERROR moving out of immutable local variable prohibited due to outstanding loan } }; diff --git a/src/test/compile-fail/borrowck-pat-enum-in-box.rs b/src/test/compile-fail/borrowck-pat-enum-in-box.rs index 86ff452c356..103de904609 100644 --- a/src/test/compile-fail/borrowck-pat-enum-in-box.rs +++ b/src/test/compile-fail/borrowck-pat-enum-in-box.rs @@ -1,14 +1,14 @@ fn match_imm_box(v: &const @option<int>) -> int { alt *v { - @some(i) {i} - @none {0} + @some(i) => {i} + @none => {0} } } fn match_const_box(v: &const @const option<int>) -> int { alt *v { - @some(i) { i } // ok because this is pure - @none {0} + @some(i) => { i } // ok because this is pure + @none => {0} } } @@ -16,10 +16,10 @@ pure fn pure_process(_i: int) {} fn match_const_box_and_do_pure_things(v: &const @const option<int>) { alt *v { - @some(i) { + @some(i) => { pure_process(i) } - @none {} + @none => {} } } @@ -27,10 +27,10 @@ fn process(_i: int) {} fn match_const_box_and_do_bad_things(v: &const @const option<int>) { alt *v { - @some(i) { //~ ERROR illegal borrow unless pure: enum variant in aliasable, mutable location + @some(i) => { //~ ERROR illegal borrow unless pure: enum variant in aliasable, mutable location process(i) //~ NOTE impure due to access to impure function } - @none {} + @none => {} } } diff --git a/src/test/compile-fail/borrowck-pat-enum.rs b/src/test/compile-fail/borrowck-pat-enum.rs index 091467283c5..6dd37e647ac 100644 --- a/src/test/compile-fail/borrowck-pat-enum.rs +++ b/src/test/compile-fail/borrowck-pat-enum.rs @@ -1,23 +1,23 @@ fn match_ref(&&v: option<int>) -> int { alt v { - some(i) { + some(i) => { i } - none {0} + none => {0} } } fn match_ref_unused(&&v: option<int>) { alt v { - some(_) {} - none {} + some(_) => {} + none => {} } } fn match_const_reg(v: &const option<int>) -> int { alt *v { - some(i) {i} // OK because this is pure - none {0} + some(i) => {i} // OK because this is pure + none => {0} } } @@ -26,23 +26,23 @@ fn impure(_i: int) { fn match_const_reg_unused(v: &const option<int>) { alt *v { - some(_) {impure(0)} // OK because nothing is captured - none {} + some(_) => {impure(0)} // OK because nothing is captured + none => {} } } fn match_const_reg_impure(v: &const option<int>) { alt *v { - some(i) {impure(i)} //~ ERROR illegal borrow unless pure: enum variant in aliasable, mutable location + some(i) => {impure(i)} //~ ERROR illegal borrow unless pure: enum variant in aliasable, mutable location //~^ NOTE impure due to access to impure function - none {} + none => {} } } fn match_imm_reg(v: &option<int>) { alt *v { - some(i) {impure(i)} // OK because immutable - none {} + some(i) => {impure(i)} // OK because immutable + none => {} } } diff --git a/src/test/compile-fail/borrowck-pat-reassign-binding.rs b/src/test/compile-fail/borrowck-pat-reassign-binding.rs index 7ce3ff8f028..2d7f33e6620 100644 --- a/src/test/compile-fail/borrowck-pat-reassign-binding.rs +++ b/src/test/compile-fail/borrowck-pat-reassign-binding.rs @@ -3,8 +3,8 @@ fn main() { let mut x: option<int> = none; alt x { //~ NOTE loan of mutable local variable granted here - none {} - some(i) { + none => {} + some(i) => { // Not ok: i is an outstanding ptr into x. x = some(i+1); //~ ERROR assigning to mutable local variable prohibited due to outstanding loan } diff --git a/src/test/compile-fail/borrowck-pat-reassign-sometimes-binding.rs b/src/test/compile-fail/borrowck-pat-reassign-sometimes-binding.rs index 1e1de3e39cf..12c2d0ef6e8 100644 --- a/src/test/compile-fail/borrowck-pat-reassign-sometimes-binding.rs +++ b/src/test/compile-fail/borrowck-pat-reassign-sometimes-binding.rs @@ -3,12 +3,12 @@ fn main() { let mut x = none; alt x { //~ NOTE loan of mutable local variable granted here - none { + none => { // It is ok to reassign x here, because there is in // fact no outstanding loan of x! x = some(0); } - some(i) { + some(i) => { x = some(1); //~ ERROR assigning to mutable local variable prohibited due to outstanding loan } } diff --git a/src/test/compile-fail/borrowck-unchecked-with-borrow.rs b/src/test/compile-fail/borrowck-unchecked-with-borrow.rs index c0a2466199f..34031aa70d6 100644 --- a/src/test/compile-fail/borrowck-unchecked-with-borrow.rs +++ b/src/test/compile-fail/borrowck-unchecked-with-borrow.rs @@ -3,25 +3,25 @@ fn impure(_i: int) {} // check that unchecked alone does not override borrowck: fn foo(v: &const option<int>) { alt *v { - some(i) { + some(i) => { //~^ ERROR illegal borrow unless pure: enum variant in aliasable, mutable location unchecked { impure(i); //~ NOTE impure due to access to impure function } } - none { + none => { } } } fn bar(v: &const option<int>) { alt *v { - some(i) { + some(i) => { unsafe { impure(i); } } - none { + none => { } } } diff --git a/src/test/compile-fail/deref-non-pointer.rs b/src/test/compile-fail/deref-non-pointer.rs index 3e4b7b73b60..5468a46a6a7 100644 --- a/src/test/compile-fail/deref-non-pointer.rs +++ b/src/test/compile-fail/deref-non-pointer.rs @@ -1,6 +1,6 @@ // error-pattern:cannot be dereferenced fn main() { alt *1 { - _ { fail; } + _ => { fail; } } } \ No newline at end of file diff --git a/src/test/compile-fail/issue-1193.rs b/src/test/compile-fail/issue-1193.rs index d6ab1e44211..4ac885e5b10 100644 --- a/src/test/compile-fail/issue-1193.rs +++ b/src/test/compile-fail/issue-1193.rs @@ -7,8 +7,8 @@ mod foo { fn bar(v: t) -> bool { alt v { - a { return true; } - b { return false; } + a => { return true; } + b => { return false; } } } } diff --git a/src/test/compile-fail/issue-2111.rs b/src/test/compile-fail/issue-2111.rs index 957d84eaa84..f5639a887f0 100644 --- a/src/test/compile-fail/issue-2111.rs +++ b/src/test/compile-fail/issue-2111.rs @@ -1,8 +1,8 @@ fn foo(a: option<uint>, b: option<uint>) { alt (a,b) { //~ ERROR: non-exhaustive patterns: none not covered - (some(a), some(b)) if a == b { } + (some(a), some(b)) if a == b => { } (some(_), none) | - (none, some(_)) { } + (none, some(_)) => { } } } diff --git a/src/test/compile-fail/issue-2848.rs b/src/test/compile-fail/issue-2848.rs index 606c5fc8e00..376426bb82e 100644 --- a/src/test/compile-fail/issue-2848.rs +++ b/src/test/compile-fail/issue-2848.rs @@ -9,7 +9,7 @@ mod bar { fn main() { import bar::{alpha, charlie}; alt alpha { - alpha | beta {} //~ ERROR: inconsistent number of bindings - charlie {} + alpha | beta => {} //~ ERROR: inconsistent number of bindings + charlie => {} } } diff --git a/src/test/compile-fail/issue-2849.rs b/src/test/compile-fail/issue-2849.rs index 5fed9f2d26c..6085fc9fe8f 100644 --- a/src/test/compile-fail/issue-2849.rs +++ b/src/test/compile-fail/issue-2849.rs @@ -2,6 +2,6 @@ enum foo { alpha, beta(int) } fn main() { alt alpha { - alpha | beta(i) {} //~ ERROR inconsistent number of bindings + alpha | beta(i) => {} //~ ERROR inconsistent number of bindings } } diff --git a/src/test/compile-fail/issue-3038.rs b/src/test/compile-fail/issue-3038.rs index 0728dca2e8b..f5aa30c1416 100644 --- a/src/test/compile-fail/issue-3038.rs +++ b/src/test/compile-fail/issue-3038.rs @@ -9,17 +9,17 @@ fn main() { let _z = alt g(1, 2) { - g(x, x) { log(debug, x + x); } + g(x, x) => { log(debug, x + x); } //~^ ERROR Identifier x is bound more than once in the same pattern }; let _z = alt i(l(1, 2), m(3, 4)) { i(l(x, _), m(_, x)) //~ ERROR Identifier x is bound more than once in the same pattern - { log(error, x + x); } + => { log(error, x + x); } }; let _z = alt (1, 2) { - (x, x) { x } //~ ERROR Identifier x is bound more than once in the same pattern + (x, x) => { x } //~ ERROR Identifier x is bound more than once in the same pattern }; } diff --git a/src/test/compile-fail/liveness-missing-ret2.rs b/src/test/compile-fail/liveness-missing-ret2.rs index 8cb365afbf6..e1803b0248a 100644 --- a/src/test/compile-fail/liveness-missing-ret2.rs +++ b/src/test/compile-fail/liveness-missing-ret2.rs @@ -3,7 +3,7 @@ fn f() -> int { // Make sure typestate doesn't interpreturn this alt expression // as the function result - alt check true { true { } }; + alt check true { true => { } }; } fn main() { } diff --git a/src/test/compile-fail/liveness-unused.rs b/src/test/compile-fail/liveness-unused.rs index 28c531b3b81..4f9e62e0502 100644 --- a/src/test/compile-fail/liveness-unused.rs +++ b/src/test/compile-fail/liveness-unused.rs @@ -28,9 +28,9 @@ fn f3b() { fn f4() { alt some(3) { - some(i) { + some(i) => { } - none {} + none => {} } } diff --git a/src/test/compile-fail/non-exhaustive-match-nested.rs b/src/test/compile-fail/non-exhaustive-match-nested.rs index 37490724a23..dea250a734c 100644 --- a/src/test/compile-fail/non-exhaustive-match-nested.rs +++ b/src/test/compile-fail/non-exhaustive-match-nested.rs @@ -6,8 +6,8 @@ enum u { c, d } fn main() { let x = a(c); alt x { - a(d) { fail ~"hello"; } - b { fail ~"goodbye"; } + a(d) => { fail ~"hello"; } + b => { fail ~"goodbye"; } } } diff --git a/src/test/compile-fail/non-exhaustive-match.rs b/src/test/compile-fail/non-exhaustive-match.rs index 0d004df5c1a..e712406ba19 100644 --- a/src/test/compile-fail/non-exhaustive-match.rs +++ b/src/test/compile-fail/non-exhaustive-match.rs @@ -2,27 +2,27 @@ enum t { a, b, } fn main() { let x = a; - alt x { b { } } //~ ERROR non-exhaustive patterns + alt x { b => { } } //~ ERROR non-exhaustive patterns alt true { //~ ERROR non-exhaustive patterns - true {} + true => {} } alt @some(10) { //~ ERROR non-exhaustive patterns - @none {} + @none => {} } alt (2, 3, 4) { //~ ERROR non-exhaustive patterns - (_, _, 4) {} + (_, _, 4) => {} } alt (a, a) { //~ ERROR non-exhaustive patterns - (a, b) {} - (b, a) {} + (a, b) => {} + (b, a) => {} } alt a { //~ ERROR b not covered - a {} + a => {} } // This is exhaustive, though the algorithm got it wrong at one point alt (a, b) { - (a, _) {} - (_, a) {} - (b, b) {} + (a, _) => {} + (_, a) => {} + (b, b) => {} } } diff --git a/src/test/compile-fail/occurs-check-3.rs b/src/test/compile-fail/occurs-check-3.rs index 870b86d42c3..207bbd91cc5 100644 --- a/src/test/compile-fail/occurs-check-3.rs +++ b/src/test/compile-fail/occurs-check-3.rs @@ -1,4 +1,4 @@ // error-pattern:mismatched types // From Issue #778 enum clam<T> { a(T), } -fn main() { let c; c = a(c); alt c { a::<int>(_) { } } } +fn main() { let c; c = a(c); alt c { a::<int>(_) => { } } } diff --git a/src/test/compile-fail/or-patter-mismatch.rs b/src/test/compile-fail/or-patter-mismatch.rs index 997121f20ca..37d194cbd50 100644 --- a/src/test/compile-fail/or-patter-mismatch.rs +++ b/src/test/compile-fail/or-patter-mismatch.rs @@ -2,4 +2,4 @@ enum blah { a(int, int, uint), b(int, int), } -fn main() { alt a(1, 1, 2u) { a(_, x, y) | b(x, y) { } } } +fn main() { alt a(1, 1, 2u) { a(_, x, y) | b(x, y) => { } } } diff --git a/src/test/compile-fail/pattern-tyvar-2.rs b/src/test/compile-fail/pattern-tyvar-2.rs index 3e9648e19c9..1dee20e0ef6 100644 --- a/src/test/compile-fail/pattern-tyvar-2.rs +++ b/src/test/compile-fail/pattern-tyvar-2.rs @@ -8,6 +8,6 @@ import option::some; enum bar { t1((), option<~[int]>), t2, } -fn foo(t: bar) -> int { alt t { t1(_, some(x)) { return x * 3; } _ { fail; } } } +fn foo(t: bar) -> int { alt t { t1(_, some(x)) => { return x * 3; } _ => { fail; } } } fn main() { } diff --git a/src/test/compile-fail/pattern-tyvar.rs b/src/test/compile-fail/pattern-tyvar.rs index 8be922cd93a..2622dadc040 100644 --- a/src/test/compile-fail/pattern-tyvar.rs +++ b/src/test/compile-fail/pattern-tyvar.rs @@ -9,10 +9,10 @@ enum bar { t1((), option<~[int]>), t2, } fn foo(t: bar) { alt t { - t1(_, some::<int>(x)) { + t1(_, some::<int>(x)) => { log(debug, x); } - _ { fail; } + _ => { fail; } } } diff --git a/src/test/compile-fail/regions-creating-enums.rs b/src/test/compile-fail/regions-creating-enums.rs index 02780c70ed8..0702618c68c 100644 --- a/src/test/compile-fail/regions-creating-enums.rs +++ b/src/test/compile-fail/regions-creating-enums.rs @@ -12,17 +12,17 @@ fn build() { fn compute(x: &ast) -> uint { alt *x { - num(x) { x } - add(x, y) { compute(x) + compute(y) } + num(x) => { x } + add(x, y) => { compute(x) + compute(y) } } } fn map_nums(x: &ast, f: fn(uint) -> uint) -> &ast { alt *x { - num(x) { + num(x) => { return &num(f(x)); //~ ERROR illegal borrow } - add(x, y) { + add(x, y) => { let m_x = map_nums(x, f); let m_y = map_nums(y, f); return &add(m_x, m_y); //~ ERROR illegal borrow diff --git a/src/test/compile-fail/unreachable-arm.rs b/src/test/compile-fail/unreachable-arm.rs index 89d31a41dcc..1865fe6aff9 100644 --- a/src/test/compile-fail/unreachable-arm.rs +++ b/src/test/compile-fail/unreachable-arm.rs @@ -2,4 +2,4 @@ enum foo { a(@foo, int), b(uint), } -fn main() { alt b(1u) { b(_) | a(@_, 1) { } a(_, 1) { } } } +fn main() { alt b(1u) { b(_) | a(@_, 1) => { } a(_, 1) => { } } } diff --git a/src/test/pretty/block-disambig.rs b/src/test/pretty/block-disambig.rs index 0f504bb8e89..14a8629ab72 100644 --- a/src/test/pretty/block-disambig.rs +++ b/src/test/pretty/block-disambig.rs @@ -8,7 +8,7 @@ fn test2() -> int { let val = @0; { } *val } fn test3() { let regs = @{mut eax: 0}; - alt check true { true { } } + alt check true { true => { } } (*regs).eax = 1; } @@ -20,14 +20,14 @@ fn test6() -> bool { { } (true || false) && true } fn test7() -> uint { let regs = @0; - alt check true { true { } } + alt check true { true => { } } (*regs < 2) as uint } fn test8() -> int { let val = @0; alt check true { - true { } + true => { } } if *val < 1 { 0 @@ -36,11 +36,11 @@ fn test8() -> int { } } -fn test9() { let regs = @mut 0; alt check true { true { } } *regs += 1; } +fn test9() { let regs = @mut 0; alt check true { true => { } } *regs += 1; } fn test10() -> int { let regs = @mut ~[0]; - alt check true { true { } } + alt check true { true => { } } (*regs)[0] } diff --git a/src/test/pretty/unary-op-disambig.rs b/src/test/pretty/unary-op-disambig.rs index e9fd2c2dc2c..1f9d68cc8a2 100644 --- a/src/test/pretty/unary-op-disambig.rs +++ b/src/test/pretty/unary-op-disambig.rs @@ -10,8 +10,8 @@ fn if_semi() -> int { if true { f() } else { f() }; -1 } fn if_nosemi() -> int { (if true { 0 } else { 0 }) - 1 } -fn alt_semi() -> int { alt check true { true { f() } }; -1 } +fn alt_semi() -> int { alt check true { true => { f() } }; -1 } -fn alt_no_semi() -> int { (alt check true { true { 0 } }) - 1 } +fn alt_no_semi() -> int { (alt check true { true => { 0 } }) - 1 } fn stmt() { { f() }; -1; } diff --git a/src/test/run-fail/alt-bot-fail.rs b/src/test/run-fail/alt-bot-fail.rs index 88c6688b766..08320af9775 100644 --- a/src/test/run-fail/alt-bot-fail.rs +++ b/src/test/run-fail/alt-bot-fail.rs @@ -4,6 +4,6 @@ fn foo(s: ~str) { } fn main() { let i = - alt some::<int>(3) { none::<int> { fail } some::<int>(_) { fail } }; + alt some::<int>(3) { none::<int> => { fail } some::<int>(_) => { fail } }; foo(i); } diff --git a/src/test/run-fail/alt-disc-bot.rs b/src/test/run-fail/alt-disc-bot.rs index 09770179ebf..ab444a8273e 100644 --- a/src/test/run-fail/alt-disc-bot.rs +++ b/src/test/run-fail/alt-disc-bot.rs @@ -1,4 +1,4 @@ // error-pattern:quux fn f() -> ! { fail ~"quux" } -fn g() -> int { alt f() { true { 1 } false { 0 } } } +fn g() -> int { alt f() { true => { 1 } false => { 0 } } } fn main() { g(); } diff --git a/src/test/run-fail/alt-wildcards.rs b/src/test/run-fail/alt-wildcards.rs index 4a428f3cdb1..3a3c4c5a0a8 100644 --- a/src/test/run-fail/alt-wildcards.rs +++ b/src/test/run-fail/alt-wildcards.rs @@ -1,8 +1,8 @@ // error-pattern:squirrelcupcake fn cmp() -> int { alt check (option::some('a'), option::none::<char>) { - (option::some(_), _) { fail ~"squirrelcupcake"; } - (_, option::some(_)) { fail; } + (option::some(_), _) => { fail ~"squirrelcupcake"; } + (_, option::some(_)) => { fail; } } } diff --git a/src/test/run-fail/expr-alt-fail-fn.rs b/src/test/run-fail/expr-alt-fail-fn.rs index 5a1d410bec1..f6d3779b9f0 100644 --- a/src/test/run-fail/expr-alt-fail-fn.rs +++ b/src/test/run-fail/expr-alt-fail-fn.rs @@ -4,6 +4,6 @@ // error-pattern:explicit failure fn f() -> ! { fail } -fn g() -> int { let x = alt true { true { f() } false { 10 } }; return x; } +fn g() -> int { let x = alt true { true => { f() } false => { 10 } }; return x; } fn main() { g(); } diff --git a/src/test/run-fail/expr-alt-fail.rs b/src/test/run-fail/expr-alt-fail.rs index 230497135cd..3a70b690755 100644 --- a/src/test/run-fail/expr-alt-fail.rs +++ b/src/test/run-fail/expr-alt-fail.rs @@ -2,4 +2,4 @@ // error-pattern:explicit failure -fn main() { let x = alt true { false { 0 } true { fail } }; } +fn main() { let x = alt true { false => { 0 } true => { fail } }; } diff --git a/src/test/run-fail/issue-2156.rs b/src/test/run-fail/issue-2156.rs index 1e8fea9d111..026af3a2f65 100644 --- a/src/test/run-fail/issue-2156.rs +++ b/src/test/run-fail/issue-2156.rs @@ -5,6 +5,6 @@ import io::{reader, reader_util}; fn main() { do io::with_str_reader(~"") |rdr| { - alt rdr.read_char() { '=' { } _ { fail } } + alt rdr.read_char() { '=' => { } _ => { fail } } } } diff --git a/src/test/run-fail/unwind-alt.rs b/src/test/run-fail/unwind-alt.rs index 751dc722fc8..d5f013a42b6 100644 --- a/src/test/run-fail/unwind-alt.rs +++ b/src/test/run-fail/unwind-alt.rs @@ -4,7 +4,7 @@ fn test_box() { @0; } fn test_str() { - let res = alt check false { true { ~"happy" } }; + let res = alt check false { true => { ~"happy" } }; assert res == ~"happy"; } fn main() { diff --git a/src/test/run-pass/alt-bot-2.rs b/src/test/run-pass/alt-bot-2.rs index 341fcdc38d5..cbf1519dc34 100644 --- a/src/test/run-pass/alt-bot-2.rs +++ b/src/test/run-pass/alt-bot-2.rs @@ -1,3 +1,3 @@ // n.b. This was only ever failing with optimization disabled. -fn a() -> int { alt check return 1 { 2 { 3 } } } +fn a() -> int { alt check return 1 { 2 => 3 } } fn main() { a(); } diff --git a/src/test/run-pass/alt-bot.rs b/src/test/run-pass/alt-bot.rs index bf5f963e9cc..7162bf69aa5 100644 --- a/src/test/run-pass/alt-bot.rs +++ b/src/test/run-pass/alt-bot.rs @@ -1,6 +1,6 @@ fn main() { let i: int = - alt some::<int>(3) { none::<int> { fail } some::<int>(_) { 5 } }; + alt some::<int>(3) { none::<int> => { fail } some::<int>(_) => { 5 } }; log(debug, i); } diff --git a/src/test/run-pass/alt-implicit-copy-unique.rs b/src/test/run-pass/alt-implicit-copy-unique.rs index bef4af11be4..796a73a0204 100644 --- a/src/test/run-pass/alt-implicit-copy-unique.rs +++ b/src/test/run-pass/alt-implicit-copy-unique.rs @@ -1,6 +1,6 @@ fn main() { let x = ~{mut a: ~10, b: ~20}; alt x { - ~{a, b} { assert *a == 10; (*x).a = ~30; assert *a == 30; } + ~{a, b} => { assert *a == 10; (*x).a = ~30; assert *a == 30; } } } diff --git a/src/test/run-pass/alt-implicit-copy.rs b/src/test/run-pass/alt-implicit-copy.rs index 63cbdf6ca79..355e678d3a3 100644 --- a/src/test/run-pass/alt-implicit-copy.rs +++ b/src/test/run-pass/alt-implicit-copy.rs @@ -1,6 +1,6 @@ fn main() { let x = @{mut a: @10, b: @20}; alt x { - @{a, b} { assert *a == 10; (*x).a = @30; assert *a == 30; } + @{a, b} => { assert *a == 10; (*x).a = @30; assert *a == 30; } } } diff --git a/src/test/run-pass/alt-join.rs b/src/test/run-pass/alt-join.rs index 2ba2fedb386..2d4078ced04 100644 --- a/src/test/run-pass/alt-join.rs +++ b/src/test/run-pass/alt-join.rs @@ -9,7 +9,13 @@ fn foo<T>(y: option<T>) { entire if expression */ if true { - } else { alt y { none::<T> { x = 17; } _ { x = 42; } } rs += ~[x]; } + } else { + alt y { + none::<T> => x = 17, + _ => x = 42 + } + rs += ~[x]; + } return; } diff --git a/src/test/run-pass/alt-path.rs b/src/test/run-pass/alt-path.rs index aa3ccfcbafd..aa9e9f18481 100644 --- a/src/test/run-pass/alt-path.rs +++ b/src/test/run-pass/alt-path.rs @@ -4,6 +4,6 @@ mod m1 { enum foo { foo1, foo2, } } -fn bar(x: m1::foo) { alt x { m1::foo1 { } m1::foo2 { } } } +fn bar(x: m1::foo) { alt x { m1::foo1 => { } m1::foo2 => { } } } fn main() { } diff --git a/src/test/run-pass/alt-pattern-drop.rs b/src/test/run-pass/alt-pattern-drop.rs index b8ce7299271..92366e54b30 100644 --- a/src/test/run-pass/alt-pattern-drop.rs +++ b/src/test/run-pass/alt-pattern-drop.rs @@ -10,11 +10,11 @@ fn foo(s: @int) { let x: t = make_t(s); // ref up alt x { - make_t(y) { + make_t(y) => { log(debug, y); // ref up then down } - _ { debug!{"?"}; fail; } + _ => { debug!{"?"}; fail; } } log(debug, sys::refcount(s)); assert (sys::refcount(s) == count + 1u); diff --git a/src/test/run-pass/alt-pattern-lit.rs b/src/test/run-pass/alt-pattern-lit.rs index aba7336a23b..bc1f788abc0 100644 --- a/src/test/run-pass/alt-pattern-lit.rs +++ b/src/test/run-pass/alt-pattern-lit.rs @@ -2,8 +2,8 @@ fn altlit(f: int) -> int { alt check f { - 10 { debug!{"case 10"}; return 20; } - 11 { debug!{"case 11"}; return 22; } + 10 => { debug!{"case 10"}; return 20; } + 11 => { debug!{"case 11"}; return 22; } } } diff --git a/src/test/run-pass/alt-pattern-no-type-params.rs b/src/test/run-pass/alt-pattern-no-type-params.rs index 91340f94333..badad32ce28 100644 --- a/src/test/run-pass/alt-pattern-no-type-params.rs +++ b/src/test/run-pass/alt-pattern-no-type-params.rs @@ -1,7 +1,7 @@ enum maybe<T> { nothing, just(T), } fn foo(x: maybe<int>) { - alt x { nothing { error!{"A"}; } just(a) { error!{"B"}; } } + alt x { nothing => { error!{"A"}; } just(a) => { error!{"B"}; } } } fn main() { } diff --git a/src/test/run-pass/alt-pattern-simple.rs b/src/test/run-pass/alt-pattern-simple.rs index e29cd72ac77..e4ca776bb61 100644 --- a/src/test/run-pass/alt-pattern-simple.rs +++ b/src/test/run-pass/alt-pattern-simple.rs @@ -1,5 +1,5 @@ -fn altsimple(f: int) { alt f { x { } } } +fn altsimple(f: int) { alt f { x => () } } fn main() { } diff --git a/src/test/run-pass/alt-phi.rs b/src/test/run-pass/alt-phi.rs index 5a99563e2af..358b8d64e6c 100644 --- a/src/test/run-pass/alt-phi.rs +++ b/src/test/run-pass/alt-phi.rs @@ -7,8 +7,8 @@ fn foo(it: fn(int)) { it(10); } fn main() { let mut x = true; alt a { - a { x = true; foo(|_i| { } ) } - b { x = false; } - c { x = false; } + a => { x = true; foo(|_i| { } ) } + b => { x = false; } + c => { x = false; } } } diff --git a/src/test/run-pass/alt-range.rs b/src/test/run-pass/alt-range.rs index 29bbc452d47..75ca1dd5e52 100644 --- a/src/test/run-pass/alt-range.rs +++ b/src/test/run-pass/alt-range.rs @@ -1,30 +1,30 @@ fn main() { alt 5u { - 1u to 5u {} - _ { fail ~"should match range"; } + 1u to 5u => {} + _ => fail ~"should match range", } alt 5u { - 6u to 7u { fail ~"shouldn't match range"; } - _ {} + 6u to 7u => fail ~"shouldn't match range", + _ => {} } alt check 5u { - 1u { fail ~"should match non-first range"; } - 2u to 6u {} + 1u => fail ~"should match non-first range", + 2u to 6u => {} } alt 'c' { - 'a' to 'z' {} - _ { fail ~"should suppport char ranges"; } + 'a' to 'z' => {} + _ => fail ~"should suppport char ranges" } alt -3 { - -7 to 5 {} - _ { fail ~"should match signed range"; } + -7 to 5 => {} + _ => fail ~"should match signed range" } alt 3.0 { - 1.0 to 5.0 {} - _ { fail ~"should match float range"; } + 1.0 to 5.0 => {} + _ => fail ~"should match float range" } alt -1.5 { - -3.6 to 3.6 {} - _ { fail ~"should match negative float range"; } + -3.6 to 3.6 => {} + _ => fail ~"should match negative float range" } } diff --git a/src/test/run-pass/alt-str.rs b/src/test/run-pass/alt-str.rs index 708932b2e1a..4693635458d 100644 --- a/src/test/run-pass/alt-str.rs +++ b/src/test/run-pass/alt-str.rs @@ -1,21 +1,21 @@ // Issue #53 fn main() { - alt check ~"test" { ~"not-test" { fail; } ~"test" { } _ { fail; } } + alt check ~"test" { ~"not-test" => fail, ~"test" => (), _ => fail } enum t { tag1(~str), tag2, } alt tag1(~"test") { - tag2 { fail; } - tag1(~"not-test") { fail; } - tag1(~"test") { } - _ { fail; } + tag2 => fail, + tag1(~"not-test") => fail, + tag1(~"test") => (), + _ => fail } - let x = alt check ~"a" { ~"a" { 1 } ~"b" { 2 } }; + let x = alt check ~"a" { ~"a" => 1, ~"b" => 2 }; assert (x == 1); - alt check ~"a" { ~"a" { } ~"b" { } } + alt check ~"a" { ~"a" => { } ~"b" => { } } } diff --git a/src/test/run-pass/alt-tag.rs b/src/test/run-pass/alt-tag.rs index f58eb29edb2..4b8cdce110e 100644 --- a/src/test/run-pass/alt-tag.rs +++ b/src/test/run-pass/alt-tag.rs @@ -11,9 +11,9 @@ enum color { fn process(c: color) -> int { let mut x: int; alt c { - rgb(r, _, _) { debug!{"rgb"}; log(debug, r); x = r; } - rgba(_, _, _, a) { debug!{"rgba"}; log(debug, a); x = a; } - hsl(_, s, _) { debug!{"hsl"}; log(debug, s); x = s; } + rgb(r, _, _) => { debug!{"rgb"}; log(debug, r); x = r; } + rgba(_, _, _, a) => { debug!{"rgba"}; log(debug, a); x = a; } + hsl(_, s, _) => { debug!{"hsl"}; log(debug, s); x = s; } } return x; } diff --git a/src/test/run-pass/alt-unique-bind.rs b/src/test/run-pass/alt-unique-bind.rs index 0f47c910529..b907afa1e8d 100644 --- a/src/test/run-pass/alt-unique-bind.rs +++ b/src/test/run-pass/alt-unique-bind.rs @@ -1,6 +1,6 @@ fn main() { alt ~100 { - ~x { + ~x => { debug!{"%?", x}; assert x == 100; } diff --git a/src/test/run-pass/alt-with-ret-arm.rs b/src/test/run-pass/alt-with-ret-arm.rs index 74a7e36a6e6..50c03e71be2 100644 --- a/src/test/run-pass/alt-with-ret-arm.rs +++ b/src/test/run-pass/alt-with-ret-arm.rs @@ -3,8 +3,8 @@ fn main() { // the right type for f, as we unified // bot and u32 here let f = alt uint::from_str(~"1234") { - none { return () } - some(num) { num as u32 } + none => return (), + some(num) => num as u32 }; assert f == 1234u32; log(error, f) diff --git a/src/test/run-pass/binary-minus-without-space.rs b/src/test/run-pass/binary-minus-without-space.rs index 79627d5501d..d2df3b2dab3 100644 --- a/src/test/run-pass/binary-minus-without-space.rs +++ b/src/test/run-pass/binary-minus-without-space.rs @@ -1,6 +1,6 @@ // Check that issue #954 stays fixed fn main() { - alt check -1 { -1 {} } + alt check -1 { -1 => {} } assert 1-1 == 0; } diff --git a/src/test/run-pass/block-arg.rs b/src/test/run-pass/block-arg.rs index cebafd03f00..685f68c61ad 100644 --- a/src/test/run-pass/block-arg.rs +++ b/src/test/run-pass/block-arg.rs @@ -25,13 +25,13 @@ fn main() { assert false; } alt do vec::all(v) |e| { float::is_negative(e) } { - true { fail ~"incorrect answer."; } - false { } + true => { fail ~"incorrect answer."; } + false => { } } alt 3 { - _ if do vec::any(v) |e| { float::is_negative(e) } { + _ if do vec::any(v) |e| { float::is_negative(e) } => { } - _ { + _ => { fail ~"wrong answer."; } } diff --git a/src/test/run-pass/borrowck-pat-reassign-no-binding.rs b/src/test/run-pass/borrowck-pat-reassign-no-binding.rs index 73a7085d865..bbc2abf51af 100644 --- a/src/test/run-pass/borrowck-pat-reassign-no-binding.rs +++ b/src/test/run-pass/borrowck-pat-reassign-no-binding.rs @@ -1,11 +1,11 @@ fn main() { let mut x = none; alt x { - none { + none => { // It is ok to reassign x here, because there is in // fact no outstanding loan of x! x = some(0); } - some(_) { } + some(_) => { } } } diff --git a/src/test/run-pass/borrowck-preserve-box-in-arm-not-taken.rs b/src/test/run-pass/borrowck-preserve-box-in-arm-not-taken.rs index 9b49e3cd044..87b4fd59e5f 100644 --- a/src/test/run-pass/borrowck-preserve-box-in-arm-not-taken.rs +++ b/src/test/run-pass/borrowck-preserve-box-in-arm-not-taken.rs @@ -3,12 +3,12 @@ fn main() { let x: @mut @option<~int> = @mut @none; alt x { - @@some(y) { + @@some(y) => { // here, the refcount of `*x` is bumped so // `y` remains valid even if `*x` is modified. *x = @none; } - @@none { + @@none => { // here, no bump of the ref count of `*x` is needed, but in // fact a bump occurs anyway because of how pattern marching // works. diff --git a/src/test/run-pass/borrowck-preserve-box-in-discr.rs b/src/test/run-pass/borrowck-preserve-box-in-discr.rs index 0bbd2b2d90a..99b446ce315 100644 --- a/src/test/run-pass/borrowck-preserve-box-in-discr.rs +++ b/src/test/run-pass/borrowck-preserve-box-in-discr.rs @@ -3,7 +3,7 @@ fn main() { let mut x = @{f: ~3}; alt *x { - {f: b_x} { + {f: b_x} => { assert *b_x == 3; assert ptr::addr_of(*x.f) == ptr::addr_of(*b_x); diff --git a/src/test/run-pass/borrowck-preserve-box-in-pat.rs b/src/test/run-pass/borrowck-preserve-box-in-pat.rs index cf738e02d2f..7a37432db74 100644 --- a/src/test/run-pass/borrowck-preserve-box-in-pat.rs +++ b/src/test/run-pass/borrowck-preserve-box-in-pat.rs @@ -3,7 +3,7 @@ fn main() { let mut x = @mut @{f: ~3}; alt x { - @@{f: b_x} { + @@{f: b_x} => { assert *b_x == 3; assert ptr::addr_of(x.f) == ptr::addr_of(b_x); diff --git a/src/test/run-pass/borrowck-preserve-box-sometimes-needed.rs b/src/test/run-pass/borrowck-preserve-box-sometimes-needed.rs index 285b3ad8e0f..f8bf02a7703 100644 --- a/src/test/run-pass/borrowck-preserve-box-sometimes-needed.rs +++ b/src/test/run-pass/borrowck-preserve-box-sometimes-needed.rs @@ -3,8 +3,8 @@ fn switcher(x: option<@int>) { let mut x = x; alt x { - some(@y) { copy y; x = none; } - none { } + some(@y) => { copy y; x = none; } + none => { } } } diff --git a/src/test/run-pass/borrowck-univariant-enum.rs b/src/test/run-pass/borrowck-univariant-enum.rs index 3b01c4aa076..fde259046a7 100644 --- a/src/test/run-pass/borrowck-univariant-enum.rs +++ b/src/test/run-pass/borrowck-univariant-enum.rs @@ -10,7 +10,7 @@ fn main() { let x = @mut 5; let y = @mut newtype(3); let z = alt *y { - newtype(b) { + newtype(b) => { *x += 1; *x * b } diff --git a/src/test/run-pass/box-pattern.rs b/src/test/run-pass/box-pattern.rs index 3eb95b70029..faf3ff73b01 100644 --- a/src/test/run-pass/box-pattern.rs +++ b/src/test/run-pass/box-pattern.rs @@ -3,7 +3,7 @@ enum bar { u(@foo), w(int), } fn main() { assert (alt u(@{a: 10, b: 40u}) { - u(@{a: a, b: b}) { a + (b as int) } - _ { 66 } + u(@{a: a, b: b}) => { a + (b as int) } + _ => { 66 } } == 50); } diff --git a/src/test/run-pass/class-impl-very-parameterized-trait.rs b/src/test/run-pass/class-impl-very-parameterized-trait.rs index 326a7a7ae2d..175c5f9936a 100644 --- a/src/test/run-pass/class-impl-very-parameterized-trait.rs +++ b/src/test/run-pass/class-impl-very-parameterized-trait.rs @@ -49,8 +49,8 @@ class cat<T: copy> : map<int, T> { fn contains_key_ref(k: &int) -> bool { self.contains_key(*k) } fn get(+k:int) -> T { alt self.find(k) { - some(v) { v } - none { fail ~"epic fail"; } + some(v) => { v } + none => { fail ~"epic fail"; } } } fn [](&&k:int) -> T { self.get(k) } @@ -62,10 +62,10 @@ class cat<T: copy> : map<int, T> { fn remove(+k:int) -> option<T> { alt self.find(k) { - some(x) { + some(x) => { self.meows -= k; some(x) } - none { none } + none => { none } } } diff --git a/src/test/run-pass/drop-on-empty-block-exit.rs b/src/test/run-pass/drop-on-empty-block-exit.rs index 3632e8833d1..3b9d41fc82a 100644 --- a/src/test/run-pass/drop-on-empty-block-exit.rs +++ b/src/test/run-pass/drop-on-empty-block-exit.rs @@ -2,4 +2,4 @@ enum t { foo(@int), } -fn main() { let tt = foo(@10); alt tt { foo(z) { } } } +fn main() { let tt = foo(@10); alt tt { foo(z) => { } } } diff --git a/src/test/run-pass/expr-alt-box.rs b/src/test/run-pass/expr-alt-box.rs index 9953838b274..8930f113431 100644 --- a/src/test/run-pass/expr-alt-box.rs +++ b/src/test/run-pass/expr-alt-box.rs @@ -5,12 +5,12 @@ // Tests for alt as expressions resulting in boxed types fn test_box() { - let res = alt check true { true { @100 } }; + let res = alt check true { true => { @100 } }; assert (*res == 100); } fn test_str() { - let res = alt check true { true { ~"happy" } }; + let res = alt check true { true => { ~"happy" } }; assert (res == ~"happy"); } diff --git a/src/test/run-pass/expr-alt-fail-all.rs b/src/test/run-pass/expr-alt-fail-all.rs index 3ff8af3cb97..a38464f6d0a 100644 --- a/src/test/run-pass/expr-alt-fail-all.rs +++ b/src/test/run-pass/expr-alt-fail-all.rs @@ -6,7 +6,7 @@ fn main() { let x = alt true { - true { 10 } - false { alt true { true { fail } false { fail } } } + true => { 10 } + false => { alt true { true => { fail } false => { fail } } } }; } diff --git a/src/test/run-pass/expr-alt-fail.rs b/src/test/run-pass/expr-alt-fail.rs index 52ffd09fba3..5635a660f42 100644 --- a/src/test/run-pass/expr-alt-fail.rs +++ b/src/test/run-pass/expr-alt-fail.rs @@ -1,10 +1,10 @@ fn test_simple() { - let r = alt true { true { true } false { fail } }; + let r = alt true { true => { true } false => { fail } }; assert (r == true); } fn test_box() { - let r = alt true { true { ~[10] } false { fail } }; + let r = alt true { true => { ~[10] } false => { fail } }; assert (r[0] == 10); } diff --git a/src/test/run-pass/expr-alt-generic-box1.rs b/src/test/run-pass/expr-alt-generic-box1.rs index 3254996d141..f3f9dee2ff4 100644 --- a/src/test/run-pass/expr-alt-generic-box1.rs +++ b/src/test/run-pass/expr-alt-generic-box1.rs @@ -5,7 +5,7 @@ type compare<T> = fn@(@T, @T) -> bool; fn test_generic<T>(expected: @T, eq: compare<T>) { - let actual: @T = alt check true { true { expected } }; + let actual: @T = alt check true { true => { expected } }; assert (eq(expected, actual)); } diff --git a/src/test/run-pass/expr-alt-generic-box2.rs b/src/test/run-pass/expr-alt-generic-box2.rs index d5fad94a464..e03c196c289 100644 --- a/src/test/run-pass/expr-alt-generic-box2.rs +++ b/src/test/run-pass/expr-alt-generic-box2.rs @@ -5,7 +5,7 @@ type compare<T> = fn@(T, T) -> bool; fn test_generic<T: copy>(expected: T, eq: compare<T>) { - let actual: T = alt check true { true { expected } }; + let actual: T = alt check true { true => { expected } }; assert (eq(expected, actual)); } diff --git a/src/test/run-pass/expr-alt-generic-unique1.rs b/src/test/run-pass/expr-alt-generic-unique1.rs index 35a631062a8..5168fd5ca80 100644 --- a/src/test/run-pass/expr-alt-generic-unique1.rs +++ b/src/test/run-pass/expr-alt-generic-unique1.rs @@ -4,7 +4,7 @@ type compare<T> = fn@(~T, ~T) -> bool; fn test_generic<T: copy>(expected: ~T, eq: compare<T>) { - let actual: ~T = alt check true { true { expected } }; + let actual: ~T = alt check true { true => { expected } }; assert (eq(expected, actual)); } diff --git a/src/test/run-pass/expr-alt-generic-unique2.rs b/src/test/run-pass/expr-alt-generic-unique2.rs index 95b79e9b3b9..e1475373dc2 100644 --- a/src/test/run-pass/expr-alt-generic-unique2.rs +++ b/src/test/run-pass/expr-alt-generic-unique2.rs @@ -5,7 +5,7 @@ type compare<T> = fn@(T, T) -> bool; fn test_generic<T: copy>(expected: T, eq: compare<T>) { - let actual: T = alt check true { true { expected } }; + let actual: T = alt check true { true => { expected } }; assert (eq(expected, actual)); } diff --git a/src/test/run-pass/expr-alt-generic.rs b/src/test/run-pass/expr-alt-generic.rs index b4078a7d907..98536b1afe1 100644 --- a/src/test/run-pass/expr-alt-generic.rs +++ b/src/test/run-pass/expr-alt-generic.rs @@ -5,7 +5,7 @@ type compare<T> = fn@(T, T) -> bool; fn test_generic<T: copy>(expected: T, eq: compare<T>) { - let actual: T = alt check true { true { expected } }; + let actual: T = alt check true { true => { expected } }; assert (eq(expected, actual)); } diff --git a/src/test/run-pass/expr-alt-struct.rs b/src/test/run-pass/expr-alt-struct.rs index 52ec91884f6..2bfef283f9d 100644 --- a/src/test/run-pass/expr-alt-struct.rs +++ b/src/test/run-pass/expr-alt-struct.rs @@ -5,13 +5,13 @@ // Tests for alt as expressions resulting in structural types fn test_rec() { - let rs = alt check true { true { {i: 100} } }; + let rs = alt check true { true => { {i: 100} } }; assert (rs == {i: 100}); } fn test_tag() { enum mood { happy, sad, } - let rs = alt true { true { happy } false { sad } }; + let rs = alt true { true => { happy } false => { sad } }; assert (rs == happy); } diff --git a/src/test/run-pass/expr-alt-unique.rs b/src/test/run-pass/expr-alt-unique.rs index e3a55892955..58a88bee1d3 100644 --- a/src/test/run-pass/expr-alt-unique.rs +++ b/src/test/run-pass/expr-alt-unique.rs @@ -5,7 +5,7 @@ // Tests for alt as expressions resulting in boxed types fn test_box() { - let res = alt check true { true { ~100 } }; + let res = alt check true { true => { ~100 } }; assert (*res == 100); } diff --git a/src/test/run-pass/expr-alt.rs b/src/test/run-pass/expr-alt.rs index 7badeedf824..2e855ce36fa 100644 --- a/src/test/run-pass/expr-alt.rs +++ b/src/test/run-pass/expr-alt.rs @@ -5,14 +5,14 @@ // Tests for using alt as an expression fn test_basic() { - let mut rs: bool = alt true { true { true } false { false } }; + let mut rs: bool = alt true { true => { true } false => { false } }; assert (rs); - rs = alt false { true { false } false { true } }; + rs = alt false { true => { false } false => { true } }; assert (rs); } fn test_inferrence() { - let mut rs = alt true { true { true } false { false } }; + let mut rs = alt true { true => { true } false => { false } }; assert (rs); } @@ -20,9 +20,9 @@ fn test_alt_as_alt_head() { // Yeah, this is kind of confusing ... let rs = - alt alt false { true { true } false { false } } { - true { false } - false { true } + alt alt false { true => { true } false => { false } } { + true => { false } + false => { true } }; assert (rs); } @@ -30,8 +30,8 @@ fn test_alt_as_alt_head() { fn test_alt_as_block_result() { let rs = alt false { - true { false } - false { alt true { true { true } false { false } } } + true => { false } + false => { alt true { true => { true } false => { false } } } }; assert (rs); } diff --git a/src/test/run-pass/expr-empty-ret.rs b/src/test/run-pass/expr-empty-ret.rs index 0a50faf4401..1148d145ba0 100644 --- a/src/test/run-pass/expr-empty-ret.rs +++ b/src/test/run-pass/expr-empty-ret.rs @@ -1,5 +1,5 @@ // Issue #521 -fn f() { let x = alt true { true { 10 } false { return } }; } +fn f() { let x = alt true { true => { 10 } false => { return } }; } fn main() { } diff --git a/src/test/run-pass/expr-fn.rs b/src/test/run-pass/expr-fn.rs index 3b32df0ec79..8d38e5d2941 100644 --- a/src/test/run-pass/expr-fn.rs +++ b/src/test/run-pass/expr-fn.rs @@ -14,7 +14,7 @@ fn test_generic() { } fn test_alt() { - fn f() -> int { alt true { false { 10 } true { 20 } } } + fn f() -> int { alt true { false => { 10 } true => { 20 } } } assert (f() == 20); } diff --git a/src/test/run-pass/generic-tag-alt.rs b/src/test/run-pass/generic-tag-alt.rs index 5857d1ae421..68013a41072 100644 --- a/src/test/run-pass/generic-tag-alt.rs +++ b/src/test/run-pass/generic-tag-alt.rs @@ -4,7 +4,7 @@ enum foo<T> { arm(T), } fn altfoo<T>(f: foo<T>) { let mut hit = false; - alt f { arm::<T>(x) { debug!{"in arm"}; hit = true; } } + alt f { arm::<T>(x) => { debug!{"in arm"}; hit = true; } } assert (hit); } diff --git a/src/test/run-pass/generic-tag-values.rs b/src/test/run-pass/generic-tag-values.rs index d8c039fa413..237c8c7f844 100644 --- a/src/test/run-pass/generic-tag-values.rs +++ b/src/test/run-pass/generic-tag-values.rs @@ -6,10 +6,10 @@ enum noption<T> { some(T), } fn main() { let nop: noption<int> = some::<int>(5); - alt nop { some::<int>(n) { log(debug, n); assert (n == 5); } } + alt nop { some::<int>(n) => { log(debug, n); assert (n == 5); } } let nop2: noption<{x: int, y: int}> = some({x: 17, y: 42}); alt nop2 { - some(t) { + some(t) => { log(debug, t.x); log(debug, t.y); assert (t.x == 17); diff --git a/src/test/run-pass/guards.rs b/src/test/run-pass/guards.rs index 2dc646ee823..a34fa14860d 100644 --- a/src/test/run-pass/guards.rs +++ b/src/test/run-pass/guards.rs @@ -1,13 +1,13 @@ fn main() { let a = - alt 10 { x if x < 7 { 1 } x if x < 11 { 2 } 10 { 3 } _ { 4 } }; + alt 10 { x if x < 7 => { 1 } x if x < 11 => { 2 } 10 => { 3 } _ => { 4 } }; assert (a == 2); let b = alt {x: 10, y: 20} { - x if x.x < 5 && x.y < 5 { 1 } - {x: x, y: y} if x == 10 && y == 20 { 2 } - {x: x, y: y} { 3 } + x if x.x < 5 && x.y < 5 => { 1 } + {x: x, y: y} if x == 10 && y == 20 => { 2 } + {x: x, y: y} => { 3 } }; assert (b == 2); } diff --git a/src/test/run-pass/hashmap-memory.rs b/src/test/run-pass/hashmap-memory.rs index 80c942c69d1..e4fc8c1650f 100644 --- a/src/test/run-pass/hashmap-memory.rs +++ b/src/test/run-pass/hashmap-memory.rs @@ -46,8 +46,8 @@ mod map_reduce { val: ~str) { let mut c; alt im.find(key) { - some(_c) { c = _c } - none { + some(_c) => { c = _c } + none => { let p = port(); error!{"sending find_reducer"}; send(ctrl, find_reducer(str::bytes(key), chan(p))); @@ -79,12 +79,12 @@ mod map_reduce { while num_mappers > 0 { alt recv(ctrl) { - mapper_done { num_mappers -= 1; } - find_reducer(k, cc) { + mapper_done => { num_mappers -= 1; } + find_reducer(k, cc) => { let mut c; alt reducers.find(str::from_bytes(k)) { - some(_c) { c = _c; } - none { c = 0; } + some(_c) => { c = _c; } + none => { c = 0; } } send(cc, c); } diff --git a/src/test/run-pass/inferred-suffix-in-pattern-range.rs b/src/test/run-pass/inferred-suffix-in-pattern-range.rs index eadb3503bda..ae9c27d7880 100644 --- a/src/test/run-pass/inferred-suffix-in-pattern-range.rs +++ b/src/test/run-pass/inferred-suffix-in-pattern-range.rs @@ -1,22 +1,22 @@ fn main() { let x = 2; let x_message = alt x { - 0 to 1 { ~"not many" } - _ { ~"lots" } + 0 to 1 => { ~"not many" } + _ => { ~"lots" } }; assert x_message == ~"lots"; let y = 2i; let y_message = alt y { - 0 to 1 { ~"not many" } - _ { ~"lots" } + 0 to 1 => { ~"not many" } + _ => { ~"lots" } }; assert y_message == ~"lots"; let z = 1u64; let z_message = alt z { - 0 to 1 { ~"not many" } - _ { ~"lots" } + 0 to 1 => { ~"not many" } + _ => { ~"lots" } }; assert z_message == ~"not many"; } diff --git a/src/test/run-pass/issue-1701.rs b/src/test/run-pass/issue-1701.rs index f550c98d337..4c1f703733d 100644 --- a/src/test/run-pass/issue-1701.rs +++ b/src/test/run-pass/issue-1701.rs @@ -6,10 +6,10 @@ enum animal { cat(pattern), dog(breed), rabbit(name, ear_kind), tiger } fn noise(a: animal) -> option<~str> { alt a { - cat(*) { some(~"meow") } - dog(*) { some(~"woof") } - rabbit(*) { none } - tiger(*) { some(~"roar") } + cat(*) => { some(~"meow") } + dog(*) => { some(~"woof") } + rabbit(*) => { none } + tiger(*) => { some(~"roar") } } } diff --git a/src/test/run-pass/issue-2718.rs b/src/test/run-pass/issue-2718.rs index 5ffcab99a7b..8fb85a7d11e 100644 --- a/src/test/run-pass/issue-2718.rs +++ b/src/test/run-pass/issue-2718.rs @@ -59,19 +59,19 @@ mod pipes { (*p).payload <- some(payload); let old_state = swap_state_rel((*p).state, full); alt old_state { - empty { + empty => { // Yay, fastpath. // The receiver will eventually clean this up. unsafe { forget(p); } } - full { fail ~"duplicate send" } - blocked { + full => { fail ~"duplicate send" } + blocked => { // The receiver will eventually clean this up. unsafe { forget(p); } } - terminated { + terminated => { // The receiver will never receive this. Rely on drop_glue // to clean everything up. } @@ -85,13 +85,13 @@ mod pipes { let old_state = swap_state_acq((*p).state, blocked); alt old_state { - empty | blocked { task::yield(); } - full { + empty | blocked => { task::yield(); } + full => { let mut payload = none; payload <-> (*p).payload; return some(option::unwrap(payload)) } - terminated { + terminated => { assert old_state == terminated; return none; } @@ -102,15 +102,15 @@ mod pipes { fn sender_terminate<T: send>(p: *packet<T>) { let p = unsafe { uniquify(p) }; alt swap_state_rel((*p).state, terminated) { - empty | blocked { + empty | blocked => { // The receiver will eventually clean up. unsafe { forget(p) } } - full { + full => { // This is impossible fail ~"you dun goofed" } - terminated { + terminated => { // I have to clean up, use drop_glue } } @@ -119,15 +119,15 @@ mod pipes { fn receiver_terminate<T: send>(p: *packet<T>) { let p = unsafe { uniquify(p) }; alt swap_state_rel((*p).state, terminated) { - empty { + empty => { // the sender will clean up unsafe { forget(p) } } - blocked { + blocked => { // this shouldn't happen. fail ~"terminating a blocked packet" } - terminated | full { + terminated | full => { // I have to clean up, use drop_glue } } @@ -179,7 +179,7 @@ mod pingpong { fn liberate_ping(-p: ping) -> pipes::send_packet<pong> unsafe { let addr : *pipes::send_packet<pong> = alt p { - ping(x) { unsafe::reinterpret_cast(ptr::addr_of(x)) } + ping(x) => { unsafe::reinterpret_cast(ptr::addr_of(x)) } }; let liberated_value <- *addr; unsafe::forget(p); @@ -188,7 +188,7 @@ mod pingpong { fn liberate_pong(-p: pong) -> pipes::send_packet<ping> unsafe { let addr : *pipes::send_packet<ping> = alt p { - pong(x) { unsafe::reinterpret_cast(ptr::addr_of(x)) } + pong(x) => { unsafe::reinterpret_cast(ptr::addr_of(x)) } }; let liberated_value <- *addr; unsafe::forget(p); diff --git a/src/test/run-pass/issue-2804.rs b/src/test/run-pass/issue-2804.rs index 811f5a52a14..dbaa37abacd 100644 --- a/src/test/run-pass/issue-2804.rs +++ b/src/test/run-pass/issue-2804.rs @@ -13,16 +13,16 @@ fn lookup(table: std::map::hashmap<~str, std::json::json>, key: ~str, default: ~ { alt table.find(key) { - option::some(std::json::string(s)) + option::some(std::json::string(s)) => { *s } - option::some(value) + option::some(value) => { error!{"%s was expected to be a string but is a %?", key, value}; default } - option::none + option::none => { default } @@ -33,14 +33,14 @@ fn add_interface(store: int, managed_ip: ~str, data: std::json::json) -> (~str, { alt data { - std::json::dict(interface) + std::json::dict(interface) => { let name = lookup(interface, ~"ifDescr", ~""); let label = fmt!{"%s-%s", managed_ip, name}; (label, bool_value(false)) } - _ + _ => { error!{"Expected dict for %s interfaces but found %?", managed_ip, data}; (~"gnos:missing-interface", bool_value(true)) @@ -52,13 +52,13 @@ fn add_interfaces(store: int, managed_ip: ~str, device: std::map::hashmap<~str, { alt device[~"interfaces"] { - std::json::list(interfaces) + std::json::list(interfaces) => { do vec::map(*interfaces) |interface| { add_interface(store, managed_ip, interface) } } - _ + _ => { error!{"Expected list for %s interfaces but found %?", managed_ip, device[~"interfaces"]}; ~[] diff --git a/src/test/run-pass/issue-2904.rs b/src/test/run-pass/issue-2904.rs index 4072560a3cf..a7ae3a55000 100644 --- a/src/test/run-pass/issue-2904.rs +++ b/src/test/run-pass/issue-2904.rs @@ -18,29 +18,29 @@ enum square { impl of to_str::to_str for square { fn to_str() -> ~str { alt self { - bot { ~"R" } - wall { ~"#" } - rock { ~"*" } - lambda { ~"\\" } - closed_lift { ~"L" } - open_lift { ~"O" } - earth { ~"." } - empty { ~" " } + bot => { ~"R" } + wall => { ~"#" } + rock => { ~"*" } + lambda => { ~"\\" } + closed_lift => { ~"L" } + open_lift => { ~"O" } + earth => { ~"." } + empty => { ~" " } } } } fn square_from_char(c: char) -> square { alt c { - 'R' { bot } - '#' { wall } - '*' { rock } - '\\' { lambda } - 'L' { closed_lift } - 'O' { open_lift } - '.' { earth } - ' ' { empty } - _ { + 'R' => { bot } + '#' => { wall } + '*' => { rock } + '\\' => { lambda } + 'L' => { closed_lift } + 'O' => { open_lift } + '.' => { earth } + ' ' => { empty } + _ => { #error("invalid square: %?", c); fail } diff --git a/src/test/run-pass/issue-687.rs b/src/test/run-pass/issue-687.rs index 9ffa90069b8..a314bf4856b 100644 --- a/src/test/run-pass/issue-687.rs +++ b/src/test/run-pass/issue-687.rs @@ -49,8 +49,8 @@ fn main() { loop { let msg = recv(p); alt msg { - closed { debug!{"Got close message"}; break; } - received(data) { + closed => { debug!{"Got close message"}; break; } + received(data) => { debug!{"Got data. Length is:"}; log(debug, vec::len::<u8>(data)); } diff --git a/src/test/run-pass/keyword-changes-2012-07-31.rs b/src/test/run-pass/keyword-changes-2012-07-31.rs index 1473c433e53..c7d48d95108 100644 --- a/src/test/run-pass/keyword-changes-2012-07-31.rs +++ b/src/test/run-pass/keyword-changes-2012-07-31.rs @@ -10,6 +10,6 @@ mod foo { fn bar() -> int { match 0 { - _ { 0 } + _ => { 0 } } } \ No newline at end of file diff --git a/src/test/run-pass/leaky_comm.rs b/src/test/run-pass/leaky_comm.rs index 58a655917ba..3a3bfa4f515 100644 --- a/src/test/run-pass/leaky_comm.rs +++ b/src/test/run-pass/leaky_comm.rs @@ -7,8 +7,8 @@ fn main() { let p = test_comm::port(); alt none::<int> { - none {} - some(_) { + none => {} + some(_) =>{ if test_comm::recv(p) == 0 { error!{"floop"}; } diff --git a/src/test/run-pass/macro-interpolation.rs b/src/test/run-pass/macro-interpolation.rs index 0f692533eb9..cbaa9182dc5 100644 --- a/src/test/run-pass/macro-interpolation.rs +++ b/src/test/run-pass/macro-interpolation.rs @@ -4,10 +4,10 @@ macro_rules! overly_complicated { { fn $fnname($arg: $ty) -> option<$ty> $body alt $fnname($val) { - some($pat) { + some($pat) => { $res } - _ { fail; } + _ => { fail; } } } diff --git a/src/test/run-pass/module-polymorphism4-files/cat.rs b/src/test/run-pass/module-polymorphism4-files/cat.rs index 1f186036e13..832cca5c4f1 100644 --- a/src/test/run-pass/module-polymorphism4-files/cat.rs +++ b/src/test/run-pass/module-polymorphism4-files/cat.rs @@ -8,7 +8,7 @@ enum cat { fn animal() -> ~str { ~"cat" } fn talk(c: cat) -> ~str { alt c { - howlycat { ~"howl" } - meowlycat { ~"meow" } + howlycat => { ~"howl" } + meowlycat => { ~"meow" } } } diff --git a/src/test/run-pass/monad.rs b/src/test/run-pass/monad.rs index 3b0f6c1bbdf..1e611804f9f 100644 --- a/src/test/run-pass/monad.rs +++ b/src/test/run-pass/monad.rs @@ -17,8 +17,8 @@ trait option_monad<A> { impl monad<A> of option_monad<A> for option<A> { fn bind<B>(f: fn(A) -> option<B>) -> option<B> { alt self { - some(a) { f(a) } - none { none } + some(a) => { f(a) } + none => { none } } } } diff --git a/src/test/run-pass/negative.rs b/src/test/run-pass/negative.rs index 78f0451c9cf..38661bb84b2 100644 --- a/src/test/run-pass/negative.rs +++ b/src/test/run-pass/negative.rs @@ -1,6 +1,6 @@ fn main() { alt -5 { - -5 {} - _ { fail } + -5 => {} + _ => { fail } } } \ No newline at end of file diff --git a/src/test/run-pass/nested-alts.rs b/src/test/run-pass/nested-alts.rs index 935b82ada56..ff0f0228a63 100644 --- a/src/test/run-pass/nested-alts.rs +++ b/src/test/run-pass/nested-alts.rs @@ -3,12 +3,12 @@ fn baz() -> ! { fail; } fn foo() { alt some::<int>(5) { - some::<int>(x) { + some::<int>(x) => { let mut bar; - alt none::<int> { none::<int> { bar = 5; } _ { baz(); } } + alt none::<int> { none::<int> => { bar = 5; } _ => { baz(); } } log(debug, bar); } - none::<int> { debug!{"hello"}; } + none::<int> => { debug!{"hello"}; } } } diff --git a/src/test/run-pass/nested-exhaustive-alt.rs b/src/test/run-pass/nested-exhaustive-alt.rs index f3ebc1f8a4f..51d7b7d4538 100644 --- a/src/test/run-pass/nested-exhaustive-alt.rs +++ b/src/test/run-pass/nested-exhaustive-alt.rs @@ -1,8 +1,8 @@ fn main() { alt @{foo: true, bar: some(10), baz: 20} { - @{foo: true, bar: some(_), _} {} - @{foo: false, bar: none, _} {} - @{foo: true, bar: none, _} {} - @{foo: false, bar: some(_), _} {} + @{foo: true, bar: some(_), _} => {} + @{foo: false, bar: none, _} => {} + @{foo: true, bar: none, _} => {} + @{foo: false, bar: some(_), _} => {} } } diff --git a/src/test/run-pass/nested-pattern.rs b/src/test/run-pass/nested-pattern.rs index e47a8cad54c..ae901d1f9f1 100644 --- a/src/test/run-pass/nested-pattern.rs +++ b/src/test/run-pass/nested-pattern.rs @@ -10,8 +10,8 @@ enum t { foo(int, uint), bar(int, option<int>), } fn nested(o: t) { alt o { - bar(i, some::<int>(_)) { error!{"wrong pattern matched"}; fail; } - _ { error!{"succeeded"}; } + bar(i, some::<int>(_)) => { error!{"wrong pattern matched"}; fail; } + _ => { error!{"succeeded"}; } } } diff --git a/src/test/run-pass/nested-patterns.rs b/src/test/run-pass/nested-patterns.rs index d58cb896a60..0b93154b566 100644 --- a/src/test/run-pass/nested-patterns.rs +++ b/src/test/run-pass/nested-patterns.rs @@ -1,7 +1,7 @@ fn main() { alt {a: 10, b: @20} { - x@{a, b: @20} { assert x.a == 10; assert a == 10; } - {b, _} { fail; } + x@{a, b: @20} => { assert x.a == 10; assert a == 10; } + {b, _} => { fail; } } let x@{b, _} = {a: 10, b: {mut c: 20}}; x.b.c = 30; diff --git a/src/test/run-pass/nil-pattern.rs b/src/test/run-pass/nil-pattern.rs index 927ff5be3e5..c1ef9c5970e 100644 --- a/src/test/run-pass/nil-pattern.rs +++ b/src/test/run-pass/nil-pattern.rs @@ -1 +1 @@ -fn main() { let x = (); alt x { () { } } } +fn main() { let x = (); alt x { () => { } } } diff --git a/src/test/run-pass/non-boolean-pure-fns.rs b/src/test/run-pass/non-boolean-pure-fns.rs index 02926c0eff5..a338fd39101 100644 --- a/src/test/run-pass/non-boolean-pure-fns.rs +++ b/src/test/run-pass/non-boolean-pure-fns.rs @@ -3,7 +3,7 @@ use std; import std::list::*; pure fn pure_length_go<T: copy>(ls: @list<T>, acc: uint) -> uint { - alt *ls { nil { acc } cons(_, tl) { pure_length_go(tl, acc + 1u) } } + alt *ls { nil => { acc } cons(_, tl) => { pure_length_go(tl, acc + 1u) } } } pure fn pure_length<T: copy>(ls: @list<T>) -> uint { pure_length_go(ls, 0u) } diff --git a/src/test/run-pass/nullary-or-pattern.rs b/src/test/run-pass/nullary-or-pattern.rs index 87109cfb1d6..a856eb3e61b 100644 --- a/src/test/run-pass/nullary-or-pattern.rs +++ b/src/test/run-pass/nullary-or-pattern.rs @@ -1,7 +1,7 @@ enum blah { a, b, } fn or_alt(q: blah) -> int { - alt q { a | b { 42 } } + alt q { a | b => { 42 } } } fn main() { diff --git a/src/test/run-pass/or-pattern.rs b/src/test/run-pass/or-pattern.rs index aca2232ffc5..979bf5522e9 100644 --- a/src/test/run-pass/or-pattern.rs +++ b/src/test/run-pass/or-pattern.rs @@ -1,7 +1,7 @@ enum blah { a(int, int, uint), b(int, int), c, } fn or_alt(q: blah) -> int { - alt q { a(x, y, _) | b(x, y) { return x + y; } c { return 0; } } + alt q { a(x, y, _) | b(x, y) => { return x + y; } c => { return 0; } } } fn main() { diff --git a/src/test/run-pass/paren-free.rs b/src/test/run-pass/paren-free.rs index e06997c671d..5e115abb0dc 100644 --- a/src/test/run-pass/paren-free.rs +++ b/src/test/run-pass/paren-free.rs @@ -1,5 +1,5 @@ fn main() { let x = true; if x { let mut i = 10; while i > 0 { i -= 1; } } - alt x { true { debug!{"right"}; } false { debug!{"wrong"}; } } + alt x { true => { debug!{"right"}; } false => { debug!{"wrong"}; } } } diff --git a/src/test/run-pass/pattern-bound-var-in-for-each.rs b/src/test/run-pass/pattern-bound-var-in-for-each.rs index a2823561e62..ae753296a2f 100644 --- a/src/test/run-pass/pattern-bound-var-in-for-each.rs +++ b/src/test/run-pass/pattern-bound-var-in-for-each.rs @@ -5,13 +5,13 @@ fn foo(src: uint) { alt some(src) { - some(src_id) { + some(src_id) => { for uint::range(0u, 10u) |i| { let yyy = src_id; assert (yyy == 0u); } } - _ { } + _ => { } } } diff --git a/src/test/run-pass/pipe-bank-proto.rs b/src/test/run-pass/pipe-bank-proto.rs index af50c9c974e..81e33bbbebb 100644 --- a/src/test/run-pass/pipe-bank-proto.rs +++ b/src/test/run-pass/pipe-bank-proto.rs @@ -110,23 +110,23 @@ fn bank_client(+bank: bank::client::login) { let bank = client::login(bank, ~"theincredibleholk", ~"1234"); let bank = alt try_recv(bank) { - some(ok(connected)) { + some(ok(connected)) => { move_it!{connected} } - some(invalid(_)) { fail ~"login unsuccessful" } - none { fail ~"bank closed the connection" } + some(invalid(_)) => { fail ~"login unsuccessful" } + none => { fail ~"bank closed the connection" } }; let bank = client::deposit(bank, 100.00); let bank = client::withdrawal(bank, 50.00); alt try_recv(bank) { - some(money(m, _)) { + some(money(m, _)) => { io::println(~"Yay! I got money!"); } - some(insufficient_funds(_)) { + some(insufficient_funds(_)) => { fail ~"someone stole my money" } - none { + none => { fail ~"bank closed the connection" } } diff --git a/src/test/run-pass/pipe-detect-term.rs b/src/test/run-pass/pipe-detect-term.rs index 93b919154db..b68be9cb23c 100644 --- a/src/test/run-pass/pipe-detect-term.rs +++ b/src/test/run-pass/pipe-detect-term.rs @@ -20,8 +20,8 @@ fn main() { pipes::spawn_service(oneshot::init, |p| { alt try_recv(p) { - some(*) { fail } - none { } + some(*) => { fail } + none => { } } }); diff --git a/src/test/run-pass/pipe-select.rs b/src/test/run-pass/pipe-select.rs index 04cde9c742e..856bb3fe5cc 100644 --- a/src/test/run-pass/pipe-select.rs +++ b/src/test/run-pass/pipe-select.rs @@ -79,8 +79,8 @@ fn test_select2() { stream::client::send(ac, 42); alt pipes::select2(ap, bp) { - either::left(*) { } - either::right(*) { fail } + either::left(*) => { } + either::right(*) => { fail } } stream::client::send(bc, ~"abc"); @@ -93,8 +93,8 @@ fn test_select2() { stream::client::send(bc, ~"abc"); alt pipes::select2(ap, bp) { - either::left(*) { fail } - either::right(*) { } + either::left(*) => { fail } + either::right(*) => { } } stream::client::send(ac, 42); diff --git a/src/test/run-pass/record-pat.rs b/src/test/run-pass/record-pat.rs index 1adc8c5838b..9ccdf58c4f1 100644 --- a/src/test/run-pass/record-pat.rs +++ b/src/test/run-pass/record-pat.rs @@ -4,8 +4,8 @@ enum t3 { c(t2, uint), } fn m(in: t3) -> int { alt in { - c({x: a(m), _}, _) { return m; } - c({x: b(m), y: y}, z) { return ((m + z) as int) + y; } + c({x: a(m), _}, _) => { return m; } + c({x: b(m), y: y}, z) => { return ((m + z) as int) + y; } } } diff --git a/src/test/run-pass/regions-infer-borrow-scope-addr-of.rs b/src/test/run-pass/regions-infer-borrow-scope-addr-of.rs index 124c271032f..dccdc6ce384 100644 --- a/src/test/run-pass/regions-infer-borrow-scope-addr-of.rs +++ b/src/test/run-pass/regions-infer-borrow-scope-addr-of.rs @@ -8,7 +8,7 @@ fn main() { // naively borrowed &x for the lifetime // of the variable x, as we once did alt i { - i { + i => { let y = &x; assert i < *y; } diff --git a/src/test/run-pass/regions-self-in-enums.rs b/src/test/run-pass/regions-self-in-enums.rs index ef7a8ae1ed7..bd03a2ff6e7 100644 --- a/src/test/run-pass/regions-self-in-enums.rs +++ b/src/test/run-pass/regions-self-in-enums.rs @@ -7,7 +7,7 @@ fn main() { let y = int_wrapper_ctor(&x); let mut z : ∫ alt y { - int_wrapper_ctor(zz) { z = zz; } + int_wrapper_ctor(zz) => { z = zz; } } log(debug, *z); } diff --git a/src/test/run-pass/shadow.rs b/src/test/run-pass/shadow.rs index 0194f4558cb..96b018e6a3b 100644 --- a/src/test/run-pass/shadow.rs +++ b/src/test/run-pass/shadow.rs @@ -5,14 +5,14 @@ fn foo(c: ~[int]) { alt none::<int> { - some::<int>(_) { + some::<int>(_) => { for c.each |i| { log(debug, a); let a = 17; b += ~[a]; } } - _ { } + _ => { } } } diff --git a/src/test/run-pass/simple-alt-generic-tag.rs b/src/test/run-pass/simple-alt-generic-tag.rs index 43ba568fb08..ef5bd284a0d 100644 --- a/src/test/run-pass/simple-alt-generic-tag.rs +++ b/src/test/run-pass/simple-alt-generic-tag.rs @@ -4,5 +4,5 @@ enum opt<T> { none, } fn main() { let x = none::<int>; - alt x { none::<int> { debug!{"hello world"}; } } + alt x { none::<int> => { debug!{"hello world"}; } } } diff --git a/src/test/run-pass/simple-generic-alt.rs b/src/test/run-pass/simple-generic-alt.rs index 4e30d44304a..2bf60273c54 100644 --- a/src/test/run-pass/simple-generic-alt.rs +++ b/src/test/run-pass/simple-generic-alt.rs @@ -2,4 +2,4 @@ enum clam<T> { a(T), } -fn main() { let c = a(2); alt c { a::<int>(_) { } } } +fn main() { let c = a(2); alt c { a::<int>(_) => { } } } diff --git a/src/test/run-pass/size-and-align.rs b/src/test/run-pass/size-and-align.rs index c4689f0951a..5c325e25f48 100644 --- a/src/test/run-pass/size-and-align.rs +++ b/src/test/run-pass/size-and-align.rs @@ -6,8 +6,8 @@ enum clam<T> { a(T, int), b, } fn uhoh<T>(v: ~[clam<T>]) { alt v[1] { - a::<T>(t, u) { debug!{"incorrect"}; log(debug, u); fail; } - b::<T> { debug!{"correct"}; } + a::<T>(t, u) => { debug!{"incorrect"}; log(debug, u); fail; } + b::<T> => { debug!{"correct"}; } } } diff --git a/src/test/run-pass/tag-variant-disr-val.rs b/src/test/run-pass/tag-variant-disr-val.rs index 45c2c2ef94d..2b43cb7061f 100644 --- a/src/test/run-pass/tag-variant-disr-val.rs +++ b/src/test/run-pass/tag-variant-disr-val.rs @@ -30,14 +30,14 @@ fn test_color(color: color, val: int, name: ~str) unsafe { fn get_color_alt(color: color) -> ~str { alt color { - red {~"red"} - green {~"green"} - blue {~"blue"} - black {~"black"} - white {~"white"} - imaginary {~"imaginary"} - purple {~"purple"} - orange {~"orange"} + red => {~"red"} + green => {~"green"} + blue => {~"blue"} + black => {~"black"} + white => {~"white"} + imaginary => {~"imaginary"} + purple => {~"purple"} + orange => {~"orange"} } } diff --git a/src/test/run-pass/trait-cast.rs b/src/test/run-pass/trait-cast.rs index 919c53d32b2..a56061a8ff5 100644 --- a/src/test/run-pass/trait-cast.rs +++ b/src/test/run-pass/trait-cast.rs @@ -14,8 +14,8 @@ trait to_str { impl <T: to_str> of to_str for option<T> { fn to_str() -> ~str { alt self { - none { ~"none" } - some(t) { ~"some(" + t.to_str() + ~")" } + none => { ~"none" } + some(t) => { ~"some(" + t.to_str() + ~")" } } } } diff --git a/src/test/run-pass/typestate-cfg-nesting.rs b/src/test/run-pass/typestate-cfg-nesting.rs index 8c1c3ef7a70..a1825737a4e 100644 --- a/src/test/run-pass/typestate-cfg-nesting.rs +++ b/src/test/run-pass/typestate-cfg-nesting.rs @@ -2,7 +2,7 @@ fn f() { let x = 10; let mut y = 11; - if true { alt x { _ { y = x; } } } else { } + if true { alt x { _ => { y = x; } } } else { } } fn main() { diff --git a/src/test/run-pass/unique-alt-discrim.rs b/src/test/run-pass/unique-alt-discrim.rs index ad9b6ed2ce8..2f155ef00e7 100644 --- a/src/test/run-pass/unique-alt-discrim.rs +++ b/src/test/run-pass/unique-alt-discrim.rs @@ -2,7 +2,7 @@ fn altsimple() { alt ~true { - _ { } + _ => { } } } fn main() { } \ No newline at end of file diff --git a/src/test/run-pass/unique-in-tag.rs b/src/test/run-pass/unique-in-tag.rs index d65143285bd..aaba73c72d0 100644 --- a/src/test/run-pass/unique-in-tag.rs +++ b/src/test/run-pass/unique-in-tag.rs @@ -3,11 +3,11 @@ fn test1() { let x = u(~10); assert alt x { - u(a) { + u(a) => { log(error, a); *a } - _ { 66 } + _ => { 66 } } == 10; } diff --git a/src/test/run-pass/unique-pat-2.rs b/src/test/run-pass/unique-pat-2.rs index 169ce721de7..241ff4b1d3a 100644 --- a/src/test/run-pass/unique-pat-2.rs +++ b/src/test/run-pass/unique-pat-2.rs @@ -4,7 +4,7 @@ enum bar { u(~foo), w(int), } fn main() { assert (alt u(~{a: 10, b: 40u}) { - u(~{a: a, b: b}) { a + (b as int) } - _ { 66 } + u(~{a: a, b: b}) => { a + (b as int) } + _ => { 66 } } == 50); } diff --git a/src/test/run-pass/unique-pat-3.rs b/src/test/run-pass/unique-pat-3.rs index 034404f7a3f..edc5be4d159 100644 --- a/src/test/run-pass/unique-pat-3.rs +++ b/src/test/run-pass/unique-pat-3.rs @@ -3,10 +3,10 @@ enum bar { u(~int), w(int), } fn main() { assert alt u(~10) { - u(a) { + u(a) => { log(error, a); *a } - _ { 66 } + _ => { 66 } } == 10; } diff --git a/src/test/run-pass/unique-pat.rs b/src/test/run-pass/unique-pat.rs index 391c4c8405e..81c1e6ccbd6 100644 --- a/src/test/run-pass/unique-pat.rs +++ b/src/test/run-pass/unique-pat.rs @@ -1,7 +1,7 @@ fn simple() { alt ~true { - ~true { } - _ { fail; } + ~true => { } + _ => { fail; } } } diff --git a/src/test/run-pass/unreachable-code.rs b/src/test/run-pass/unreachable-code.rs index 2747ed2755e..e48056d68c0 100644 --- a/src/test/run-pass/unreachable-code.rs +++ b/src/test/run-pass/unreachable-code.rs @@ -23,8 +23,8 @@ fn ret_ret() -> int { return (return 2) + 3; } fn ret_guard() { alt 2 { - x if (return) { x; } - _ {} + x if (return) => { x; } + _ => {} } } diff --git a/src/test/run-pass/use-uninit-alt.rs b/src/test/run-pass/use-uninit-alt.rs index 76e1c95ca58..21b1c1d66da 100644 --- a/src/test/run-pass/use-uninit-alt.rs +++ b/src/test/run-pass/use-uninit-alt.rs @@ -2,7 +2,7 @@ fn foo<T>(o: myoption<T>) -> int { let mut x: int = 5; - alt o { none::<T> { } some::<T>(t) { x += 1; } } + alt o { none::<T> => { } some::<T>(t) => { x += 1; } } return x; } diff --git a/src/test/run-pass/use-uninit-alt2.rs b/src/test/run-pass/use-uninit-alt2.rs index 0479d3c9555..b06d2035644 100644 --- a/src/test/run-pass/use-uninit-alt2.rs +++ b/src/test/run-pass/use-uninit-alt2.rs @@ -2,7 +2,7 @@ fn foo<T>(o: myoption<T>) -> int { let mut x: int; - alt o { none::<T> { fail; } some::<T>(t) { x = 5; } } + alt o { none::<T> => { fail; } some::<T>(t) => { x = 5; } } return x; } diff --git a/src/test/run-pass/weird-exprs.rs b/src/test/run-pass/weird-exprs.rs index 5dd7d91640e..5e7fe0b0524 100644 --- a/src/test/run-pass/weird-exprs.rs +++ b/src/test/run-pass/weird-exprs.rs @@ -20,14 +20,14 @@ fn zombiejesus() { while (return) { if (return) { alt (return) { - 1 { + 1 => { if (return) { return } else { return } } - _ { return } + _ => { return } }; } else if (return) { return; @@ -59,7 +59,7 @@ fn canttouchthis() -> uint { fn angrydome() { loop { if break { } } let mut i = 0; - loop { i += 1; if i == 1 { alt check again { 1 { } } } break; } + loop { i += 1; if i == 1 { alt check again { 1 => { } } } break; } } fn evil_lincoln() { let evil <- debug!{"lincoln"}; } |
