Skip to content

Commit d699db6

Browse files
committed
rustc: Refactor lint check and avoid a segv fault
The segv fault issue is #1566
1 parent 7ffb2cb commit d699db6

File tree

2 files changed

+16
-23
lines changed

2 files changed

+16
-23
lines changed

src/comp/driver/driver.rs

+9-4
Original file line numberDiff line numberDiff line change
@@ -203,9 +203,14 @@ fn compile_upto(sess: session, cfg: ast::crate_cfg,
203203
bind last_use::find_last_uses(crate, def_map, ref_map, ty_cx));
204204
time(time_passes, "kind checking",
205205
bind kind::check_crate(ty_cx, method_map, last_uses, crate));
206-
if vec::len(sess.opts.lint_opts) > 0u {
207-
let timer = bind time(time_passes, _, _);
208-
lint::check_crate(ty_cx, crate, sess.opts.lint_opts, timer)
206+
207+
vec::iter(sess.opts.lint_opts) {|lopt|
208+
alt lopt {
209+
ctypes {
210+
time(time_passes, "ctypes usage checking",
211+
bind lint::check_ctypes(ty_cx, crate))
212+
}
213+
}
209214
}
210215

211216
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,
384389

385390
let parse_only = opt_present(match, "parse-only");
386391
let no_trans = opt_present(match, "no-trans");
387-
let lint_opts : [lint::option] = [];
392+
let lint_opts = [];
388393
if !opt_present(match, "no-lint-ctypes") {
389394
lint_opts += [lint::ctypes];
390395
}

src/comp/middle/lint.rs

+7-19
Original file line numberDiff line numberDiff line change
@@ -8,31 +8,19 @@ enum option {
88
ctypes;
99
}
1010

11-
fn check_crate(tcx: ty::ctxt, crate: @ast::crate,
12-
checks: [option], timer: block(str, fn@())) {
13-
let ccx = @{tcx: tcx};
14-
vec::iter(checks) {|c|
15-
alt c {
16-
ctypes {
17-
timer("ctypes usage checking", bind check_ctypes(ccx, crate))
18-
}
19-
}
20-
}
21-
}
22-
23-
fn check_ctypes(ccx: @crate_ctxt, crate: @ast::crate) {
24-
fn check_native_fn(ccx: @crate_ctxt, decl: ast::fn_decl) {
11+
fn check_ctypes(tcx: ty::ctxt, crate: @ast::crate) {
12+
fn check_native_fn(tcx: ty::ctxt, decl: ast::fn_decl) {
2513
let tys = vec::map(decl.inputs) {|a| a.ty };
2614
for ty in (tys + [decl.output]) {
2715
alt ty.node {
2816
ast::ty_int(ast::ty_i) {
29-
ccx.tcx.sess.span_warn(
17+
tcx.sess.span_warn(
3018
ty.span,
3119
"found rust type `int` in native module, while \
3220
ctypes::c_int or ctypes::long should be used");
3321
}
3422
ast::ty_uint(ast::ty_u) {
35-
ccx.tcx.sess.span_warn(
23+
tcx.sess.span_warn(
3624
ty.span,
3725
"found rust type `uint` in native module, while \
3826
ctypes::c_uint or ctypes::ulong should be used");
@@ -42,13 +30,13 @@ fn check_ctypes(ccx: @crate_ctxt, crate: @ast::crate) {
4230
}
4331
}
4432

45-
fn check_item(ccx: @crate_ctxt, it: @ast::item) {
33+
fn check_item(tcx: ty::ctxt, it: @ast::item) {
4634
alt it.node {
4735
ast::item_native_mod(nmod) {
4836
for ni in nmod.items {
4937
alt ni.node {
5038
ast::native_item_fn(decl, tps) {
51-
check_native_fn(ccx, decl);
39+
check_native_fn(tcx, decl);
5240
}
5341
_ { }
5442
}
@@ -59,7 +47,7 @@ fn check_ctypes(ccx: @crate_ctxt, crate: @ast::crate) {
5947
}
6048

6149
let visit = visit::mk_simple_visitor(@{
62-
visit_item: bind check_item(ccx, _)
50+
visit_item: bind check_item(tcx, _)
6351
with *visit::default_simple_visitor()
6452
});
6553
visit::visit_crate(*crate, (), visit);

0 commit comments

Comments
 (0)