2012-06-04 18:07:54 -05:00
|
|
|
import driver::session;
|
2012-01-19 02:50:51 -06:00
|
|
|
import driver::session::session;
|
2012-04-12 19:30:52 -05:00
|
|
|
import middle::ty;
|
2012-01-19 02:50:51 -06:00
|
|
|
import syntax::{ast, visit};
|
2012-03-22 20:16:22 -05:00
|
|
|
import syntax::attr;
|
2012-04-12 19:30:52 -05:00
|
|
|
import syntax::codemap::span;
|
2012-05-01 14:58:07 -05:00
|
|
|
import std::map::{map,hashmap,int_hash,hash_from_strs};
|
2012-05-31 17:06:45 -05:00
|
|
|
import std::smallintmap::{map,smallintmap};
|
2012-01-21 11:20:22 -06:00
|
|
|
import io::writer_util;
|
2012-04-19 20:04:41 -05:00
|
|
|
import syntax::print::pprust::expr_to_str;
|
2012-05-22 12:54:12 -05:00
|
|
|
export lint, ctypes, unused_imports, while_true, path_statement, old_vecs;
|
|
|
|
export unrecognized_warning, non_implicitly_copyable_typarams;
|
|
|
|
export vecs_not_implicitly_copyable, implicit_copies;
|
2012-04-12 19:30:52 -05:00
|
|
|
export level, ignore, warn, error;
|
2012-06-04 20:34:11 -05:00
|
|
|
export lookup_lint, lint_dict, get_lint_dict;
|
|
|
|
export get_warning_level, get_warning_settings_level;
|
2012-06-04 18:07:54 -05:00
|
|
|
export check_crate, build_settings_crate, mk_warning_settings;
|
|
|
|
export warning_settings;
|
2012-04-12 19:30:52 -05:00
|
|
|
|
|
|
|
#[doc="
|
|
|
|
|
2012-04-19 20:04:41 -05:00
|
|
|
A 'lint' check is a kind of miscellaneous constraint that a user _might_ want
|
2012-04-12 19:30:52 -05:00
|
|
|
to enforce, but might reasonably want to permit as well, on a module-by-module
|
|
|
|
basis. They contrast with static constraints enforced by other phases of the
|
|
|
|
compiler, which are generally required to hold in order to compile the program
|
2012-04-19 20:04:41 -05:00
|
|
|
at all.
|
2012-04-12 19:30:52 -05:00
|
|
|
|
2012-06-01 16:25:06 -05:00
|
|
|
We also build up a table containing information about lint settings, in order
|
|
|
|
to allow other passes to take advantage of the warning attribute
|
|
|
|
infrastructure. To save space, the table is keyed by the id of /items/, not of
|
|
|
|
every expression. When an item has the default settings, the entry will be
|
|
|
|
omitted. If we start allowing warn attributes on expressions, we will start
|
|
|
|
having entries for expressions that do not share their enclosing items
|
|
|
|
settings.
|
|
|
|
|
2012-06-04 18:07:54 -05:00
|
|
|
This module then, exports two passes: one that populates the warning settings
|
|
|
|
table in the session and is run early in the compile process, and one that
|
|
|
|
does a variety of lint checks, and is run late in the compile process.
|
|
|
|
|
2012-04-12 19:30:52 -05:00
|
|
|
"]
|
|
|
|
|
|
|
|
enum lint {
|
2012-01-19 19:56:05 -06:00
|
|
|
ctypes,
|
2012-04-12 19:30:52 -05:00
|
|
|
unused_imports,
|
2012-04-26 15:47:13 -05:00
|
|
|
while_true,
|
|
|
|
path_statement,
|
2012-05-01 14:58:07 -05:00
|
|
|
old_vecs,
|
2012-06-01 17:58:04 -05:00
|
|
|
unrecognized_warning,
|
2012-05-29 18:22:22 -05:00
|
|
|
non_implicitly_copyable_typarams,
|
2012-06-04 20:34:11 -05:00
|
|
|
vecs_not_implicitly_copyable,
|
2012-06-04 22:44:58 -05:00
|
|
|
implicit_copies,
|
2012-06-22 19:37:19 -05:00
|
|
|
old_strs,
|
2012-01-19 02:50:51 -06:00
|
|
|
}
|
|
|
|
|
2012-05-31 17:06:45 -05:00
|
|
|
// This is pretty unfortunate. We really want some sort of "deriving Enum"
|
|
|
|
// type of thing.
|
|
|
|
fn int_to_lint(i: int) -> lint {
|
|
|
|
alt check i {
|
|
|
|
0 { ctypes }
|
|
|
|
1 { unused_imports }
|
|
|
|
2 { while_true }
|
|
|
|
3 { path_statement }
|
|
|
|
4 { old_vecs }
|
2012-06-01 17:58:04 -05:00
|
|
|
5 { unrecognized_warning }
|
2012-05-29 18:22:22 -05:00
|
|
|
6 { non_implicitly_copyable_typarams }
|
2012-06-04 20:34:11 -05:00
|
|
|
7 { vecs_not_implicitly_copyable }
|
2012-06-04 22:44:58 -05:00
|
|
|
8 { implicit_copies }
|
2012-06-22 19:37:19 -05:00
|
|
|
9 { old_strs }
|
2012-05-31 17:06:45 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-04-12 19:30:52 -05:00
|
|
|
enum level {
|
|
|
|
ignore, warn, error
|
2012-01-21 11:20:22 -06:00
|
|
|
}
|
|
|
|
|
2012-04-12 19:30:52 -05:00
|
|
|
type lint_spec = @{lint: lint,
|
|
|
|
desc: str,
|
|
|
|
default: level};
|
|
|
|
|
|
|
|
type lint_dict = hashmap<str,lint_spec>;
|
|
|
|
|
2012-04-19 20:04:41 -05:00
|
|
|
/*
|
|
|
|
Pass names should not contain a '-', as the compiler normalizes
|
|
|
|
'-' to '_' in command-line flags
|
|
|
|
*/
|
2012-04-12 19:30:52 -05:00
|
|
|
fn get_lint_dict() -> lint_dict {
|
2012-06-29 18:26:56 -05:00
|
|
|
let v = ~[
|
2012-04-12 19:30:52 -05:00
|
|
|
("ctypes",
|
|
|
|
@{lint: ctypes,
|
2012-07-03 18:11:00 -05:00
|
|
|
desc: "proper use of core::libc types in foreign modules",
|
2012-04-12 19:30:52 -05:00
|
|
|
default: warn}),
|
|
|
|
|
2012-04-12 20:11:23 -05:00
|
|
|
("unused_imports",
|
2012-04-12 19:30:52 -05:00
|
|
|
@{lint: unused_imports,
|
|
|
|
desc: "imports that are never used",
|
2012-04-19 20:04:41 -05:00
|
|
|
default: ignore}),
|
|
|
|
|
|
|
|
("while_true",
|
|
|
|
@{lint: while_true,
|
|
|
|
desc: "suggest using loop { } instead of while(true) { }",
|
2012-04-26 15:47:13 -05:00
|
|
|
default: warn}),
|
|
|
|
|
|
|
|
("path_statement",
|
|
|
|
@{lint: path_statement,
|
|
|
|
desc: "path statements with no effect",
|
2012-05-01 14:58:07 -05:00
|
|
|
default: warn}),
|
|
|
|
|
|
|
|
("old_vecs",
|
|
|
|
@{lint: old_vecs,
|
2012-06-22 19:37:19 -05:00
|
|
|
desc: "old (deprecated) vectors",
|
|
|
|
default: warn}),
|
|
|
|
|
|
|
|
("old_strs",
|
|
|
|
@{lint: old_strs,
|
|
|
|
desc: "old (deprecated) strings",
|
2012-06-01 17:58:04 -05:00
|
|
|
default: ignore}),
|
|
|
|
|
|
|
|
("unrecognized_warning",
|
|
|
|
@{lint: unrecognized_warning,
|
|
|
|
desc: "unrecognized warning attribute",
|
2012-05-29 18:22:22 -05:00
|
|
|
default: warn}),
|
|
|
|
|
|
|
|
("non_implicitly_copyable_typarams",
|
|
|
|
@{lint: non_implicitly_copyable_typarams,
|
|
|
|
desc: "passing non implicitly copyable types as copy type params",
|
2012-06-04 20:34:11 -05:00
|
|
|
default: warn}),
|
|
|
|
|
|
|
|
("vecs_not_implicitly_copyable",
|
|
|
|
@{lint: vecs_not_implicitly_copyable,
|
|
|
|
desc: "make vecs and strs not implicitly copyable\
|
|
|
|
('err' is ignored; only checked at top level",
|
2012-06-04 22:44:58 -05:00
|
|
|
default: warn}),
|
|
|
|
|
|
|
|
("implicit_copies",
|
|
|
|
@{lint: implicit_copies,
|
|
|
|
desc: "implicit copies of non implicitly copyable data",
|
2012-06-01 17:58:04 -05:00
|
|
|
default: warn})
|
2012-04-26 15:47:13 -05:00
|
|
|
|
2012-06-29 18:26:56 -05:00
|
|
|
];
|
2012-04-12 19:30:52 -05:00
|
|
|
hash_from_strs(v)
|
2012-01-21 11:20:22 -06:00
|
|
|
}
|
|
|
|
|
2012-05-31 18:13:42 -05:00
|
|
|
// This is a highly not-optimal set of data structure decisions.
|
|
|
|
type lint_modes = smallintmap<level>;
|
|
|
|
type lint_mode_map = hashmap<ast::node_id, lint_modes>;
|
|
|
|
|
2012-05-31 21:07:00 -05:00
|
|
|
// settings_map maps node ids of items with non-default warning settings
|
|
|
|
// to their settings; default_settings contains the settings for everything
|
|
|
|
// not in the map.
|
2012-05-31 18:13:42 -05:00
|
|
|
type warning_settings = {
|
|
|
|
default_settings: lint_modes,
|
|
|
|
settings_map: lint_mode_map
|
|
|
|
};
|
|
|
|
|
2012-06-04 18:07:54 -05:00
|
|
|
fn mk_warning_settings() -> warning_settings {
|
|
|
|
{default_settings: std::smallintmap::mk(),
|
|
|
|
settings_map: int_hash()}
|
|
|
|
}
|
|
|
|
|
2012-06-01 16:25:06 -05:00
|
|
|
fn get_warning_level(modes: lint_modes, lint: lint) -> level {
|
|
|
|
alt modes.find(lint as uint) {
|
|
|
|
some(c) { c }
|
|
|
|
none { ignore }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-04 18:07:54 -05:00
|
|
|
fn get_warning_settings_level(settings: warning_settings,
|
|
|
|
lint_mode: lint,
|
|
|
|
_expr_id: ast::node_id,
|
|
|
|
item_id: ast::node_id) -> level {
|
|
|
|
alt settings.settings_map.find(item_id) {
|
|
|
|
some(modes) { get_warning_level(modes, lint_mode) }
|
|
|
|
none { get_warning_level(settings.default_settings, lint_mode) }
|
2012-06-01 16:25:06 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-05-31 18:13:42 -05:00
|
|
|
// This is kind of unfortunate. It should be somewhere else, or we should use
|
|
|
|
// a persistent data structure...
|
|
|
|
fn clone_lint_modes(modes: lint_modes) -> lint_modes {
|
|
|
|
@{v: copy modes.v}
|
|
|
|
}
|
|
|
|
|
|
|
|
type ctxt = {dict: lint_dict,
|
|
|
|
curr: lint_modes,
|
2012-05-31 21:07:00 -05:00
|
|
|
is_default: bool,
|
2012-06-04 18:07:54 -05:00
|
|
|
sess: session};
|
2012-05-31 18:13:42 -05:00
|
|
|
|
2012-01-21 11:20:22 -06:00
|
|
|
|
2012-04-12 19:30:52 -05:00
|
|
|
impl methods for ctxt {
|
|
|
|
fn get_level(lint: lint) -> level {
|
2012-06-01 16:25:06 -05:00
|
|
|
get_warning_level(self.curr, lint)
|
2012-01-21 11:20:22 -06:00
|
|
|
}
|
|
|
|
|
2012-04-12 19:30:52 -05:00
|
|
|
fn set_level(lint: lint, level: level) {
|
|
|
|
if level == ignore {
|
2012-05-31 17:06:45 -05:00
|
|
|
self.curr.remove(lint as uint);
|
2012-04-12 19:30:52 -05:00
|
|
|
} else {
|
2012-05-31 17:06:45 -05:00
|
|
|
self.curr.insert(lint as uint, level);
|
2012-04-12 19:30:52 -05:00
|
|
|
}
|
2012-01-21 11:20:22 -06:00
|
|
|
}
|
|
|
|
|
2012-04-12 19:30:52 -05:00
|
|
|
fn span_lint(level: level, span: span, msg: str) {
|
2012-06-04 18:07:54 -05:00
|
|
|
self.sess.span_lint_level(level, span, msg);
|
2012-01-21 11:20:22 -06:00
|
|
|
}
|
|
|
|
|
2012-04-12 19:30:52 -05:00
|
|
|
#[doc="
|
|
|
|
Merge the warnings specified by any `warn(...)` attributes into the
|
|
|
|
current lint context, call the provided function, then reset the
|
|
|
|
warnings in effect to their previous state.
|
|
|
|
"]
|
2012-06-29 18:26:56 -05:00
|
|
|
fn with_warn_attrs(attrs: ~[ast::attribute], f: fn(ctxt)) {
|
2012-01-21 11:20:22 -06:00
|
|
|
|
2012-05-31 18:13:42 -05:00
|
|
|
let mut new_ctxt = self;
|
2012-01-21 11:20:22 -06:00
|
|
|
|
2012-04-12 19:30:52 -05:00
|
|
|
let metas = attr::attr_metas(attr::find_attrs_by_name(attrs, "warn"));
|
2012-06-30 18:19:07 -05:00
|
|
|
for metas.each |meta| {
|
2012-04-12 19:30:52 -05:00
|
|
|
alt meta.node {
|
|
|
|
ast::meta_list(_, metas) {
|
2012-06-30 18:19:07 -05:00
|
|
|
for metas.each |meta| {
|
2012-04-12 19:30:52 -05:00
|
|
|
alt meta.node {
|
|
|
|
ast::meta_word(lintname) {
|
2012-06-10 02:49:59 -05:00
|
|
|
alt lookup_lint(self.dict, *lintname) {
|
2012-06-01 17:58:04 -05:00
|
|
|
(name, none) {
|
|
|
|
self.span_lint(
|
|
|
|
self.get_level(unrecognized_warning),
|
2012-04-12 19:30:52 -05:00
|
|
|
meta.span,
|
2012-06-01 17:58:04 -05:00
|
|
|
#fmt("unknown warning: '%s'", name));
|
2012-04-12 19:30:52 -05:00
|
|
|
}
|
2012-06-01 17:58:04 -05:00
|
|
|
(_, some((lint, new_level))) {
|
2012-05-31 18:13:42 -05:00
|
|
|
// we do multiple unneeded copies of the map
|
|
|
|
// if many attributes are set, but this shouldn't
|
|
|
|
// actually be a problem...
|
2012-05-31 21:07:00 -05:00
|
|
|
new_ctxt = {is_default: false,
|
2012-06-04 20:07:26 -05:00
|
|
|
curr: clone_lint_modes(new_ctxt.curr)
|
2012-05-31 18:13:42 -05:00
|
|
|
with new_ctxt};
|
|
|
|
new_ctxt.set_level(lint, new_level);
|
2012-04-12 19:30:52 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
_ {
|
2012-06-04 18:07:54 -05:00
|
|
|
self.sess.span_err(
|
2012-04-12 19:30:52 -05:00
|
|
|
meta.span,
|
|
|
|
"malformed warning attribute");
|
|
|
|
}
|
|
|
|
}
|
2012-01-21 11:20:22 -06:00
|
|
|
}
|
2012-04-12 19:30:52 -05:00
|
|
|
}
|
|
|
|
_ {
|
2012-06-04 18:07:54 -05:00
|
|
|
self.sess.span_err(meta.span,
|
|
|
|
"malformed warning attribute");
|
2012-04-12 19:30:52 -05:00
|
|
|
}
|
2012-01-21 11:20:22 -06:00
|
|
|
}
|
|
|
|
}
|
2012-04-12 19:30:52 -05:00
|
|
|
|
2012-05-31 18:13:42 -05:00
|
|
|
f(new_ctxt);
|
2012-04-12 19:30:52 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fn lookup_lint(dict: lint_dict, s: str)
|
2012-06-01 17:58:04 -05:00
|
|
|
-> (str, option<(lint, level)>) {
|
2012-04-12 19:30:52 -05:00
|
|
|
let s = str::replace(s, "-", "_");
|
|
|
|
let (name, level) = if s.starts_with("no_") {
|
|
|
|
(s.substr(3u, s.len() - 3u), ignore)
|
|
|
|
} else if s.starts_with("err_") {
|
|
|
|
(s.substr(4u, s.len() - 4u), error)
|
|
|
|
} else {
|
|
|
|
(s, warn)
|
2012-01-21 11:20:22 -06:00
|
|
|
};
|
2012-06-01 17:58:04 -05:00
|
|
|
(name,
|
|
|
|
alt dict.find(name) {
|
|
|
|
none { none }
|
|
|
|
some(spec) { some((spec.lint, level)) }
|
|
|
|
})
|
2012-04-12 19:30:52 -05:00
|
|
|
}
|
|
|
|
|
2012-06-04 18:07:54 -05:00
|
|
|
fn build_settings_item(i: @ast::item, &&cx: ctxt, v: visit::vt<ctxt>) {
|
2012-06-30 18:19:07 -05:00
|
|
|
do cx.with_warn_attrs(i.attrs) |cx| {
|
2012-05-31 21:07:00 -05:00
|
|
|
if !cx.is_default {
|
2012-06-04 18:07:54 -05:00
|
|
|
cx.sess.warning_settings.settings_map.insert(i.id, cx.curr);
|
2012-05-31 21:07:00 -05:00
|
|
|
}
|
2012-05-31 20:24:00 -05:00
|
|
|
visit::visit_item(i, cx, v);
|
2012-01-21 11:20:22 -06:00
|
|
|
}
|
2012-04-12 19:30:52 -05:00
|
|
|
}
|
2012-01-21 11:20:22 -06:00
|
|
|
|
2012-06-04 18:07:54 -05:00
|
|
|
fn build_settings_crate(sess: session::session, crate: @ast::crate) {
|
|
|
|
|
|
|
|
let cx = {dict: get_lint_dict(),
|
|
|
|
curr: std::smallintmap::mk(),
|
|
|
|
is_default: true,
|
|
|
|
sess: sess};
|
|
|
|
|
|
|
|
// Install defaults.
|
2012-06-30 18:19:07 -05:00
|
|
|
for cx.dict.each |_k, spec| { cx.set_level(spec.lint, spec.default); }
|
2012-06-04 18:07:54 -05:00
|
|
|
|
|
|
|
// Install command-line options, overriding defaults.
|
2012-06-30 18:19:07 -05:00
|
|
|
for sess.opts.lint_opts.each |pair| {
|
2012-06-04 18:07:54 -05:00
|
|
|
let (lint,level) = pair;
|
|
|
|
cx.set_level(lint, level);
|
|
|
|
}
|
|
|
|
|
2012-06-30 18:19:07 -05:00
|
|
|
do cx.with_warn_attrs(crate.node.attrs) |cx| {
|
2012-06-04 18:07:54 -05:00
|
|
|
// Copy out the default settings
|
2012-06-30 18:19:07 -05:00
|
|
|
for cx.curr.each |k, v| {
|
2012-06-04 18:07:54 -05:00
|
|
|
sess.warning_settings.default_settings.insert(k, v);
|
|
|
|
}
|
|
|
|
|
|
|
|
let cx = {is_default: true with cx};
|
|
|
|
|
|
|
|
let visit = visit::mk_vt(@{
|
|
|
|
visit_item: build_settings_item
|
|
|
|
with *visit::default_visitor()
|
|
|
|
});
|
|
|
|
visit::visit_crate(*crate, cx, visit);
|
|
|
|
}
|
|
|
|
|
|
|
|
sess.abort_if_errors();
|
|
|
|
}
|
|
|
|
|
|
|
|
fn check_item(i: @ast::item, cx: ty::ctxt) {
|
|
|
|
check_item_ctypes(cx, i);
|
|
|
|
check_item_while_true(cx, i);
|
|
|
|
check_item_path_statement(cx, i);
|
|
|
|
check_item_old_vecs(cx, i);
|
|
|
|
}
|
|
|
|
|
2012-05-31 20:24:00 -05:00
|
|
|
// Take a visitor, and modify it so that it will not proceed past subitems.
|
|
|
|
// This is used to make the simple visitors used for the lint passes
|
|
|
|
// not traverse into subitems, since that is handled by the outer
|
|
|
|
// lint visitor.
|
|
|
|
fn item_stopping_visitor<E>(v: visit::vt<E>) -> visit::vt<E> {
|
2012-06-30 18:19:07 -05:00
|
|
|
visit::mk_vt(@{visit_item: |_i, _e, _v| { } with **v})
|
2012-05-31 20:24:00 -05:00
|
|
|
}
|
|
|
|
|
2012-06-04 18:07:54 -05:00
|
|
|
fn check_item_while_true(cx: ty::ctxt, it: @ast::item) {
|
2012-05-31 20:24:00 -05:00
|
|
|
let visit = item_stopping_visitor(visit::mk_simple_visitor(@{
|
2012-04-19 20:04:41 -05:00
|
|
|
visit_expr: fn@(e: @ast::expr) {
|
|
|
|
alt e.node {
|
|
|
|
ast::expr_while(cond, _) {
|
|
|
|
alt cond.node {
|
|
|
|
ast::expr_lit(@{node: ast::lit_bool(true),_}) {
|
2012-06-04 18:07:54 -05:00
|
|
|
cx.sess.span_lint(
|
2012-06-20 12:30:48 -05:00
|
|
|
while_true, e.id, it.id,
|
2012-06-04 18:07:54 -05:00
|
|
|
e.span,
|
|
|
|
"denote infinite loops with loop { ... }");
|
2012-04-19 20:04:41 -05:00
|
|
|
}
|
|
|
|
_ {}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
_ {}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
with *visit::default_simple_visitor()
|
2012-05-31 20:24:00 -05:00
|
|
|
}));
|
2012-04-19 20:04:41 -05:00
|
|
|
visit::visit_item(it, (), visit);
|
|
|
|
}
|
|
|
|
|
2012-06-04 18:07:54 -05:00
|
|
|
fn check_item_ctypes(cx: ty::ctxt, it: @ast::item) {
|
2012-04-12 19:30:52 -05:00
|
|
|
|
2012-06-26 18:18:37 -05:00
|
|
|
fn check_foreign_fn(cx: ty::ctxt, fn_id: ast::node_id,
|
2012-06-04 18:07:54 -05:00
|
|
|
decl: ast::fn_decl) {
|
2012-06-30 18:19:07 -05:00
|
|
|
let tys = vec::map(decl.inputs, |a| a.ty );
|
|
|
|
for vec::each(vec::append_one(tys, decl.output)) |ty| {
|
2012-01-19 02:50:51 -06:00
|
|
|
alt ty.node {
|
2012-02-06 08:29:56 -06:00
|
|
|
ast::ty_path(_, id) {
|
2012-06-04 18:07:54 -05:00
|
|
|
alt cx.def_map.get(id) {
|
2012-02-06 08:29:56 -06:00
|
|
|
ast::def_prim_ty(ast::ty_int(ast::ty_i)) {
|
2012-06-04 18:07:54 -05:00
|
|
|
cx.sess.span_lint(
|
2012-06-20 12:30:48 -05:00
|
|
|
ctypes, id, fn_id,
|
2012-06-04 18:07:54 -05:00
|
|
|
ty.span,
|
2012-07-03 18:11:00 -05:00
|
|
|
"found rust type `int` in foreign module, while \
|
2012-03-12 22:04:27 -05:00
|
|
|
libc::c_int or libc::c_long should be used");
|
2012-02-06 08:29:56 -06:00
|
|
|
}
|
|
|
|
ast::def_prim_ty(ast::ty_uint(ast::ty_u)) {
|
2012-06-04 18:07:54 -05:00
|
|
|
cx.sess.span_lint(
|
2012-06-20 12:30:48 -05:00
|
|
|
ctypes, id, fn_id,
|
2012-06-04 18:07:54 -05:00
|
|
|
ty.span,
|
2012-07-03 18:11:00 -05:00
|
|
|
"found rust type `uint` in foreign module, while \
|
2012-03-12 22:04:27 -05:00
|
|
|
libc::c_uint or libc::c_ulong should be used");
|
2012-02-06 08:29:56 -06:00
|
|
|
}
|
|
|
|
_ { }
|
|
|
|
}
|
2012-01-19 02:50:51 -06:00
|
|
|
}
|
|
|
|
_ { }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-04-12 19:30:52 -05:00
|
|
|
alt it.node {
|
2012-06-26 18:18:37 -05:00
|
|
|
ast::item_foreign_mod(nmod) if attr::foreign_abi(it.attrs) !=
|
|
|
|
either::right(ast::foreign_abi_rust_intrinsic) {
|
2012-06-30 18:19:07 -05:00
|
|
|
for nmod.items.each |ni| {
|
2012-04-12 19:30:52 -05:00
|
|
|
alt ni.node {
|
2012-06-26 18:18:37 -05:00
|
|
|
ast::foreign_item_fn(decl, tps) {
|
|
|
|
check_foreign_fn(cx, it.id, decl);
|
2012-04-12 19:30:52 -05:00
|
|
|
}
|
2012-01-19 02:50:51 -06:00
|
|
|
}
|
|
|
|
}
|
2012-04-12 19:30:52 -05:00
|
|
|
}
|
|
|
|
_ {/* nothing to do */ }
|
2012-01-19 02:50:51 -06:00
|
|
|
}
|
|
|
|
}
|
2012-01-21 11:20:22 -06:00
|
|
|
|
2012-06-04 18:07:54 -05:00
|
|
|
fn check_item_path_statement(cx: ty::ctxt, it: @ast::item) {
|
2012-05-31 20:24:00 -05:00
|
|
|
let visit = item_stopping_visitor(visit::mk_simple_visitor(@{
|
2012-04-26 15:47:13 -05:00
|
|
|
visit_stmt: fn@(s: @ast::stmt) {
|
|
|
|
alt s.node {
|
2012-07-03 18:06:09 -05:00
|
|
|
ast::stmt_expr(@{id: id,
|
2012-04-26 15:47:13 -05:00
|
|
|
node: ast::expr_path(@path),
|
|
|
|
span: _}, _) {
|
2012-06-04 18:07:54 -05:00
|
|
|
cx.sess.span_lint(
|
2012-06-20 12:30:48 -05:00
|
|
|
path_statement, id, it.id,
|
2012-06-04 18:07:54 -05:00
|
|
|
s.span,
|
2012-04-26 15:47:13 -05:00
|
|
|
"path statement with no effect");
|
|
|
|
}
|
|
|
|
_ {}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
with *visit::default_simple_visitor()
|
2012-05-31 20:24:00 -05:00
|
|
|
}));
|
2012-04-26 15:47:13 -05:00
|
|
|
visit::visit_item(it, (), visit);
|
|
|
|
}
|
|
|
|
|
2012-06-04 18:07:54 -05:00
|
|
|
fn check_item_old_vecs(cx: ty::ctxt, it: @ast::item) {
|
2012-05-01 14:58:07 -05:00
|
|
|
let uses_vstore = int_hash();
|
|
|
|
|
2012-05-31 20:24:00 -05:00
|
|
|
let visit = item_stopping_visitor(visit::mk_simple_visitor(@{
|
2012-05-01 14:58:07 -05:00
|
|
|
|
|
|
|
visit_expr:fn@(e: @ast::expr) {
|
|
|
|
alt e.node {
|
2012-06-22 19:37:19 -05:00
|
|
|
ast::expr_vec(_, _)
|
2012-05-01 14:58:07 -05:00
|
|
|
if ! uses_vstore.contains_key(e.id) {
|
2012-06-04 18:07:54 -05:00
|
|
|
cx.sess.span_lint(
|
2012-06-20 12:30:48 -05:00
|
|
|
old_vecs, e.id, it.id,
|
2012-06-22 19:37:19 -05:00
|
|
|
e.span, "deprecated vec expr");
|
2012-05-01 14:58:07 -05:00
|
|
|
}
|
2012-06-22 19:37:19 -05:00
|
|
|
ast::expr_lit(@{node: ast::lit_str(_), span:_})
|
|
|
|
if ! uses_vstore.contains_key(e.id) {
|
|
|
|
cx.sess.span_lint(
|
|
|
|
old_strs, e.id, it.id,
|
|
|
|
e.span, "deprecated str expr");
|
|
|
|
}
|
|
|
|
|
2012-05-01 14:58:07 -05:00
|
|
|
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) {
|
2012-06-04 18:07:54 -05:00
|
|
|
cx.sess.span_lint(
|
2012-06-20 12:30:48 -05:00
|
|
|
old_vecs, t.id, it.id,
|
2012-06-04 18:07:54 -05:00
|
|
|
t.span, "deprecated vec type");
|
2012-05-01 14:58:07 -05:00
|
|
|
}
|
|
|
|
ast::ty_path(@{span: _, global: _, idents: ids,
|
|
|
|
rp: none, types: _}, _)
|
2012-06-29 18:26:56 -05:00
|
|
|
if ids == ~[@"str"] && (! uses_vstore.contains_key(t.id)) {
|
2012-06-04 18:07:54 -05:00
|
|
|
cx.sess.span_lint(
|
2012-06-22 19:37:19 -05:00
|
|
|
old_strs, t.id, it.id,
|
2012-06-04 18:07:54 -05:00
|
|
|
t.span, "deprecated str type");
|
2012-05-01 14:58:07 -05:00
|
|
|
}
|
|
|
|
ast::ty_vstore(inner, _) {
|
|
|
|
uses_vstore.insert(inner.id, true);
|
|
|
|
}
|
|
|
|
_ { }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
with *visit::default_simple_visitor()
|
2012-05-31 20:24:00 -05:00
|
|
|
}));
|
2012-05-01 14:58:07 -05:00
|
|
|
visit::visit_item(it, (), visit);
|
|
|
|
}
|
|
|
|
|
2012-06-04 18:07:54 -05:00
|
|
|
fn check_crate(tcx: ty::ctxt, crate: @ast::crate) {
|
2012-04-12 19:30:52 -05:00
|
|
|
|
2012-06-04 18:07:54 -05:00
|
|
|
let v = visit::mk_simple_visitor(@{
|
|
|
|
visit_item: fn@(it: @ast::item) { check_item(it, tcx); }
|
|
|
|
with *visit::default_simple_visitor()
|
|
|
|
});
|
|
|
|
visit::visit_crate(*crate, (), v);
|
2012-04-12 19:30:52 -05:00
|
|
|
|
|
|
|
tcx.sess.abort_if_errors();
|
2012-01-21 11:20:22 -06:00
|
|
|
}
|
2012-04-12 19:30:52 -05:00
|
|
|
|
2012-01-19 02:50:51 -06:00
|
|
|
//
|
|
|
|
// Local Variables:
|
|
|
|
// mode: rust
|
|
|
|
// fill-column: 78;
|
|
|
|
// indent-tabs-mode: nil
|
|
|
|
// c-basic-offset: 4
|
|
|
|
// buffer-file-coding-system: utf-8-unix
|
|
|
|
// End:
|
|
|
|
//
|