Skip to content

Commit

Permalink
rustc: Refactor lint check and avoid a segv fault
Browse files Browse the repository at this point in the history
The segv fault issue is #1566
  • Loading branch information
lht committed Jan 19, 2012
1 parent 7ffb2cb commit d699db6
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 23 deletions.
13 changes: 9 additions & 4 deletions src/comp/driver/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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}; }
Expand Down Expand Up @@ -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];
}
Expand Down
26 changes: 7 additions & 19 deletions src/comp/middle/lint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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);
}
_ { }
}
Expand All @@ -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);
Expand Down

0 comments on commit d699db6

Please sign in to comment.