Skip to content

Commit 79ed1f2

Browse files
committed
New lint pass for picking out uses of old-style vecs and str.
1 parent 0cdbb93 commit 79ed1f2

File tree

1 file changed

+53
-2
lines changed

1 file changed

+53
-2
lines changed

src/rustc/middle/lint.rs

Lines changed: 53 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import middle::ty;
33
import syntax::{ast, visit};
44
import syntax::attr;
55
import syntax::codemap::span;
6-
import std::map::{map,hashmap,hash_from_strs};
6+
import std::map::{map,hashmap,int_hash,hash_from_strs};
77
import io::writer_util;
88
import syntax::print::pprust::expr_to_str;
99

@@ -26,6 +26,7 @@ enum lint {
2626
unused_imports,
2727
while_true,
2828
path_statement,
29+
old_vecs,
2930
}
3031

3132
enum level {
@@ -62,7 +63,12 @@ fn get_lint_dict() -> lint_dict {
6263
("path_statement",
6364
@{lint: path_statement,
6465
desc: "path statements with no effect",
65-
default: warn})
66+
default: warn}),
67+
68+
("old_vecs",
69+
@{lint: old_vecs,
70+
desc: "old (deprecated) vectors and strings",
71+
default: ignore})
6672

6773
];
6874
hash_from_strs(v)
@@ -185,6 +191,7 @@ fn check_item(cx: ctxt, i: @ast::item) {
185191
unused_imports { check_item_unused_imports(cx, level, i); }
186192
while_true { check_item_while_true(cx, level, i); }
187193
path_statement { check_item_path_statement(cx, level, i); }
194+
old_vecs { check_item_old_vecs(cx, level, i); }
188195
}
189196
}
190197
}
@@ -279,6 +286,50 @@ fn check_item_path_statement(cx: ctxt, level: level, it: @ast::item) {
279286
visit::visit_item(it, (), visit);
280287
}
281288

289+
fn check_item_old_vecs(cx: ctxt, level: level, it: @ast::item) {
290+
let uses_vstore = int_hash();
291+
292+
let visit = visit::mk_simple_visitor(@{
293+
294+
visit_expr:fn@(e: @ast::expr) {
295+
alt e.node {
296+
ast::expr_vec(_, _) |
297+
ast::expr_lit(@{node: ast::lit_str(_), span:_})
298+
if ! uses_vstore.contains_key(e.id) {
299+
cx.span_lint(level, e.span, "deprecated vec/str expr");
300+
}
301+
ast::expr_vstore(@inner, _) {
302+
uses_vstore.insert(inner.id, true);
303+
}
304+
_ { }
305+
}
306+
},
307+
308+
visit_ty: fn@(t: @ast::ty) {
309+
alt t.node {
310+
ast::ty_vec(_)
311+
if ! uses_vstore.contains_key(t.id) {
312+
cx.span_lint(level, t.span, "deprecated vec type");
313+
}
314+
315+
ast::ty_path(@{span: _, global: _, idents: ids,
316+
rp: none, types: _}, _)
317+
if ids == ["str"] && (! uses_vstore.contains_key(t.id)) {
318+
cx.span_lint(level, t.span, "deprecated str type");
319+
}
320+
321+
ast::ty_vstore(inner, _) {
322+
uses_vstore.insert(inner.id, true);
323+
}
324+
_ { }
325+
}
326+
}
327+
328+
with *visit::default_simple_visitor()
329+
});
330+
visit::visit_item(it, (), visit);
331+
}
332+
282333

283334
fn check_crate(tcx: ty::ctxt, crate: @ast::crate,
284335
lint_opts: [(lint, level)], time_pass: bool) {

0 commit comments

Comments
 (0)