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-08-14 15:38:35 -05:00
|
|
|
import io::WriterUtil;
|
2012-07-25 08:41:56 -05:00
|
|
|
import util::ppaux::{ty_to_str};
|
2012-08-07 09:14:44 -05:00
|
|
|
import middle::pat_util::{pat_bindings};
|
|
|
|
import syntax::ast_util::{path_to_ident};
|
|
|
|
import syntax::print::pprust::{expr_to_str, mode_to_str, pat_to_str};
|
2012-05-22 12:54:12 -05:00
|
|
|
export lint, ctypes, unused_imports, while_true, path_statement, old_vecs;
|
Nomenclature fixes in the lint checker. Fewer double-negatives.
New style is allow(foo), warn(foo), deny(foo) and forbid(foo),
mirrored by -A foo, -W foo, -D foo and -F foo on command line.
These replace -W no-foo, -W foo, -W err-foo, respectively.
Forbid is new, and means "deny, and you can't override it".
2012-07-26 19:08:21 -05:00
|
|
|
export unrecognized_lint, non_implicitly_copyable_typarams;
|
|
|
|
export vecs_implicitly_copyable, implicit_copies;
|
|
|
|
export level, allow, warn, deny, forbid;
|
|
|
|
export lint_dict, get_lint_dict, level_to_str;
|
|
|
|
export get_lint_level, get_lint_settings_level;
|
|
|
|
export check_crate, build_settings_crate, mk_lint_settings;
|
|
|
|
export lint_settings;
|
2012-04-12 19:30:52 -05:00
|
|
|
|
2012-07-04 16:53:12 -05:00
|
|
|
/**
|
|
|
|
* A 'lint' check is a kind of miscellaneous constraint that a user _might_
|
|
|
|
* want 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 at all.
|
|
|
|
*
|
|
|
|
* We also build up a table containing information about lint settings, in
|
Nomenclature fixes in the lint checker. Fewer double-negatives.
New style is allow(foo), warn(foo), deny(foo) and forbid(foo),
mirrored by -A foo, -W foo, -D foo and -F foo on command line.
These replace -W no-foo, -W foo, -W err-foo, respectively.
Forbid is new, and means "deny, and you can't override it".
2012-07-26 19:08:21 -05:00
|
|
|
* order to allow other passes to take advantage of the lint attribute
|
2012-07-04 16:53:12 -05:00
|
|
|
* 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
|
Nomenclature fixes in the lint checker. Fewer double-negatives.
New style is allow(foo), warn(foo), deny(foo) and forbid(foo),
mirrored by -A foo, -W foo, -D foo and -F foo on command line.
These replace -W no-foo, -W foo, -W err-foo, respectively.
Forbid is new, and means "deny, and you can't override it".
2012-07-26 19:08:21 -05:00
|
|
|
* be omitted. If we start allowing lint attributes on expressions, we will
|
2012-07-04 16:53:12 -05:00
|
|
|
* start having entries for expressions that do not share their enclosing
|
|
|
|
* items settings.
|
|
|
|
*
|
Nomenclature fixes in the lint checker. Fewer double-negatives.
New style is allow(foo), warn(foo), deny(foo) and forbid(foo),
mirrored by -A foo, -W foo, -D foo and -F foo on command line.
These replace -W no-foo, -W foo, -W err-foo, respectively.
Forbid is new, and means "deny, and you can't override it".
2012-07-26 19:08:21 -05:00
|
|
|
* This module then, exports two passes: one that populates the lint
|
2012-07-04 16:53:12 -05:00
|
|
|
* 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-07-14 15:55:41 -05:00
|
|
|
implicit_copies,
|
Nomenclature fixes in the lint checker. Fewer double-negatives.
New style is allow(foo), warn(foo), deny(foo) and forbid(foo),
mirrored by -A foo, -W foo, -D foo and -F foo on command line.
These replace -W no-foo, -W foo, -W err-foo, respectively.
Forbid is new, and means "deny, and you can't override it".
2012-07-26 19:08:21 -05:00
|
|
|
unrecognized_lint,
|
2012-05-29 18:22:22 -05:00
|
|
|
non_implicitly_copyable_typarams,
|
Nomenclature fixes in the lint checker. Fewer double-negatives.
New style is allow(foo), warn(foo), deny(foo) and forbid(foo),
mirrored by -A foo, -W foo, -D foo and -F foo on command line.
These replace -W no-foo, -W foo, -W err-foo, respectively.
Forbid is new, and means "deny, and you can't override it".
2012-07-26 19:08:21 -05:00
|
|
|
vecs_implicitly_copyable,
|
2012-07-25 08:41:56 -05:00
|
|
|
deprecated_mode,
|
2012-08-07 09:14:44 -05:00
|
|
|
deprecated_pattern,
|
2012-07-31 20:58:03 -05:00
|
|
|
non_camel_case_types
|
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 {
|
2012-08-06 14:34:08 -05:00
|
|
|
match check i {
|
2012-08-03 21:59:04 -05:00
|
|
|
0 => ctypes,
|
|
|
|
1 => unused_imports,
|
|
|
|
2 => while_true,
|
|
|
|
3 => path_statement,
|
|
|
|
4 => implicit_copies,
|
|
|
|
5 => unrecognized_lint,
|
|
|
|
6 => non_implicitly_copyable_typarams,
|
|
|
|
7 => vecs_implicitly_copyable,
|
|
|
|
8 => deprecated_mode,
|
|
|
|
9 => non_camel_case_types
|
2012-05-31 17:06:45 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Nomenclature fixes in the lint checker. Fewer double-negatives.
New style is allow(foo), warn(foo), deny(foo) and forbid(foo),
mirrored by -A foo, -W foo, -D foo and -F foo on command line.
These replace -W no-foo, -W foo, -W err-foo, respectively.
Forbid is new, and means "deny, and you can't override it".
2012-07-26 19:08:21 -05:00
|
|
|
fn level_to_str(lv: level) -> ~str {
|
2012-08-06 14:34:08 -05:00
|
|
|
match lv {
|
2012-08-03 21:59:04 -05:00
|
|
|
allow => ~"allow",
|
|
|
|
warn => ~"warn",
|
|
|
|
deny => ~"deny",
|
|
|
|
forbid => ~"forbid"
|
Nomenclature fixes in the lint checker. Fewer double-negatives.
New style is allow(foo), warn(foo), deny(foo) and forbid(foo),
mirrored by -A foo, -W foo, -D foo and -F foo on command line.
These replace -W no-foo, -W foo, -W err-foo, respectively.
Forbid is new, and means "deny, and you can't override it".
2012-07-26 19:08:21 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-04-12 19:30:52 -05:00
|
|
|
enum level {
|
Nomenclature fixes in the lint checker. Fewer double-negatives.
New style is allow(foo), warn(foo), deny(foo) and forbid(foo),
mirrored by -A foo, -W foo, -D foo and -F foo on command line.
These replace -W no-foo, -W foo, -W err-foo, respectively.
Forbid is new, and means "deny, and you can't override it".
2012-07-26 19:08:21 -05:00
|
|
|
allow, warn, deny, forbid
|
2012-01-21 11:20:22 -06:00
|
|
|
}
|
|
|
|
|
2012-04-12 19:30:52 -05:00
|
|
|
type lint_spec = @{lint: lint,
|
2012-07-14 00:57:48 -05:00
|
|
|
desc: ~str,
|
2012-04-12 19:30:52 -05:00
|
|
|
default: level};
|
|
|
|
|
2012-07-14 00:57:48 -05:00
|
|
|
type lint_dict = hashmap<~str,lint_spec>;
|
2012-04-12 19:30:52 -05:00
|
|
|
|
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-07-14 00:57:48 -05:00
|
|
|
(~"ctypes",
|
2012-04-12 19:30:52 -05:00
|
|
|
@{lint: ctypes,
|
2012-07-14 00:57:48 -05:00
|
|
|
desc: ~"proper use of core::libc types in foreign modules",
|
2012-04-12 19:30:52 -05:00
|
|
|
default: warn}),
|
|
|
|
|
2012-07-14 00:57:48 -05:00
|
|
|
(~"unused_imports",
|
2012-04-12 19:30:52 -05:00
|
|
|
@{lint: unused_imports,
|
2012-07-14 00:57:48 -05:00
|
|
|
desc: ~"imports that are never used",
|
Nomenclature fixes in the lint checker. Fewer double-negatives.
New style is allow(foo), warn(foo), deny(foo) and forbid(foo),
mirrored by -A foo, -W foo, -D foo and -F foo on command line.
These replace -W no-foo, -W foo, -W err-foo, respectively.
Forbid is new, and means "deny, and you can't override it".
2012-07-26 19:08:21 -05:00
|
|
|
default: allow}),
|
2012-04-19 20:04:41 -05:00
|
|
|
|
2012-07-14 00:57:48 -05:00
|
|
|
(~"while_true",
|
2012-04-19 20:04:41 -05:00
|
|
|
@{lint: while_true,
|
2012-07-14 00:57:48 -05:00
|
|
|
desc: ~"suggest using loop { } instead of while(true) { }",
|
2012-04-26 15:47:13 -05:00
|
|
|
default: warn}),
|
|
|
|
|
2012-07-14 00:57:48 -05:00
|
|
|
(~"path_statement",
|
2012-04-26 15:47:13 -05:00
|
|
|
@{lint: path_statement,
|
2012-07-14 00:57:48 -05:00
|
|
|
desc: ~"path statements with no effect",
|
2012-05-01 14:58:07 -05:00
|
|
|
default: warn}),
|
|
|
|
|
Nomenclature fixes in the lint checker. Fewer double-negatives.
New style is allow(foo), warn(foo), deny(foo) and forbid(foo),
mirrored by -A foo, -W foo, -D foo and -F foo on command line.
These replace -W no-foo, -W foo, -W err-foo, respectively.
Forbid is new, and means "deny, and you can't override it".
2012-07-26 19:08:21 -05:00
|
|
|
(~"unrecognized_lint",
|
|
|
|
@{lint: unrecognized_lint,
|
|
|
|
desc: ~"unrecognized lint attribute",
|
2012-05-29 18:22:22 -05:00
|
|
|
default: warn}),
|
|
|
|
|
2012-07-14 00:57:48 -05:00
|
|
|
(~"non_implicitly_copyable_typarams",
|
2012-05-29 18:22:22 -05:00
|
|
|
@{lint: non_implicitly_copyable_typarams,
|
2012-07-14 00:57:48 -05:00
|
|
|
desc: ~"passing non implicitly copyable types as copy type params",
|
2012-06-04 20:34:11 -05:00
|
|
|
default: warn}),
|
|
|
|
|
Nomenclature fixes in the lint checker. Fewer double-negatives.
New style is allow(foo), warn(foo), deny(foo) and forbid(foo),
mirrored by -A foo, -W foo, -D foo and -F foo on command line.
These replace -W no-foo, -W foo, -W err-foo, respectively.
Forbid is new, and means "deny, and you can't override it".
2012-07-26 19:08:21 -05:00
|
|
|
(~"vecs_implicitly_copyable",
|
|
|
|
@{lint: vecs_implicitly_copyable,
|
|
|
|
desc: ~"make vecs and strs not implicitly copyable \
|
|
|
|
(only checked at top level)",
|
2012-06-04 22:44:58 -05:00
|
|
|
default: warn}),
|
|
|
|
|
2012-07-14 00:57:48 -05:00
|
|
|
(~"implicit_copies",
|
2012-06-04 22:44:58 -05:00
|
|
|
@{lint: implicit_copies,
|
2012-07-14 00:57:48 -05:00
|
|
|
desc: ~"implicit copies of non implicitly copyable data",
|
2012-07-25 08:41:56 -05:00
|
|
|
default: warn}),
|
2012-04-26 15:47:13 -05:00
|
|
|
|
2012-07-25 08:41:56 -05:00
|
|
|
(~"deprecated_mode",
|
|
|
|
@{lint: deprecated_mode,
|
|
|
|
desc: ~"warn about deprecated uses of modes",
|
2012-07-31 20:58:03 -05:00
|
|
|
default: allow}),
|
|
|
|
|
2012-08-07 09:14:44 -05:00
|
|
|
(~"deprecated_pattern",
|
|
|
|
@{lint: deprecated_pattern,
|
|
|
|
desc: ~"warn about deprecated uses of pattern bindings",
|
|
|
|
default: allow}),
|
|
|
|
|
2012-07-31 20:58:03 -05:00
|
|
|
(~"non_camel_case_types",
|
|
|
|
@{lint: non_camel_case_types,
|
|
|
|
desc: ~"types, variants and traits must have camel case names",
|
Nomenclature fixes in the lint checker. Fewer double-negatives.
New style is allow(foo), warn(foo), deny(foo) and forbid(foo),
mirrored by -A foo, -W foo, -D foo and -F foo on command line.
These replace -W no-foo, -W foo, -W err-foo, respectively.
Forbid is new, and means "deny, and you can't override it".
2012-07-26 19:08:21 -05:00
|
|
|
default: allow})
|
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>;
|
|
|
|
|
Nomenclature fixes in the lint checker. Fewer double-negatives.
New style is allow(foo), warn(foo), deny(foo) and forbid(foo),
mirrored by -A foo, -W foo, -D foo and -F foo on command line.
These replace -W no-foo, -W foo, -W err-foo, respectively.
Forbid is new, and means "deny, and you can't override it".
2012-07-26 19:08:21 -05:00
|
|
|
// settings_map maps node ids of items with non-default lint settings
|
2012-05-31 21:07:00 -05:00
|
|
|
// to their settings; default_settings contains the settings for everything
|
|
|
|
// not in the map.
|
Nomenclature fixes in the lint checker. Fewer double-negatives.
New style is allow(foo), warn(foo), deny(foo) and forbid(foo),
mirrored by -A foo, -W foo, -D foo and -F foo on command line.
These replace -W no-foo, -W foo, -W err-foo, respectively.
Forbid is new, and means "deny, and you can't override it".
2012-07-26 19:08:21 -05:00
|
|
|
type lint_settings = {
|
2012-05-31 18:13:42 -05:00
|
|
|
default_settings: lint_modes,
|
|
|
|
settings_map: lint_mode_map
|
|
|
|
};
|
|
|
|
|
Nomenclature fixes in the lint checker. Fewer double-negatives.
New style is allow(foo), warn(foo), deny(foo) and forbid(foo),
mirrored by -A foo, -W foo, -D foo and -F foo on command line.
These replace -W no-foo, -W foo, -W err-foo, respectively.
Forbid is new, and means "deny, and you can't override it".
2012-07-26 19:08:21 -05:00
|
|
|
fn mk_lint_settings() -> lint_settings {
|
2012-06-04 18:07:54 -05:00
|
|
|
{default_settings: std::smallintmap::mk(),
|
|
|
|
settings_map: int_hash()}
|
|
|
|
}
|
|
|
|
|
Nomenclature fixes in the lint checker. Fewer double-negatives.
New style is allow(foo), warn(foo), deny(foo) and forbid(foo),
mirrored by -A foo, -W foo, -D foo and -F foo on command line.
These replace -W no-foo, -W foo, -W err-foo, respectively.
Forbid is new, and means "deny, and you can't override it".
2012-07-26 19:08:21 -05:00
|
|
|
fn get_lint_level(modes: lint_modes, lint: lint) -> level {
|
2012-08-06 14:34:08 -05:00
|
|
|
match modes.find(lint as uint) {
|
2012-08-03 21:59:04 -05:00
|
|
|
some(c) => c,
|
|
|
|
none => allow
|
2012-06-01 16:25:06 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Nomenclature fixes in the lint checker. Fewer double-negatives.
New style is allow(foo), warn(foo), deny(foo) and forbid(foo),
mirrored by -A foo, -W foo, -D foo and -F foo on command line.
These replace -W no-foo, -W foo, -W err-foo, respectively.
Forbid is new, and means "deny, and you can't override it".
2012-07-26 19:08:21 -05:00
|
|
|
fn get_lint_settings_level(settings: lint_settings,
|
2012-06-04 18:07:54 -05:00
|
|
|
lint_mode: lint,
|
|
|
|
_expr_id: ast::node_id,
|
|
|
|
item_id: ast::node_id) -> level {
|
2012-08-06 14:34:08 -05:00
|
|
|
match settings.settings_map.find(item_id) {
|
2012-08-03 21:59:04 -05:00
|
|
|
some(modes) => get_lint_level(modes, lint_mode),
|
|
|
|
none => get_lint_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 {
|
2012-07-11 17:00:40 -05:00
|
|
|
std::smallintmap::smallintmap_(@{v: copy modes.v})
|
2012-05-31 18:13:42 -05:00
|
|
|
}
|
|
|
|
|
2012-07-11 17:00:40 -05:00
|
|
|
type ctxt_ = {dict: lint_dict,
|
|
|
|
curr: lint_modes,
|
|
|
|
is_default: bool,
|
|
|
|
sess: session};
|
2012-05-31 18:13:42 -05:00
|
|
|
|
2012-07-11 17:00:40 -05:00
|
|
|
enum ctxt {
|
|
|
|
ctxt_(ctxt_)
|
|
|
|
}
|
2012-01-21 11:20:22 -06:00
|
|
|
|
2012-08-07 20:10:06 -05:00
|
|
|
impl ctxt {
|
2012-04-12 19:30:52 -05:00
|
|
|
fn get_level(lint: lint) -> level {
|
Nomenclature fixes in the lint checker. Fewer double-negatives.
New style is allow(foo), warn(foo), deny(foo) and forbid(foo),
mirrored by -A foo, -W foo, -D foo and -F foo on command line.
These replace -W no-foo, -W foo, -W err-foo, respectively.
Forbid is new, and means "deny, and you can't override it".
2012-07-26 19:08:21 -05:00
|
|
|
get_lint_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) {
|
Nomenclature fixes in the lint checker. Fewer double-negatives.
New style is allow(foo), warn(foo), deny(foo) and forbid(foo),
mirrored by -A foo, -W foo, -D foo and -F foo on command line.
These replace -W no-foo, -W foo, -W err-foo, respectively.
Forbid is new, and means "deny, and you can't override it".
2012-07-26 19:08:21 -05:00
|
|
|
if level == allow {
|
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-07-14 00:57:48 -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-07-04 16:53:12 -05:00
|
|
|
/**
|
Nomenclature fixes in the lint checker. Fewer double-negatives.
New style is allow(foo), warn(foo), deny(foo) and forbid(foo),
mirrored by -A foo, -W foo, -D foo and -F foo on command line.
These replace -W no-foo, -W foo, -W err-foo, respectively.
Forbid is new, and means "deny, and you can't override it".
2012-07-26 19:08:21 -05:00
|
|
|
* Merge the lints specified by any lint attributes into the
|
2012-07-04 16:53:12 -05:00
|
|
|
* current lint context, call the provided function, then reset the
|
Nomenclature fixes in the lint checker. Fewer double-negatives.
New style is allow(foo), warn(foo), deny(foo) and forbid(foo),
mirrored by -A foo, -W foo, -D foo and -F foo on command line.
These replace -W no-foo, -W foo, -W err-foo, respectively.
Forbid is new, and means "deny, and you can't override it".
2012-07-26 19:08:21 -05:00
|
|
|
* lints in effect to their previous state.
|
2012-07-04 16:53:12 -05:00
|
|
|
*/
|
Nomenclature fixes in the lint checker. Fewer double-negatives.
New style is allow(foo), warn(foo), deny(foo) and forbid(foo),
mirrored by -A foo, -W foo, -D foo and -F foo on command line.
These replace -W no-foo, -W foo, -W err-foo, respectively.
Forbid is new, and means "deny, and you can't override it".
2012-07-26 19:08:21 -05:00
|
|
|
fn with_lint_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;
|
Nomenclature fixes in the lint checker. Fewer double-negatives.
New style is allow(foo), warn(foo), deny(foo) and forbid(foo),
mirrored by -A foo, -W foo, -D foo and -F foo on command line.
These replace -W no-foo, -W foo, -W err-foo, respectively.
Forbid is new, and means "deny, and you can't override it".
2012-07-26 19:08:21 -05:00
|
|
|
let mut triples = ~[];
|
|
|
|
|
|
|
|
for [allow, warn, deny, forbid].each |level| {
|
|
|
|
let level_name = level_to_str(level);
|
|
|
|
let metas =
|
|
|
|
attr::attr_metas(attr::find_attrs_by_name(attrs,
|
|
|
|
level_name));
|
|
|
|
for metas.each |meta| {
|
2012-08-06 14:34:08 -05:00
|
|
|
match meta.node {
|
2012-08-03 21:59:04 -05:00
|
|
|
ast::meta_list(_, metas) => {
|
Nomenclature fixes in the lint checker. Fewer double-negatives.
New style is allow(foo), warn(foo), deny(foo) and forbid(foo),
mirrored by -A foo, -W foo, -D foo and -F foo on command line.
These replace -W no-foo, -W foo, -W err-foo, respectively.
Forbid is new, and means "deny, and you can't override it".
2012-07-26 19:08:21 -05:00
|
|
|
for metas.each |meta| {
|
2012-08-06 14:34:08 -05:00
|
|
|
match meta.node {
|
2012-08-03 21:59:04 -05:00
|
|
|
ast::meta_word(lintname) => {
|
Nomenclature fixes in the lint checker. Fewer double-negatives.
New style is allow(foo), warn(foo), deny(foo) and forbid(foo),
mirrored by -A foo, -W foo, -D foo and -F foo on command line.
These replace -W no-foo, -W foo, -W err-foo, respectively.
Forbid is new, and means "deny, and you can't override it".
2012-07-26 19:08:21 -05:00
|
|
|
vec::push(triples, (meta, level, lintname));
|
2012-04-12 19:30:52 -05:00
|
|
|
}
|
2012-08-03 21:59:04 -05:00
|
|
|
_ => {
|
Nomenclature fixes in the lint checker. Fewer double-negatives.
New style is allow(foo), warn(foo), deny(foo) and forbid(foo),
mirrored by -A foo, -W foo, -D foo and -F foo on command line.
These replace -W no-foo, -W foo, -W err-foo, respectively.
Forbid is new, and means "deny, and you can't override it".
2012-07-26 19:08:21 -05:00
|
|
|
self.sess.span_err(
|
|
|
|
meta.span,
|
|
|
|
~"malformed lint attribute");
|
2012-04-12 19:30:52 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
Nomenclature fixes in the lint checker. Fewer double-negatives.
New style is allow(foo), warn(foo), deny(foo) and forbid(foo),
mirrored by -A foo, -W foo, -D foo and -F foo on command line.
These replace -W no-foo, -W foo, -W err-foo, respectively.
Forbid is new, and means "deny, and you can't override it".
2012-07-26 19:08:21 -05:00
|
|
|
}
|
2012-08-03 21:59:04 -05:00
|
|
|
_ => {
|
Nomenclature fixes in the lint checker. Fewer double-negatives.
New style is allow(foo), warn(foo), deny(foo) and forbid(foo),
mirrored by -A foo, -W foo, -D foo and -F foo on command line.
These replace -W no-foo, -W foo, -W err-foo, respectively.
Forbid is new, and means "deny, and you can't override it".
2012-07-26 19:08:21 -05:00
|
|
|
self.sess.span_err(meta.span,
|
|
|
|
~"malformed lint attribute");
|
|
|
|
}
|
2012-01-21 11:20:22 -06:00
|
|
|
}
|
Nomenclature fixes in the lint checker. Fewer double-negatives.
New style is allow(foo), warn(foo), deny(foo) and forbid(foo),
mirrored by -A foo, -W foo, -D foo and -F foo on command line.
These replace -W no-foo, -W foo, -W err-foo, respectively.
Forbid is new, and means "deny, and you can't override it".
2012-07-26 19:08:21 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for triples.each |pair| {
|
|
|
|
let (meta, level, lintname) = pair;
|
2012-08-06 14:34:08 -05:00
|
|
|
match self.dict.find(*lintname) {
|
2012-08-03 21:59:04 -05:00
|
|
|
none => {
|
Nomenclature fixes in the lint checker. Fewer double-negatives.
New style is allow(foo), warn(foo), deny(foo) and forbid(foo),
mirrored by -A foo, -W foo, -D foo and -F foo on command line.
These replace -W no-foo, -W foo, -W err-foo, respectively.
Forbid is new, and means "deny, and you can't override it".
2012-07-26 19:08:21 -05:00
|
|
|
self.span_lint(
|
|
|
|
new_ctxt.get_level(unrecognized_lint),
|
|
|
|
meta.span,
|
2012-07-30 18:01:07 -05:00
|
|
|
fmt!{"unknown `%s` attribute: `%s`",
|
|
|
|
level_to_str(level), *lintname});
|
2012-04-12 19:30:52 -05:00
|
|
|
}
|
2012-08-03 21:59:04 -05:00
|
|
|
some(lint) => {
|
Nomenclature fixes in the lint checker. Fewer double-negatives.
New style is allow(foo), warn(foo), deny(foo) and forbid(foo),
mirrored by -A foo, -W foo, -D foo and -F foo on command line.
These replace -W no-foo, -W foo, -W err-foo, respectively.
Forbid is new, and means "deny, and you can't override it".
2012-07-26 19:08:21 -05:00
|
|
|
|
|
|
|
if new_ctxt.get_level(lint.lint) == forbid &&
|
|
|
|
level != forbid {
|
|
|
|
self.span_lint(
|
|
|
|
forbid,
|
|
|
|
meta.span,
|
2012-07-30 18:01:07 -05:00
|
|
|
fmt!{"%s(%s) overruled by outer forbid(%s)",
|
Nomenclature fixes in the lint checker. Fewer double-negatives.
New style is allow(foo), warn(foo), deny(foo) and forbid(foo),
mirrored by -A foo, -W foo, -D foo and -F foo on command line.
These replace -W no-foo, -W foo, -W err-foo, respectively.
Forbid is new, and means "deny, and you can't override it".
2012-07-26 19:08:21 -05:00
|
|
|
level_to_str(level),
|
2012-07-30 18:01:07 -05:00
|
|
|
*lintname, *lintname});
|
Nomenclature fixes in the lint checker. Fewer double-negatives.
New style is allow(foo), warn(foo), deny(foo) and forbid(foo),
mirrored by -A foo, -W foo, -D foo and -F foo on command line.
These replace -W no-foo, -W foo, -W err-foo, respectively.
Forbid is new, and means "deny, and you can't override it".
2012-07-26 19:08:21 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// we do multiple unneeded copies of the
|
|
|
|
// map if many attributes are set, but
|
|
|
|
// this shouldn't actually be a problem...
|
|
|
|
|
|
|
|
let c = clone_lint_modes(new_ctxt.curr);
|
|
|
|
new_ctxt =
|
|
|
|
ctxt_({is_default: false,
|
|
|
|
curr: c,
|
|
|
|
with *new_ctxt});
|
|
|
|
new_ctxt.set_level(lint.lint, level);
|
2012-04-12 19:30:52 -05:00
|
|
|
}
|
2012-01-21 11:20:22 -06:00
|
|
|
}
|
|
|
|
}
|
2012-05-31 18:13:42 -05:00
|
|
|
f(new_ctxt);
|
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>) {
|
Nomenclature fixes in the lint checker. Fewer double-negatives.
New style is allow(foo), warn(foo), deny(foo) and forbid(foo),
mirrored by -A foo, -W foo, -D foo and -F foo on command line.
These replace -W no-foo, -W foo, -W err-foo, respectively.
Forbid is new, and means "deny, and you can't override it".
2012-07-26 19:08:21 -05:00
|
|
|
do cx.with_lint_attrs(i.attrs) |cx| {
|
2012-05-31 21:07:00 -05:00
|
|
|
if !cx.is_default {
|
Nomenclature fixes in the lint checker. Fewer double-negatives.
New style is allow(foo), warn(foo), deny(foo) and forbid(foo),
mirrored by -A foo, -W foo, -D foo and -F foo on command line.
These replace -W no-foo, -W foo, -W err-foo, respectively.
Forbid is new, and means "deny, and you can't override it".
2012-07-26 19:08:21 -05:00
|
|
|
cx.sess.lint_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) {
|
|
|
|
|
2012-07-11 17:00:40 -05:00
|
|
|
let cx = ctxt_({dict: get_lint_dict(),
|
|
|
|
curr: std::smallintmap::mk(),
|
|
|
|
is_default: true,
|
|
|
|
sess: sess});
|
2012-06-04 18:07:54 -05:00
|
|
|
|
|
|
|
// 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);
|
|
|
|
}
|
|
|
|
|
Nomenclature fixes in the lint checker. Fewer double-negatives.
New style is allow(foo), warn(foo), deny(foo) and forbid(foo),
mirrored by -A foo, -W foo, -D foo and -F foo on command line.
These replace -W no-foo, -W foo, -W err-foo, respectively.
Forbid is new, and means "deny, and you can't override it".
2012-07-26 19:08:21 -05:00
|
|
|
do cx.with_lint_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| {
|
Nomenclature fixes in the lint checker. Fewer double-negatives.
New style is allow(foo), warn(foo), deny(foo) and forbid(foo),
mirrored by -A foo, -W foo, -D foo and -F foo on command line.
These replace -W no-foo, -W foo, -W err-foo, respectively.
Forbid is new, and means "deny, and you can't override it".
2012-07-26 19:08:21 -05:00
|
|
|
sess.lint_settings.default_settings.insert(k, v);
|
2012-06-04 18:07:54 -05:00
|
|
|
}
|
|
|
|
|
2012-07-11 17:00:40 -05:00
|
|
|
let cx = ctxt_({is_default: true with *cx});
|
2012-06-04 18:07:54 -05:00
|
|
|
|
|
|
|
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);
|
2012-07-31 20:58:03 -05:00
|
|
|
check_item_non_camel_case_types(cx, i);
|
2012-06-04 18:07:54 -05:00
|
|
|
}
|
|
|
|
|
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) {
|
2012-08-06 14:34:08 -05:00
|
|
|
match e.node {
|
2012-08-03 21:59:04 -05:00
|
|
|
ast::expr_while(cond, _) => {
|
2012-08-06 14:34:08 -05:00
|
|
|
match cond.node {
|
2012-08-03 21:59:04 -05:00
|
|
|
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,
|
2012-07-14 00:57:48 -05:00
|
|
|
~"denote infinite loops with loop { ... }");
|
2012-04-19 20:04:41 -05:00
|
|
|
}
|
2012-08-03 21:59:04 -05:00
|
|
|
_ => ()
|
2012-04-19 20:04:41 -05:00
|
|
|
}
|
|
|
|
}
|
2012-08-03 21:59:04 -05:00
|
|
|
_ => ()
|
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-08-06 14:34:08 -05:00
|
|
|
match ty.node {
|
2012-08-03 21:59:04 -05:00
|
|
|
ast::ty_path(_, id) => {
|
2012-08-06 14:34:08 -05:00
|
|
|
match cx.def_map.get(id) {
|
2012-08-03 21:59:04 -05: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-14 00:57:48 -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
|
|
|
}
|
2012-08-03 21:59:04 -05: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-14 00:57:48 -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-08-03 21:59:04 -05:00
|
|
|
_ => ()
|
2012-02-06 08:29:56 -06:00
|
|
|
}
|
2012-01-19 02:50:51 -06:00
|
|
|
}
|
2012-08-03 21:59:04 -05:00
|
|
|
_ => ()
|
2012-01-19 02:50:51 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-06 14:34:08 -05:00
|
|
|
match it.node {
|
2012-06-26 18:18:37 -05:00
|
|
|
ast::item_foreign_mod(nmod) if attr::foreign_abi(it.attrs) !=
|
2012-08-14 18:54:13 -05:00
|
|
|
either::Right(ast::foreign_abi_rust_intrinsic) => {
|
2012-06-30 18:19:07 -05:00
|
|
|
for nmod.items.each |ni| {
|
2012-08-06 14:34:08 -05:00
|
|
|
match ni.node {
|
2012-08-03 21:59:04 -05:00
|
|
|
ast::foreign_item_fn(decl, tps) => {
|
2012-06-26 18:18:37 -05:00
|
|
|
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
|
|
|
}
|
2012-08-03 21:59:04 -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) {
|
2012-08-06 14:34:08 -05:00
|
|
|
match s.node {
|
2012-07-03 19:30:25 -05:00
|
|
|
ast::stmt_semi(@{id: id,
|
2012-07-11 16:31:35 -05:00
|
|
|
callee_id: _,
|
2012-04-26 15:47:13 -05:00
|
|
|
node: ast::expr_path(@path),
|
2012-08-03 21:59:04 -05:00
|
|
|
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-07-14 00:57:48 -05:00
|
|
|
~"path statement with no effect");
|
2012-04-26 15:47:13 -05:00
|
|
|
}
|
2012-08-03 21:59:04 -05:00
|
|
|
_ => ()
|
2012-04-26 15:47:13 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
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-07-31 20:58:03 -05:00
|
|
|
fn check_item_non_camel_case_types(cx: ty::ctxt, it: @ast::item) {
|
|
|
|
fn is_camel_case(ident: ast::ident) -> bool {
|
|
|
|
assert ident.is_not_empty();
|
2012-08-08 17:05:49 -05:00
|
|
|
let ident = ident_without_trailing_underscores(ident);
|
|
|
|
char::is_uppercase(str::char_at(ident, 0)) &&
|
2012-07-31 20:58:03 -05:00
|
|
|
!ident.contains_char('_')
|
|
|
|
}
|
|
|
|
|
2012-08-08 17:05:49 -05:00
|
|
|
fn ident_without_trailing_underscores(ident: ast::ident) -> ~str {
|
|
|
|
match str::rfind(*ident, |c| c != '_') {
|
|
|
|
some(idx) => (*ident).slice(0, idx + 1),
|
|
|
|
none => {
|
|
|
|
// all underscores
|
|
|
|
*ident
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-31 20:58:03 -05:00
|
|
|
fn check_case(cx: ty::ctxt, ident: ast::ident,
|
|
|
|
expr_id: ast::node_id, item_id: ast::node_id,
|
|
|
|
span: span) {
|
|
|
|
if !is_camel_case(ident) {
|
|
|
|
cx.sess.span_lint(
|
|
|
|
non_camel_case_types, expr_id, item_id, span,
|
|
|
|
~"type, variant, or trait must be camel case");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-06 14:34:08 -05:00
|
|
|
match it.node {
|
2012-07-31 20:58:03 -05:00
|
|
|
ast::item_ty(*) | ast::item_class(*) |
|
2012-08-09 00:21:47 -05:00
|
|
|
ast::item_trait(*) => {
|
2012-07-31 20:58:03 -05:00
|
|
|
check_case(cx, it.ident, it.id, it.id, it.span)
|
|
|
|
}
|
2012-08-08 19:14:25 -05:00
|
|
|
ast::item_enum(enum_definition, _) => {
|
2012-07-31 20:58:03 -05:00
|
|
|
check_case(cx, it.ident, it.id, it.id, it.span);
|
2012-08-08 19:14:25 -05:00
|
|
|
for enum_definition.variants.each |variant| {
|
2012-07-31 20:58:03 -05:00
|
|
|
check_case(cx, variant.node.name,
|
|
|
|
variant.node.id, it.id, variant.span);
|
|
|
|
}
|
|
|
|
}
|
2012-08-03 21:59:04 -05:00
|
|
|
_ => ()
|
2012-07-31 20:58:03 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-07 09:14:44 -05:00
|
|
|
fn check_pat(tcx: ty::ctxt, pat: @ast::pat) {
|
|
|
|
debug!{"lint check_pat pat=%s", pat_to_str(pat)};
|
|
|
|
|
|
|
|
do pat_bindings(tcx.def_map, pat) |binding_mode, id, span, path| {
|
|
|
|
match binding_mode {
|
|
|
|
ast::bind_by_ref(_) | ast::bind_by_value => {}
|
|
|
|
ast::bind_by_implicit_ref => {
|
|
|
|
let pat_ty = ty::node_id_to_type(tcx, id);
|
|
|
|
let kind = ty::type_kind(tcx, pat_ty);
|
|
|
|
if !ty::kind_is_safe_for_default_mode(kind) {
|
|
|
|
tcx.sess.span_lint(
|
|
|
|
deprecated_pattern, id, id,
|
|
|
|
span,
|
|
|
|
fmt!{"binding `%s` should use ref or copy mode",
|
|
|
|
*path_to_ident(path)});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-25 08:41:56 -05:00
|
|
|
fn check_fn(tcx: ty::ctxt, fk: visit::fn_kind, decl: ast::fn_decl,
|
|
|
|
_body: ast::blk, span: span, id: ast::node_id) {
|
2012-07-30 18:01:07 -05:00
|
|
|
debug!{"lint check_fn fk=%? id=%?", fk, id};
|
2012-07-25 12:19:28 -05:00
|
|
|
|
|
|
|
// don't complain about blocks, since they tend to get their modes
|
|
|
|
// specified from the outside
|
2012-08-06 14:34:08 -05:00
|
|
|
match fk {
|
2012-08-01 19:30:05 -05:00
|
|
|
visit::fk_fn_block(*) => { return; }
|
2012-07-25 12:19:28 -05:00
|
|
|
_ => {}
|
|
|
|
}
|
|
|
|
|
2012-07-25 08:41:56 -05:00
|
|
|
let fn_ty = ty::node_id_to_type(tcx, id);
|
2012-08-06 14:34:08 -05:00
|
|
|
match check ty::get(fn_ty).struct {
|
2012-08-03 21:59:04 -05:00
|
|
|
ty::ty_fn(fn_ty) => {
|
2012-07-25 08:41:56 -05:00
|
|
|
let mut counter = 0;
|
|
|
|
do vec::iter2(fn_ty.inputs, decl.inputs) |arg_ty, arg_ast| {
|
|
|
|
counter += 1;
|
2012-07-30 18:01:07 -05:00
|
|
|
debug!{"arg %d, ty=%s, mode=%s",
|
2012-07-25 08:41:56 -05:00
|
|
|
counter,
|
|
|
|
ty_to_str(tcx, arg_ty.ty),
|
2012-07-30 18:01:07 -05:00
|
|
|
mode_to_str(arg_ast.mode)};
|
2012-08-06 14:34:08 -05:00
|
|
|
match arg_ast.mode {
|
2012-07-25 08:41:56 -05:00
|
|
|
ast::expl(ast::by_copy) => {
|
|
|
|
/* always allow by-copy */
|
|
|
|
}
|
|
|
|
|
|
|
|
ast::expl(_) => {
|
|
|
|
tcx.sess.span_lint(
|
|
|
|
deprecated_mode, id, id,
|
|
|
|
span,
|
2012-07-30 18:01:07 -05:00
|
|
|
fmt!{"argument %d uses an explicit mode", counter});
|
2012-07-25 08:41:56 -05:00
|
|
|
}
|
|
|
|
|
2012-08-03 21:59:04 -05:00
|
|
|
ast::infer(_) => {
|
2012-07-25 08:41:56 -05:00
|
|
|
let kind = ty::type_kind(tcx, arg_ty.ty);
|
|
|
|
if !ty::kind_is_safe_for_default_mode(kind) {
|
|
|
|
tcx.sess.span_lint(
|
|
|
|
deprecated_mode, id, id,
|
|
|
|
span,
|
2012-07-30 18:01:07 -05:00
|
|
|
fmt!{"argument %d uses the default mode \
|
2012-07-25 08:41:56 -05:00
|
|
|
but shouldn't",
|
2012-07-30 18:01:07 -05:00
|
|
|
counter});
|
2012-07-25 08:41:56 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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(@{
|
2012-08-07 09:14:44 -05:00
|
|
|
visit_item: |it|
|
|
|
|
check_item(it, tcx),
|
|
|
|
visit_fn: |fk, decl, body, span, id|
|
|
|
|
check_fn(tcx, fk, decl, body, span, id),
|
|
|
|
visit_pat: |pat|
|
|
|
|
check_pat(tcx, pat),
|
2012-06-04 18:07:54 -05:00
|
|
|
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:
|
|
|
|
//
|