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/rustc | |
| parent | c9d27693796fe4ced8568e11aa465750f743097b (diff) | |
| download | rust-025d86624de982cdab7e6b13600fec1499c02b56.tar.gz rust-025d86624de982cdab7e6b13600fec1499c02b56.zip | |
Switch alts to use arrows
Diffstat (limited to 'src/rustc')
73 files changed, 4227 insertions, 4258 deletions
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)} } }; |
