]> git.lizzy.rs Git - rust.git/commitdiff
rustc: Name the lint-style check module `lint`
authorHaitao Li <lihaitao@gmail.com>
Thu, 19 Jan 2012 08:50:51 +0000 (16:50 +0800)
committerHaitao Li <lihaitao@gmail.com>
Thu, 19 Jan 2012 09:54:38 +0000 (17:54 +0800)
Issue #1543

man/rustc.1
src/comp/driver/driver.rs
src/comp/driver/rustc.rs
src/comp/driver/session.rs
src/comp/middle/check_usage.rs [deleted file]
src/comp/middle/lint.rs [new file with mode: 0644]
src/comp/rustc.rc

index 20f24a1307aa5b29b1752824a24520017ade7e2d..741f9a2cba8b962bf0a080b9a5709803597b6b40 100644 (file)
@@ -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"
index 54ca5db4294914fd4419e9b0245584a803633b1e..6c2a646f35d4b751fd182177bcf59e8866a57abf 100644 (file)
@@ -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"),
index fcd5f1852ae79e86096ff9fea226902d0ae9efd1..8ca9a3e6f72b7a363e50fe1a89912ea49ed59006 100644 (file)
@@ -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
 
 ");
 }
index 4b7154a5a99b0b9c6fe260a44c3028bb3c582f26..67a8268f5fdd73bda84e0b38aa0d55b570671541 100644 (file)
@@ -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,
diff --git a/src/comp/middle/check_usage.rs b/src/comp/middle/check_usage.rs
deleted file mode 100644 (file)
index 227e563..0000000
+++ /dev/null
@@ -1,59 +0,0 @@
-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:
-//
diff --git a/src/comp/middle/lint.rs b/src/comp/middle/lint.rs
new file mode 100644 (file)
index 0000000..1b19fd6
--- /dev/null
@@ -0,0 +1,75 @@
+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:
+//
index f6405b963bad999b48df7df388c88685dca7e919..20364cc53695a7fa6f4ef7681a8cb6d808f35583 100644 (file)
@@ -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;