diff options
| author | Haitao Li <lihaitao@gmail.com> | 2012-01-19 20:29:50 +0800 |
|---|---|---|
| committer | Haitao Li <lihaitao@gmail.com> | 2012-01-19 20:31:43 +0800 |
| commit | d699db699a07d5bb80d5d08508540b0aba6e1026 (patch) | |
| tree | ca0f6e9a2dd14c469d8e875f8c4b1d5782a35cb8 | |
| parent | 7ffb2cb7e8d3f1845455a51f83fde3fd4759790c (diff) | |
| download | rust-d699db699a07d5bb80d5d08508540b0aba6e1026.tar.gz rust-d699db699a07d5bb80d5d08508540b0aba6e1026.zip | |
rustc: Refactor lint check and avoid a segv fault
The segv fault issue is #1566
| -rw-r--r-- | src/comp/driver/driver.rs | 13 | ||||
| -rw-r--r-- | src/comp/middle/lint.rs | 26 |
2 files changed, 16 insertions, 23 deletions
diff --git a/src/comp/driver/driver.rs b/src/comp/driver/driver.rs index 6c2a646f35d..ea961f917e5 100644 --- a/src/comp/driver/driver.rs +++ b/src/comp/driver/driver.rs @@ -203,9 +203,14 @@ fn compile_upto(sess: session, cfg: ast::crate_cfg, bind last_use::find_last_uses(crate, def_map, ref_map, ty_cx)); time(time_passes, "kind checking", bind kind::check_crate(ty_cx, method_map, last_uses, crate)); - if vec::len(sess.opts.lint_opts) > 0u { - let timer = bind time(time_passes, _, _); - lint::check_crate(ty_cx, crate, sess.opts.lint_opts, timer) + + vec::iter(sess.opts.lint_opts) {|lopt| + alt lopt { + ctypes { + time(time_passes, "ctypes usage checking", + bind lint::check_ctypes(ty_cx, crate)) + } + } } if upto == cu_no_trans { ret {crate: crate, tcx: some(ty_cx), src: src}; } @@ -384,7 +389,7 @@ fn build_session_options(match: getopts::match, let parse_only = opt_present(match, "parse-only"); let no_trans = opt_present(match, "no-trans"); - let lint_opts : [lint::option] = []; + let lint_opts = []; if !opt_present(match, "no-lint-ctypes") { lint_opts += [lint::ctypes]; } diff --git a/src/comp/middle/lint.rs b/src/comp/middle/lint.rs index 1b19fd60066..adbd959b0de 100644 --- a/src/comp/middle/lint.rs +++ b/src/comp/middle/lint.rs @@ -8,31 +8,19 @@ enum option { ctypes; } -fn check_crate(tcx: ty::ctxt, crate: @ast::crate, - checks: [option], timer: block(str, fn@())) { - let ccx = @{tcx: tcx}; - vec::iter(checks) {|c| - alt c { - ctypes { - timer("ctypes usage checking", bind check_ctypes(ccx, crate)) - } - } - } -} - -fn check_ctypes(ccx: @crate_ctxt, crate: @ast::crate) { - fn check_native_fn(ccx: @crate_ctxt, decl: ast::fn_decl) { +fn check_ctypes(tcx: ty::ctxt, crate: @ast::crate) { + fn check_native_fn(tcx: ty::ctxt, decl: ast::fn_decl) { let tys = vec::map(decl.inputs) {|a| a.ty }; for ty in (tys + [decl.output]) { alt ty.node { ast::ty_int(ast::ty_i) { - ccx.tcx.sess.span_warn( + tcx.sess.span_warn( ty.span, "found rust type `int` in native module, while \ ctypes::c_int or ctypes::long should be used"); } ast::ty_uint(ast::ty_u) { - ccx.tcx.sess.span_warn( + tcx.sess.span_warn( ty.span, "found rust type `uint` in native module, while \ ctypes::c_uint or ctypes::ulong should be used"); @@ -42,13 +30,13 @@ fn check_ctypes(ccx: @crate_ctxt, crate: @ast::crate) { } } - fn check_item(ccx: @crate_ctxt, it: @ast::item) { + fn check_item(tcx: ty::ctxt, it: @ast::item) { alt it.node { ast::item_native_mod(nmod) { for ni in nmod.items { alt ni.node { ast::native_item_fn(decl, tps) { - check_native_fn(ccx, decl); + check_native_fn(tcx, decl); } _ { } } @@ -59,7 +47,7 @@ fn check_ctypes(ccx: @crate_ctxt, crate: @ast::crate) { } let visit = visit::mk_simple_visitor(@{ - visit_item: bind check_item(ccx, _) + visit_item: bind check_item(tcx, _) with *visit::default_simple_visitor() }); visit::visit_crate(*crate, (), visit); |
