提交 7ffb2cb7 编写于 作者: H Haitao Li

rustc: Name the lint-style check module `lint`

Issue #1543
上级 327a15d5
......@@ -124,8 +124,10 @@ Build a test harness.
\fB--warn-unused-imports\fR:
Warn about unnecessary imports.
.TP
\fB--no-check-usage\fR:
Disables various one-off usage analyses.
\fB--no-lint-ctypes\fR:
Disables checking of possibly incorrect usage of Rust int or uint types in
native function declarations, where types defined in libcore::ctypes should be
used instead. Ctypes check emits warnings by default.
.SH "BUGS"
See \fBhttps://github.com/mozilla/rust/issues\fR for a list of known bugs.
.SH "AUTHOR"
......
......@@ -6,7 +6,7 @@
import syntax::{ast, codemap};
import front::attr;
import middle::{trans, resolve, freevars, kind, ty, typeck, fn_usage,
last_use, check_usage};
last_use, lint};
import syntax::print::{pp, pprust};
import util::{ppaux, filesearch};
import back::link;
......@@ -203,9 +203,9 @@ 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 sess.opts.check_usage {
time(time_passes, "usage analyses",
bind check_usage::check_crate(ty_cx, 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)
}
if upto == cu_no_trans { ret {crate: crate, tcx: some(ty_cx), src: src}; }
......@@ -384,6 +384,10 @@ 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] = [];
if !opt_present(match, "no-lint-ctypes") {
lint_opts += [lint::ctypes];
}
let output_type =
if parse_only || no_trans {
......@@ -399,7 +403,6 @@ fn build_session_options(match: getopts::match,
} else { link::output_type_exe };
let libcore = !opt_present(match, "no-core");
let verify = !opt_present(match, "no-verify");
let check_usage = !opt_present(match, "no-usage-check");
let save_temps = opt_present(match, "save-temps");
let extra_debuginfo = opt_present(match, "xg");
let debuginfo = opt_present(match, "g") || extra_debuginfo;
......@@ -451,7 +454,7 @@ fn build_session_options(match: getopts::match,
debuginfo: debuginfo,
extra_debuginfo: extra_debuginfo,
verify: verify,
check_usage: check_usage,
lint_opts: lint_opts,
save_temps: save_temps,
stats: stats,
time_passes: time_passes,
......@@ -520,7 +523,7 @@ fn opts() -> [getopts::opt] {
optopt("sysroot"), optopt("target"), optflag("stats"),
optflag("time-passes"), optflag("time-llvm-passes"),
optflag("no-verify"),
optflag("no-usage-check"),
optflag("no-lint-ctypes"),
optmulti("cfg"), optflag("test"),
optflag("no-core"),
optflag("lib"), optflag("bin"), optflag("static"), optflag("gc"),
......
......@@ -38,7 +38,6 @@ fn usage(argv0: str) {
--ls list the symbols defined by a crate file
-L <path> add a directory to the library search path
--no-verify suppress LLVM verification step (slight speedup)
--no-check-usage suppress various one-off usage analyses
--parse-only parse only; do not compile, assemble, or link
--no-trans run all passes except translation; no output
-g produce debug info
......@@ -59,6 +58,7 @@ fn usage(argv0: str) {
--gc garbage collect shared data (experimental/temporary)
--warn-unused-imports
warn about unnecessary imports
--no-lint-ctypes suppress lint-style ctypes usage check
");
}
......
......@@ -8,6 +8,7 @@
import syntax::parse::parser::parse_sess;
import util::filesearch;
import back::target_strs;
import middle::lint;
tag os { os_win32; os_macos; os_linux; os_freebsd; }
......@@ -33,7 +34,7 @@
debuginfo: bool,
extra_debuginfo: bool,
verify: bool,
check_usage: bool,
lint_opts: [lint::option],
save_temps: bool,
stats: bool,
time_passes: bool,
......
import driver::session::session;
import middle::ty::ctxt;
import syntax::{ast, visit};
type crate_ctxt = {tcx: ty::ctxt};
fn check_native_fn(ccx: @crate_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(
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(
ty.span, "found rust type `uint` in native module, while " +
"ctypes::c_uint or ctypes::ulong should be used");
}
_ { }
}
}
}
fn check_item(ccx: @crate_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);
}
_ { }
}
}
}
_ {/* nothing to do */ }
}
}
fn check_crate(tcx: ty::ctxt, crate: @ast::crate) {
let ccx = @{tcx: tcx};
let visit = visit::mk_simple_visitor(@{
visit_item: bind check_item(ccx, _)
with *visit::default_simple_visitor()
});
visit::visit_crate(*crate, (), visit);
tcx.sess.abort_if_errors();
}
//
// Local Variables:
// mode: rust
// fill-column: 78;
// indent-tabs-mode: nil
// c-basic-offset: 4
// buffer-file-coding-system: utf-8-unix
// End:
//
import driver::session::session;
import middle::ty::ctxt;
import syntax::{ast, visit};
type crate_ctxt = {tcx: ty::ctxt};
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) {
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(
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(
ty.span,
"found rust type `uint` in native module, while \
ctypes::c_uint or ctypes::ulong should be used");
}
_ { }
}
}
}
fn check_item(ccx: @crate_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);
}
_ { }
}
}
}
_ {/* nothing to do */ }
}
}
let visit = visit::mk_simple_visitor(@{
visit_item: bind check_item(ccx, _)
with *visit::default_simple_visitor()
});
visit::visit_crate(*crate, (), visit);
}
//
// Local Variables:
// mode: rust
// fill-column: 78;
// indent-tabs-mode: nil
// c-basic-offset: 4
// buffer-file-coding-system: utf-8-unix
// End:
//
......@@ -29,7 +29,7 @@ mod middle {
mod fn_usage;
mod check_alt;
mod check_const;
mod check_usage;
mod lint;
mod mut;
mod alias;
mod last_use;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册