about summary refs log tree commit diff
path: root/src/rustc/middle
diff options
context:
space:
mode:
authorGraydon Hoare <graydon@mozilla.com>2012-05-01 12:58:07 -0700
committerGraydon Hoare <graydon@mozilla.com>2012-05-01 12:58:07 -0700
commit79ed1f2df4153a0c868d2ccf53d19dc6d1f08214 (patch)
treefddeae21313202aab89bf5edbce8e336ddd82bbb /src/rustc/middle
parent0cdbb93411e9b3a89b7c2a19c875b5682f52ab41 (diff)
New lint pass for picking out uses of old-style vecs and str.
Diffstat (limited to 'src/rustc/middle')
-rw-r--r--src/rustc/middle/lint.rs55
1 files changed, 53 insertions, 2 deletions
diff --git a/src/rustc/middle/lint.rs b/src/rustc/middle/lint.rs
index ad0f2d54826..6588b9d86b7 100644
--- a/src/rustc/middle/lint.rs
+++ b/src/rustc/middle/lint.rs
@@ -3,7 +3,7 @@ import middle::ty;
 import syntax::{ast, visit};
 import syntax::attr;
 import syntax::codemap::span;
-import std::map::{map,hashmap,hash_from_strs};
+import std::map::{map,hashmap,int_hash,hash_from_strs};
 import io::writer_util;
 import syntax::print::pprust::expr_to_str;
 
@@ -26,6 +26,7 @@ enum lint {
     unused_imports,
     while_true,
     path_statement,
+    old_vecs,
 }
 
 enum level {
@@ -62,7 +63,12 @@ fn get_lint_dict() -> lint_dict {
         ("path_statement",
          @{lint: path_statement,
            desc: "path statements with no effect",
-           default: warn})
+           default: warn}),
+
+        ("old_vecs",
+         @{lint: old_vecs,
+           desc: "old (deprecated) vectors and strings",
+           default: ignore})
 
     ];
     hash_from_strs(v)
@@ -185,6 +191,7 @@ fn check_item(cx: ctxt, i: @ast::item) {
               unused_imports { check_item_unused_imports(cx, level, i); }
               while_true { check_item_while_true(cx, level, i); }
               path_statement { check_item_path_statement(cx, level, i); }
+              old_vecs { check_item_old_vecs(cx, level, i); }
             }
         }
     }
@@ -279,6 +286,50 @@ fn check_item_path_statement(cx: ctxt, level: level, it: @ast::item) {
     visit::visit_item(it, (), visit);
 }
 
+fn check_item_old_vecs(cx: ctxt, level: level, it: @ast::item) {
+    let uses_vstore = int_hash();
+
+    let visit = visit::mk_simple_visitor(@{
+
+        visit_expr:fn@(e: @ast::expr) {
+            alt e.node {
+              ast::expr_vec(_, _) |
+              ast::expr_lit(@{node: ast::lit_str(_), span:_})
+              if ! uses_vstore.contains_key(e.id) {
+                cx.span_lint(level, e.span, "deprecated vec/str expr");
+              }
+              ast::expr_vstore(@inner, _) {
+                uses_vstore.insert(inner.id, true);
+              }
+              _ { }
+            }
+        },
+
+        visit_ty: fn@(t: @ast::ty) {
+            alt t.node {
+              ast::ty_vec(_)
+              if ! uses_vstore.contains_key(t.id) {
+                cx.span_lint(level, t.span, "deprecated vec type");
+              }
+
+              ast::ty_path(@{span: _, global: _, idents: ids,
+                             rp: none, types: _}, _)
+              if ids == ["str"] && (! uses_vstore.contains_key(t.id)) {
+                cx.span_lint(level, t.span, "deprecated str type");
+              }
+
+              ast::ty_vstore(inner, _) {
+                uses_vstore.insert(inner.id, true);
+              }
+              _ { }
+            }
+        }
+
+        with *visit::default_simple_visitor()
+    });
+    visit::visit_item(it, (), visit);
+}
+
 
 fn check_crate(tcx: ty::ctxt, crate: @ast::crate,
                lint_opts: [(lint, level)], time_pass: bool) {