.TP
\fB--warn-unused-imports\fR:
Warn about unnecessary imports.
+.TP
+\fB--no-check-usage\fR:
+Disables various one-off usage analyses.
.SH "BUGS"
See \fBhttps://github.com/mozilla/rust/issues\fR for a list of known bugs.
.SH "AUTHOR"
import syntax::{ast, codemap};
import front::attr;
import middle::{trans, resolve, freevars, kind, ty, typeck, fn_usage,
- last_use};
+ last_use, check_usage};
import syntax::print::{pp, pprust};
import util::{ppaux, filesearch};
import back::link;
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 upto == cu_no_trans { ret {crate: crate, tcx: some(ty_cx), src: src}; }
let outputs = option::get(outputs);
} 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;
debuginfo: debuginfo,
extra_debuginfo: extra_debuginfo,
verify: verify,
+ check_usage: check_usage,
save_temps: save_temps,
stats: stats,
time_passes: time_passes,
optopt("sysroot"), optopt("target"), optflag("stats"),
optflag("time-passes"), optflag("time-llvm-passes"),
optflag("no-verify"),
+ optflag("no-usage-check"),
optmulti("cfg"), optflag("test"),
optflag("no-core"),
optflag("lib"), optflag("bin"), optflag("static"), optflag("gc"),
--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
debuginfo: bool,
extra_debuginfo: bool,
verify: bool,
+ check_usage: bool,
save_temps: bool,
stats: bool,
time_passes: bool,
--- /dev/null
+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:
+//
check_fn(ccx, ast::proto_bare, method.decl, method.body, method.id, none);
}
-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_const(_, e) { check_const(ccx, it.span, e, it.id); }
ast::item_res(decl, tps, body, dtor_id, _) {
check_fn(ccx, ast::proto_bare, decl, body, dtor_id, none);
}
- ast::item_native_mod(nmod) {
- for ni in nmod.items {
- alt ni.node {
- ast::native_item_fn(decl, tps) {
- check_native_fn(ccx, decl);
- }
- _ { }
- }
- }
- }
ast::item_impl(tps, _, ty, ms) {
ccx.self_infos += [self_impl(ast_ty_to_ty(ccx.tcx, m_check, ty))];
for m in ms { check_method(ccx, m); }
mod fn_usage;
mod check_alt;
mod check_const;
+ mod check_usage;
mod mut;
mod alias;
mod last_use;
}
fn main() {
- "let compile fail to verify warning message" = 999;
+ // let it fail to verify warning message
+ fail
}