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 /src/comp/middle | |
| parent | 7ffb2cb7e8d3f1845455a51f83fde3fd4759790c (diff) | |
rustc: Refactor lint check and avoid a segv fault
The segv fault issue is #1566
Diffstat (limited to 'src/comp/middle')
| -rw-r--r-- | src/comp/middle/lint.rs | 26 |
1 files changed, 7 insertions, 19 deletions
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); |
