2012-12-03 18:48:01 -06:00
|
|
|
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
|
|
|
|
// file at the top-level directory of this distribution and at
|
|
|
|
// http://rust-lang.org/COPYRIGHT.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
|
|
// option. This file may not be copied, modified, or distributed
|
|
|
|
// except according to those terms.
|
|
|
|
|
2013-01-08 21:37:25 -06:00
|
|
|
use core::prelude::*;
|
2013-01-07 16:16:52 -06:00
|
|
|
|
2012-10-15 16:56:42 -05:00
|
|
|
use driver::session::Session;
|
2012-12-23 16:41:37 -06:00
|
|
|
use driver::session;
|
2012-09-04 13:54:36 -05:00
|
|
|
use middle::ty;
|
|
|
|
use util::ppaux::{ty_to_str};
|
2012-12-23 16:41:37 -06:00
|
|
|
|
|
|
|
use core::char;
|
|
|
|
use core::cmp;
|
|
|
|
use core::either;
|
|
|
|
use core::i8;
|
|
|
|
use core::i16;
|
|
|
|
use core::i32;
|
|
|
|
use core::i64;
|
|
|
|
use core::int;
|
|
|
|
use core::str;
|
|
|
|
use core::u8;
|
|
|
|
use core::u16;
|
|
|
|
use core::u32;
|
|
|
|
use core::u64;
|
|
|
|
use core::uint;
|
|
|
|
use core::vec;
|
2013-02-01 01:13:36 -06:00
|
|
|
use std::oldmap::{Map, HashMap};
|
|
|
|
use std::oldmap;
|
2013-02-22 23:37:37 -06:00
|
|
|
use std::smallintmap::SmallIntMap;
|
2012-12-23 16:41:37 -06:00
|
|
|
use syntax::attr;
|
|
|
|
use syntax::codemap::span;
|
2013-01-30 11:56:33 -06:00
|
|
|
use syntax::codemap;
|
2012-09-04 13:54:36 -05:00
|
|
|
use syntax::print::pprust::{expr_to_str, mode_to_str, pat_to_str};
|
2012-12-23 16:41:37 -06:00
|
|
|
use syntax::{ast, ast_util, visit};
|
|
|
|
|
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
|
|
|
|
2013-01-30 15:44:24 -06:00
|
|
|
#[deriving_eq]
|
|
|
|
pub 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-08-24 13:04:07 -05:00
|
|
|
non_camel_case_types,
|
2012-10-24 11:21:57 -05:00
|
|
|
type_limits,
|
2012-12-14 21:07:20 -06:00
|
|
|
default_methods,
|
2013-02-25 13:34:16 -06:00
|
|
|
deprecated_mutable_fields,
|
2013-03-08 18:21:58 -06:00
|
|
|
deprecated_drop,
|
2013-03-08 19:44:37 -06:00
|
|
|
foreign_mode,
|
2012-08-24 13:04:07 -05:00
|
|
|
|
2012-08-28 20:25:41 -05:00
|
|
|
managed_heap_memory,
|
|
|
|
owned_heap_memory,
|
|
|
|
heap_memory,
|
|
|
|
|
2012-09-18 17:52:21 -05:00
|
|
|
legacy_modes,
|
|
|
|
|
2012-08-24 13:04:07 -05:00
|
|
|
// FIXME(#3266)--make liveness warnings lintable
|
|
|
|
// unused_variable,
|
|
|
|
// dead_assignment
|
2012-01-19 02:50:51 -06:00
|
|
|
}
|
|
|
|
|
2013-03-14 13:22:51 -05:00
|
|
|
pub fn level_to_str(lv: level) -> &'static str {
|
2012-08-06 14:34:08 -05:00
|
|
|
match lv {
|
2013-01-05 21:33:37 -06: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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-19 01:40:42 -06:00
|
|
|
#[deriving_eq]
|
2013-01-30 15:44:24 -06:00
|
|
|
pub 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
|
|
|
}
|
|
|
|
|
2013-02-19 01:40:42 -06:00
|
|
|
struct LintSpec {
|
|
|
|
lint: lint,
|
2013-03-14 13:22:51 -05:00
|
|
|
desc: &'static str,
|
2013-02-19 01:40:42 -06:00
|
|
|
default: level
|
2012-09-19 20:00:26 -05:00
|
|
|
}
|
2012-08-27 18:26:35 -05:00
|
|
|
|
2013-02-20 18:41:21 -06:00
|
|
|
pub type LintDict = HashMap<@~str, @LintSpec>;
|
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
|
|
|
|
*/
|
2013-02-19 01:40:42 -06:00
|
|
|
pub fn get_lint_dict() -> LintDict {
|
2012-06-29 18:26:56 -05:00
|
|
|
let v = ~[
|
2013-02-15 08:48:17 -06:00
|
|
|
(@~"ctypes",
|
2013-02-19 01:40:42 -06:00
|
|
|
@LintSpec {
|
|
|
|
lint: ctypes,
|
|
|
|
desc: "proper use of core::libc types in foreign modules",
|
|
|
|
default: warn
|
|
|
|
}),
|
2012-04-12 19:30:52 -05:00
|
|
|
|
2013-02-15 08:48:17 -06:00
|
|
|
(@~"unused_imports",
|
2013-02-19 01:40:42 -06:00
|
|
|
@LintSpec {
|
2013-02-19 02:14:56 -06:00
|
|
|
lint: unused_imports,
|
2013-02-19 01:40:42 -06:00
|
|
|
desc: "imports that are never used",
|
2013-02-26 23:09:41 -06:00
|
|
|
default: warn
|
2013-02-19 01:40:42 -06:00
|
|
|
}),
|
2012-04-19 20:04:41 -05:00
|
|
|
|
2013-02-15 08:48:17 -06:00
|
|
|
(@~"while_true",
|
2013-02-19 01:40:42 -06:00
|
|
|
@LintSpec {
|
2013-02-19 02:14:56 -06:00
|
|
|
lint: while_true,
|
2013-02-19 01:40:42 -06:00
|
|
|
desc: "suggest using loop { } instead of while(true) { }",
|
|
|
|
default: warn
|
|
|
|
}),
|
2012-04-26 15:47:13 -05:00
|
|
|
|
2013-02-15 08:48:17 -06:00
|
|
|
(@~"path_statement",
|
2013-02-19 01:40:42 -06:00
|
|
|
@LintSpec {
|
2013-02-19 02:14:56 -06:00
|
|
|
lint: path_statement,
|
2013-02-19 01:40:42 -06:00
|
|
|
desc: "path statements with no effect",
|
|
|
|
default: warn
|
|
|
|
}),
|
2012-05-01 14:58:07 -05:00
|
|
|
|
2013-02-15 08:48:17 -06:00
|
|
|
(@~"unrecognized_lint",
|
2013-02-19 01:40:42 -06:00
|
|
|
@LintSpec {
|
2013-02-19 02:14:56 -06:00
|
|
|
lint: unrecognized_lint,
|
2013-02-19 01:40:42 -06:00
|
|
|
desc: "unrecognized lint attribute",
|
|
|
|
default: warn
|
|
|
|
}),
|
2012-05-29 18:22:22 -05:00
|
|
|
|
2013-02-15 08:48:17 -06:00
|
|
|
(@~"non_implicitly_copyable_typarams",
|
2013-02-19 01:40:42 -06:00
|
|
|
@LintSpec {
|
2013-02-19 02:14:56 -06:00
|
|
|
lint: non_implicitly_copyable_typarams,
|
2013-02-19 01:40:42 -06:00
|
|
|
desc: "passing non implicitly copyable types as copy type params",
|
|
|
|
default: warn
|
|
|
|
}),
|
2012-06-04 20:34:11 -05:00
|
|
|
|
2013-02-15 08:48:17 -06:00
|
|
|
(@~"vecs_implicitly_copyable",
|
2013-02-19 01:40:42 -06:00
|
|
|
@LintSpec {
|
2013-02-19 02:14:56 -06:00
|
|
|
lint: vecs_implicitly_copyable,
|
2013-02-19 01:40:42 -06:00
|
|
|
desc: "make vecs and strs not implicitly copyable \
|
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
|
|
|
(only checked at top level)",
|
2013-02-19 01:40:42 -06:00
|
|
|
default: warn
|
|
|
|
}),
|
2012-06-04 22:44:58 -05:00
|
|
|
|
2013-02-15 08:48:17 -06:00
|
|
|
(@~"implicit_copies",
|
2013-02-19 01:40:42 -06:00
|
|
|
@LintSpec {
|
2013-02-19 02:14:56 -06:00
|
|
|
lint: implicit_copies,
|
2013-02-19 01:40:42 -06:00
|
|
|
desc: "implicit copies of non implicitly copyable data",
|
|
|
|
default: warn
|
|
|
|
}),
|
2012-04-26 15:47:13 -05:00
|
|
|
|
2013-02-15 08:48:17 -06:00
|
|
|
(@~"deprecated_mode",
|
2013-02-19 01:40:42 -06:00
|
|
|
@LintSpec {
|
2013-02-19 02:14:56 -06:00
|
|
|
lint: deprecated_mode,
|
2013-02-19 01:40:42 -06:00
|
|
|
desc: "warn about deprecated uses of modes",
|
|
|
|
default: warn
|
|
|
|
}),
|
2012-07-31 20:58:03 -05:00
|
|
|
|
2013-03-08 19:44:37 -06:00
|
|
|
(@~"foreign_mode",
|
|
|
|
@LintSpec {
|
|
|
|
lint: foreign_mode,
|
|
|
|
desc: "warn about deprecated uses of modes in foreign fns",
|
|
|
|
default: warn
|
|
|
|
}),
|
|
|
|
|
2013-02-15 08:48:17 -06:00
|
|
|
(@~"deprecated_pattern",
|
2013-02-19 01:40:42 -06:00
|
|
|
@LintSpec {
|
2013-02-19 02:14:56 -06:00
|
|
|
lint: deprecated_pattern,
|
2013-02-19 01:40:42 -06:00
|
|
|
desc: "warn about deprecated uses of pattern bindings",
|
|
|
|
default: allow
|
|
|
|
}),
|
2012-08-07 09:14:44 -05:00
|
|
|
|
2013-02-15 08:48:17 -06:00
|
|
|
(@~"non_camel_case_types",
|
2013-02-19 01:40:42 -06:00
|
|
|
@LintSpec {
|
2013-02-19 02:14:56 -06:00
|
|
|
lint: non_camel_case_types,
|
2013-02-19 01:40:42 -06:00
|
|
|
desc: "types, variants and traits should have camel case names",
|
|
|
|
default: allow
|
|
|
|
}),
|
2012-08-24 13:04:07 -05:00
|
|
|
|
2013-02-15 08:48:17 -06:00
|
|
|
(@~"managed_heap_memory",
|
2013-02-19 01:40:42 -06:00
|
|
|
@LintSpec {
|
2013-02-19 02:14:56 -06:00
|
|
|
lint: managed_heap_memory,
|
2013-02-19 01:40:42 -06:00
|
|
|
desc: "use of managed (@ type) heap memory",
|
|
|
|
default: allow
|
|
|
|
}),
|
2012-08-28 20:25:41 -05:00
|
|
|
|
2013-02-15 08:48:17 -06:00
|
|
|
(@~"owned_heap_memory",
|
2013-02-19 01:40:42 -06:00
|
|
|
@LintSpec {
|
2013-02-19 02:14:56 -06:00
|
|
|
lint: owned_heap_memory,
|
2013-02-19 01:40:42 -06:00
|
|
|
desc: "use of owned (~ type) heap memory",
|
|
|
|
default: allow
|
|
|
|
}),
|
2012-08-28 20:25:41 -05:00
|
|
|
|
2013-02-15 08:48:17 -06:00
|
|
|
(@~"heap_memory",
|
2013-02-19 01:40:42 -06:00
|
|
|
@LintSpec {
|
2013-02-19 02:14:56 -06:00
|
|
|
lint: heap_memory,
|
2013-02-19 01:40:42 -06:00
|
|
|
desc: "use of any (~ type or @ type) heap memory",
|
|
|
|
default: allow
|
|
|
|
}),
|
2012-08-28 20:25:41 -05:00
|
|
|
|
2013-02-15 08:48:17 -06:00
|
|
|
(@~"legacy modes",
|
2013-02-19 01:40:42 -06:00
|
|
|
@LintSpec {
|
2013-02-19 02:14:56 -06:00
|
|
|
lint: legacy_modes,
|
2013-02-19 01:40:42 -06:00
|
|
|
desc: "allow legacy modes",
|
|
|
|
default: forbid
|
|
|
|
}),
|
2012-09-18 17:52:21 -05:00
|
|
|
|
2013-02-15 08:48:17 -06:00
|
|
|
(@~"type_limits",
|
2013-02-19 01:40:42 -06:00
|
|
|
@LintSpec {
|
2013-02-19 02:14:56 -06:00
|
|
|
lint: type_limits,
|
2013-02-19 01:40:42 -06:00
|
|
|
desc: "comparisons made useless by limits of the types involved",
|
|
|
|
default: warn
|
|
|
|
}),
|
2012-12-14 21:07:20 -06:00
|
|
|
|
2013-02-15 08:48:17 -06:00
|
|
|
(@~"default_methods",
|
2013-02-19 01:40:42 -06:00
|
|
|
@LintSpec {
|
2013-02-19 02:14:56 -06:00
|
|
|
lint: default_methods,
|
2013-02-19 01:40:42 -06:00
|
|
|
desc: "allow default methods",
|
|
|
|
default: deny
|
|
|
|
}),
|
2012-10-24 10:20:54 -05:00
|
|
|
|
2013-02-25 13:34:16 -06:00
|
|
|
(@~"deprecated_mutable_fields",
|
|
|
|
@LintSpec {
|
|
|
|
lint: deprecated_mutable_fields,
|
|
|
|
desc: "deprecated mutable fields in structures",
|
|
|
|
default: deny
|
|
|
|
}),
|
|
|
|
|
2013-03-08 18:21:58 -06:00
|
|
|
(@~"deprecated_drop",
|
|
|
|
@LintSpec {
|
|
|
|
lint: deprecated_drop,
|
|
|
|
desc: "deprecated \"drop\" notation for the destructor",
|
|
|
|
default: deny
|
|
|
|
}),
|
|
|
|
|
2012-08-24 13:04:07 -05:00
|
|
|
/* FIXME(#3266)--make liveness warnings lintable
|
2013-02-15 08:48:17 -06:00
|
|
|
(@~"unused_variable",
|
2013-02-19 01:40:42 -06:00
|
|
|
@LintSpec {
|
2013-02-19 02:14:56 -06:00
|
|
|
lint: unused_variable,
|
2013-02-19 01:40:42 -06:00
|
|
|
desc: "detect variables which are not used in any way",
|
|
|
|
default: warn
|
|
|
|
}),
|
2012-08-24 13:04:07 -05:00
|
|
|
|
2013-02-15 08:48:17 -06:00
|
|
|
(@~"dead_assignment",
|
2013-02-19 01:40:42 -06:00
|
|
|
@LintSpec {
|
2013-02-19 02:14:56 -06:00
|
|
|
lint: dead_assignment,
|
2013-02-19 01:40:42 -06:00
|
|
|
desc: "detect assignments that will never be read",
|
|
|
|
default: warn
|
|
|
|
}),
|
2012-08-24 13:04:07 -05:00
|
|
|
*/
|
2012-06-29 18:26:56 -05:00
|
|
|
];
|
2013-02-01 01:13:36 -06:00
|
|
|
oldmap::hash_from_vec(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.
|
2013-02-22 23:37:37 -06:00
|
|
|
type LintModes = @mut SmallIntMap<level>;
|
2013-02-19 01:40:42 -06:00
|
|
|
type LintModeMap = HashMap<ast::node_id, LintModes>;
|
2012-05-31 18:13:42 -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
|
|
|
// 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.
|
2013-02-19 01:40:42 -06:00
|
|
|
pub struct LintSettings {
|
|
|
|
default_settings: LintModes,
|
|
|
|
settings_map: LintModeMap
|
2012-06-04 18:07:54 -05:00
|
|
|
}
|
|
|
|
|
2013-02-19 01:40:42 -06:00
|
|
|
pub fn mk_lint_settings() -> LintSettings {
|
|
|
|
LintSettings {
|
2013-02-22 23:37:37 -06:00
|
|
|
default_settings: @mut SmallIntMap::new(),
|
2013-02-19 01:40:42 -06:00
|
|
|
settings_map: HashMap()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn get_lint_level(modes: LintModes, lint: lint) -> level {
|
2013-02-22 23:37:37 -06:00
|
|
|
match modes.find(&(lint as uint)) {
|
|
|
|
Some(&c) => c,
|
2012-08-20 14:23:37 -05:00
|
|
|
None => allow
|
2012-06-01 16:25:06 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-19 01:40:42 -06:00
|
|
|
pub fn get_lint_settings_level(settings: LintSettings,
|
2013-01-30 15:44:24 -06:00
|
|
|
lint_mode: lint,
|
|
|
|
_expr_id: ast::node_id,
|
|
|
|
item_id: ast::node_id)
|
|
|
|
-> level {
|
2013-02-05 21:41:45 -06:00
|
|
|
match settings.settings_map.find(&item_id) {
|
2012-08-20 14:23:37 -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...
|
2013-02-19 01:40:42 -06:00
|
|
|
fn clone_lint_modes(modes: LintModes) -> LintModes {
|
2013-02-22 23:37:37 -06:00
|
|
|
@mut (copy *modes)
|
2012-05-31 18:13:42 -05:00
|
|
|
}
|
|
|
|
|
2013-02-19 01:40:42 -06:00
|
|
|
struct Context {
|
|
|
|
dict: LintDict,
|
|
|
|
curr: LintModes,
|
|
|
|
is_default: bool,
|
|
|
|
sess: Session
|
2012-07-11 17:00:40 -05:00
|
|
|
}
|
2012-01-21 11:20:22 -06:00
|
|
|
|
2013-02-26 19:47:41 -06:00
|
|
|
pub impl Context {
|
2013-02-19 01:40:42 -06:00
|
|
|
fn get_level(&self, 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
|
|
|
}
|
|
|
|
|
2013-02-19 01:40:42 -06:00
|
|
|
fn set_level(&self, 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 {
|
2013-02-22 23:37:37 -06: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
|
|
|
}
|
|
|
|
|
2013-02-19 01:40:42 -06:00
|
|
|
fn span_lint(&self, 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
|
|
|
*/
|
2013-03-07 16:38:38 -06:00
|
|
|
fn with_lint_attrs(&self, attrs: ~[ast::attribute], f: &fn(Context)) {
|
2012-01-21 11:20:22 -06:00
|
|
|
|
2013-02-19 01:40:42 -06: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| {
|
2012-09-19 18:55:01 -05:00
|
|
|
let level_name = level_to_str(*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
|
|
|
let metas =
|
2013-01-10 01:17:57 -06:00
|
|
|
attr::attr_metas(attr::find_attrs_by_name(attrs, level_name));
|
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| {
|
2013-01-07 16:16:52 -06:00
|
|
|
match /*bad*/copy 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-12-04 12:50:00 -06:00
|
|
|
ast::meta_word(ref lintname) => {
|
2013-01-07 16:16:52 -06:00
|
|
|
triples.push((*meta,
|
|
|
|
*level,
|
|
|
|
/*bad*/copy *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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-15 08:48:17 -06:00
|
|
|
for triples.each |triple| {
|
|
|
|
// FIXME(#3874): it would be nicer to write this...
|
|
|
|
// let (meta, level, lintname) = /*bad*/copy *pair;
|
|
|
|
let (meta, level, lintname) = match *triple {
|
|
|
|
(ref meta, level, lintname) => (meta, level, lintname)
|
|
|
|
};
|
|
|
|
|
|
|
|
match self.dict.find(&lintname) {
|
2012-08-20 14:23:37 -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-08-22 19:24:52 -05:00
|
|
|
fmt!("unknown `%s` attribute: `%s`",
|
2013-02-14 09:34:21 -06:00
|
|
|
level_to_str(level), *lintname));
|
2012-04-12 19:30:52 -05:00
|
|
|
}
|
2012-08-20 14:23:37 -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-08-22 19:24:52 -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),
|
2013-02-14 09:34:21 -06: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);
|
2013-02-19 01:40:42 -06:00
|
|
|
new_ctxt = Context {
|
|
|
|
is_default: false,
|
|
|
|
curr: c,
|
|
|
|
.. new_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
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-02-19 01:40:42 -06:00
|
|
|
fn build_settings_item(i: @ast::item, &&cx: Context, v: visit::vt<Context>) {
|
2013-01-07 16:16:52 -06:00
|
|
|
do cx.with_lint_attrs(/*bad*/copy 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
|
|
|
|
2013-01-30 15:44:24 -06:00
|
|
|
pub fn build_settings_crate(sess: session::Session, crate: @ast::crate) {
|
2013-02-19 01:40:42 -06:00
|
|
|
let cx = Context {
|
|
|
|
dict: get_lint_dict(),
|
2013-02-22 23:37:37 -06:00
|
|
|
curr: @mut SmallIntMap::new(),
|
2013-02-19 01:40:42 -06:00
|
|
|
is_default: true,
|
|
|
|
sess: sess
|
|
|
|
};
|
2012-06-04 18:07:54 -05:00
|
|
|
|
|
|
|
// Install defaults.
|
2013-02-08 16:08:02 -06:00
|
|
|
for cx.dict.each_value |&spec| {
|
2013-02-02 13:47:41 -06:00
|
|
|
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-09-19 18:55:01 -05:00
|
|
|
let (lint,level) = *pair;
|
2012-06-04 18:07:54 -05:00
|
|
|
cx.set_level(lint, level);
|
|
|
|
}
|
|
|
|
|
2013-01-07 16:16:52 -06:00
|
|
|
do cx.with_lint_attrs(/*bad*/copy crate.node.attrs) |cx| {
|
2012-06-04 18:07:54 -05:00
|
|
|
// Copy out the default settings
|
2013-02-22 23:37:37 -06: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
|
|
|
}
|
|
|
|
|
2013-02-19 01:40:42 -06:00
|
|
|
let cx = Context {
|
|
|
|
is_default: true,
|
|
|
|
.. cx
|
|
|
|
};
|
2012-06-04 18:07:54 -05:00
|
|
|
|
2013-01-08 16:00:45 -06:00
|
|
|
let visit = visit::mk_vt(@visit::Visitor {
|
2012-09-04 15:29:32 -05:00
|
|
|
visit_item: build_settings_item,
|
|
|
|
.. *visit::default_visitor()
|
2012-06-04 18:07:54 -05:00
|
|
|
});
|
|
|
|
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-08-28 20:25:41 -05:00
|
|
|
check_item_heap(cx, i);
|
2012-09-25 19:02:22 -05:00
|
|
|
check_item_deprecated_modes(cx, i);
|
2012-10-24 11:21:57 -05:00
|
|
|
check_item_type_limits(cx, i);
|
2012-12-14 21:07:20 -06:00
|
|
|
check_item_default_methods(cx, i);
|
2013-02-25 13:34:16 -06:00
|
|
|
check_item_deprecated_mutable_fields(cx, i);
|
2013-03-08 18:21:58 -06:00
|
|
|
check_item_deprecated_drop(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> {
|
2013-03-05 19:43:37 -06:00
|
|
|
visit::mk_vt(@visit::Visitor {visit_item: |_i, _e, _v| { },
|
|
|
|
.. **(ty_stopping_visitor(v))})
|
|
|
|
}
|
|
|
|
|
|
|
|
fn ty_stopping_visitor<E>(v: visit::vt<E>) -> visit::vt<E> {
|
|
|
|
visit::mk_vt(@visit::Visitor {visit_ty: |_t, _e, _v| { },.. **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) {
|
2013-01-08 16:00:45 -06:00
|
|
|
let visit = item_stopping_visitor(
|
|
|
|
visit::mk_simple_visitor(@visit::SimpleVisitor {
|
|
|
|
visit_expr: |e: @ast::expr| {
|
|
|
|
match e.node {
|
|
|
|
ast::expr_while(cond, _) => {
|
|
|
|
match cond.node {
|
2013-01-30 11:56:33 -06:00
|
|
|
ast::expr_lit(@codemap::spanned {
|
2013-01-08 16:00:45 -06:00
|
|
|
node: ast::lit_bool(true), _}) =>
|
|
|
|
{
|
|
|
|
cx.sess.span_lint(
|
|
|
|
while_true, e.id, it.id,
|
|
|
|
e.span,
|
|
|
|
~"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
|
|
|
}
|
2013-01-08 16:00:45 -06:00
|
|
|
},
|
|
|
|
.. *visit::default_simple_visitor()
|
|
|
|
}));
|
2012-04-19 20:04:41 -05:00
|
|
|
visit::visit_item(it, (), visit);
|
2012-10-24 10:20:54 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn check_item_type_limits(cx: ty::ctxt, it: @ast::item) {
|
2013-02-20 19:07:17 -06:00
|
|
|
pure fn is_valid<T:cmp::Ord>(binop: ast::binop, v: T,
|
2012-10-24 11:21:57 -05:00
|
|
|
min: T, max: T) -> bool {
|
|
|
|
match binop {
|
|
|
|
ast::lt => v <= max,
|
|
|
|
ast::le => v < max,
|
|
|
|
ast::gt => v >= min,
|
|
|
|
ast::ge => v > min,
|
|
|
|
ast::eq | ast::ne => v >= min && v <= max,
|
2013-02-11 21:26:38 -06:00
|
|
|
_ => fail!()
|
2012-10-24 11:21:57 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pure fn rev_binop(binop: ast::binop) -> ast::binop {
|
|
|
|
match binop {
|
|
|
|
ast::lt => ast::gt,
|
|
|
|
ast::le => ast::ge,
|
|
|
|
ast::gt => ast::lt,
|
|
|
|
ast::ge => ast::le,
|
|
|
|
_ => binop
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pure fn int_ty_range(int_ty: ast::int_ty) -> (i64, i64) {
|
|
|
|
match int_ty {
|
|
|
|
ast::ty_i => (int::min_value as i64, int::max_value as i64),
|
|
|
|
ast::ty_char => (u32::min_value as i64, u32::max_value as i64),
|
|
|
|
ast::ty_i8 => (i8::min_value as i64, i8::max_value as i64),
|
|
|
|
ast::ty_i16 => (i16::min_value as i64, i16::max_value as i64),
|
|
|
|
ast::ty_i32 => (i32::min_value as i64, i32::max_value as i64),
|
|
|
|
ast::ty_i64 => (i64::min_value, i64::max_value)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pure fn uint_ty_range(uint_ty: ast::uint_ty) -> (u64, u64) {
|
|
|
|
match uint_ty {
|
|
|
|
ast::ty_u => (uint::min_value as u64, uint::max_value as u64),
|
|
|
|
ast::ty_u8 => (u8::min_value as u64, u8::max_value as u64),
|
|
|
|
ast::ty_u16 => (u16::min_value as u64, u16::max_value as u64),
|
|
|
|
ast::ty_u32 => (u32::min_value as u64, u32::max_value as u64),
|
|
|
|
ast::ty_u64 => (u64::min_value, u64::max_value)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn check_limits(cx: ty::ctxt, binop: ast::binop, l: &ast::expr,
|
|
|
|
r: &ast::expr) -> bool {
|
2013-01-10 12:59:58 -06:00
|
|
|
let (lit, expr, swap) = match (&l.node, &r.node) {
|
|
|
|
(&ast::expr_lit(_), _) => (l, r, true),
|
|
|
|
(_, &ast::expr_lit(_)) => (r, l, false),
|
2012-10-24 11:21:57 -05:00
|
|
|
_ => return true
|
|
|
|
};
|
|
|
|
// Normalize the binop so that the literal is always on the RHS in
|
|
|
|
// the comparison
|
|
|
|
let norm_binop = if (swap) {
|
|
|
|
rev_binop(binop)
|
|
|
|
} else {
|
|
|
|
binop
|
|
|
|
};
|
2013-01-07 16:16:52 -06:00
|
|
|
match ty::get(ty::expr_ty(cx, @/*bad*/copy *expr)).sty {
|
2012-10-24 11:21:57 -05:00
|
|
|
ty::ty_int(int_ty) => {
|
|
|
|
let (min, max) = int_ty_range(int_ty);
|
|
|
|
let lit_val: i64 = match lit.node {
|
|
|
|
ast::expr_lit(@li) => match li.node {
|
|
|
|
ast::lit_int(v, _) => v,
|
|
|
|
ast::lit_uint(v, _) => v as i64,
|
|
|
|
ast::lit_int_unsuffixed(v) => v,
|
|
|
|
_ => return true
|
|
|
|
},
|
2013-02-11 21:26:38 -06:00
|
|
|
_ => fail!()
|
2012-10-24 11:21:57 -05:00
|
|
|
};
|
|
|
|
is_valid(norm_binop, lit_val, min, max)
|
|
|
|
}
|
|
|
|
ty::ty_uint(uint_ty) => {
|
|
|
|
let (min, max): (u64, u64) = uint_ty_range(uint_ty);
|
|
|
|
let lit_val: u64 = match lit.node {
|
|
|
|
ast::expr_lit(@li) => match li.node {
|
|
|
|
ast::lit_int(v, _) => v as u64,
|
|
|
|
ast::lit_uint(v, _) => v,
|
|
|
|
ast::lit_int_unsuffixed(v) => v as u64,
|
|
|
|
_ => return true
|
|
|
|
},
|
2013-02-11 21:26:38 -06:00
|
|
|
_ => fail!()
|
2012-10-24 11:21:57 -05:00
|
|
|
};
|
|
|
|
is_valid(norm_binop, lit_val, min, max)
|
|
|
|
}
|
|
|
|
_ => true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pure fn is_comparison(binop: ast::binop) -> bool {
|
|
|
|
match binop {
|
|
|
|
ast::eq | ast::lt | ast::le |
|
|
|
|
ast::ne | ast::ge | ast::gt => true,
|
|
|
|
_ => false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-08 08:21:19 -06:00
|
|
|
let visit_expr: @fn(@ast::expr) = |e| {
|
|
|
|
match e.node {
|
|
|
|
ast::expr_binary(ref binop, @ref l, @ref r) => {
|
|
|
|
if is_comparison(*binop)
|
|
|
|
&& !check_limits(cx, *binop, l, r) {
|
|
|
|
cx.sess.span_lint(
|
|
|
|
type_limits, e.id, it.id, e.span,
|
|
|
|
~"comparison is useless due to type limits");
|
2012-10-24 11:21:57 -05:00
|
|
|
}
|
|
|
|
}
|
2013-01-08 08:21:19 -06:00
|
|
|
_ => ()
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-01-08 16:00:45 -06:00
|
|
|
let visit = item_stopping_visitor(
|
|
|
|
visit::mk_simple_visitor(@visit::SimpleVisitor {
|
|
|
|
visit_expr: visit_expr,
|
|
|
|
.. *visit::default_simple_visitor()
|
|
|
|
}));
|
2012-10-24 11:21:57 -05:00
|
|
|
visit::visit_item(it, (), visit);
|
2012-04-19 20:04:41 -05:00
|
|
|
}
|
|
|
|
|
2012-12-14 21:07:20 -06:00
|
|
|
fn check_item_default_methods(cx: ty::ctxt, item: @ast::item) {
|
2013-01-07 16:16:52 -06:00
|
|
|
match /*bad*/copy item.node {
|
2012-12-14 21:07:20 -06:00
|
|
|
ast::item_trait(_, _, methods) => {
|
|
|
|
for methods.each |method| {
|
|
|
|
match *method {
|
|
|
|
ast::required(*) => {}
|
|
|
|
ast::provided(*) => {
|
|
|
|
cx.sess.span_lint(
|
|
|
|
default_methods,
|
|
|
|
item.id,
|
|
|
|
item.id,
|
|
|
|
item.span,
|
|
|
|
~"default methods are experimental");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
_ => {}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-25 13:34:16 -06:00
|
|
|
fn check_item_deprecated_mutable_fields(cx: ty::ctxt, item: @ast::item) {
|
|
|
|
match item.node {
|
|
|
|
ast::item_struct(struct_def, _) => {
|
|
|
|
for struct_def.fields.each |field| {
|
|
|
|
match field.node.kind {
|
|
|
|
ast::named_field(_, ast::struct_mutable, _) => {
|
|
|
|
cx.sess.span_lint(deprecated_mutable_fields,
|
|
|
|
item.id,
|
|
|
|
item.id,
|
|
|
|
field.span,
|
|
|
|
~"mutable fields are deprecated");
|
|
|
|
}
|
|
|
|
ast::named_field(*) | ast::unnamed_field => {}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
_ => {}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-08 18:21:58 -06:00
|
|
|
fn check_item_deprecated_drop(cx: ty::ctxt, item: @ast::item) {
|
|
|
|
match item.node {
|
|
|
|
ast::item_struct(struct_def, _) => {
|
|
|
|
match struct_def.dtor {
|
|
|
|
None => {}
|
|
|
|
Some(ref dtor) => {
|
|
|
|
cx.sess.span_lint(deprecated_drop,
|
|
|
|
item.id,
|
|
|
|
item.id,
|
|
|
|
dtor.span,
|
|
|
|
~"`drop` notation for destructors is \
|
|
|
|
deprecated; implement the `Drop` \
|
|
|
|
trait instead");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
_ => {}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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,
|
2013-02-28 09:25:31 -06:00
|
|
|
decl: &ast::fn_decl) {
|
2013-03-08 19:44:37 -06:00
|
|
|
// warn about `&&` mode on foreign functions, both because it is
|
|
|
|
// deprecated and because its semantics have changed recently:
|
|
|
|
for decl.inputs.eachi |i, arg| {
|
|
|
|
match ty::resolved_mode(cx, arg.mode) {
|
2013-03-10 10:02:16 -05:00
|
|
|
ast::by_copy => {}
|
2013-03-08 19:44:37 -06:00
|
|
|
ast::by_ref => {
|
|
|
|
cx.sess.span_lint(
|
|
|
|
foreign_mode, fn_id, fn_id, arg.ty.span,
|
|
|
|
fmt!("foreign function uses `&&` mode \
|
|
|
|
on argument %u", i));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-30 18:19:07 -05:00
|
|
|
let tys = vec::map(decl.inputs, |a| a.ty );
|
2012-09-18 23:41:13 -05:00
|
|
|
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) => {
|
2013-02-05 21:41:45 -06: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 {
|
2013-01-07 16:16:52 -06:00
|
|
|
ast::item_foreign_mod(ref 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| {
|
2013-03-08 19:44:37 -06:00
|
|
|
match ni.node {
|
2013-02-18 00:20:36 -06:00
|
|
|
ast::foreign_item_fn(ref decl, _, _) => {
|
2012-06-26 18:18:37 -05:00
|
|
|
check_foreign_fn(cx, it.id, decl);
|
2012-04-12 19:30:52 -05:00
|
|
|
}
|
2013-01-24 20:49:51 -06:00
|
|
|
// FIXME #4622: Not implemented.
|
|
|
|
ast::foreign_item_const(*) => {}
|
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-08-28 20:25:41 -05:00
|
|
|
fn check_item_heap(cx: ty::ctxt, it: @ast::item) {
|
|
|
|
|
|
|
|
fn check_type_for_lint(cx: ty::ctxt, lint: lint,
|
|
|
|
node: ast::node_id,
|
|
|
|
item: ast::node_id,
|
|
|
|
span: span, ty: ty::t) {
|
|
|
|
|
|
|
|
if get_lint_settings_level(cx.sess.lint_settings,
|
|
|
|
lint, node, item) != allow {
|
|
|
|
let mut n_box = 0;
|
|
|
|
let mut n_uniq = 0;
|
|
|
|
ty::fold_ty(cx, ty, |t| {
|
2012-09-11 18:20:31 -05:00
|
|
|
match ty::get(t).sty {
|
2012-08-28 20:25:41 -05:00
|
|
|
ty::ty_box(_) => n_box += 1,
|
|
|
|
ty::ty_uniq(_) => n_uniq += 1,
|
|
|
|
_ => ()
|
|
|
|
};
|
|
|
|
t
|
|
|
|
});
|
|
|
|
|
|
|
|
if (n_uniq > 0 && lint != managed_heap_memory) {
|
|
|
|
let s = ty_to_str(cx, ty);
|
|
|
|
let m = ~"type uses owned (~ type) pointers: " + s;
|
|
|
|
cx.sess.span_lint(lint, node, item, span, m);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (n_box > 0 && lint != owned_heap_memory) {
|
|
|
|
let s = ty_to_str(cx, ty);
|
|
|
|
let m = ~"type uses managed (@ type) pointers: " + s;
|
|
|
|
cx.sess.span_lint(lint, node, item, span, m);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn check_type(cx: ty::ctxt,
|
|
|
|
node: ast::node_id,
|
|
|
|
item: ast::node_id,
|
|
|
|
span: span, ty: ty::t) {
|
|
|
|
for [managed_heap_memory,
|
|
|
|
owned_heap_memory,
|
|
|
|
heap_memory].each |lint| {
|
2012-09-19 18:55:01 -05:00
|
|
|
check_type_for_lint(cx, *lint, node, item, span, ty);
|
2012-08-28 20:25:41 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
match it.node {
|
|
|
|
ast::item_fn(*) |
|
|
|
|
ast::item_ty(*) |
|
|
|
|
ast::item_enum(*) |
|
2012-12-10 15:47:54 -06:00
|
|
|
ast::item_struct(*) |
|
2012-08-28 20:25:41 -05:00
|
|
|
ast::item_trait(*) => check_type(cx, it.id, it.id, it.span,
|
|
|
|
ty::node_id_to_type(cx, it.id)),
|
|
|
|
_ => ()
|
|
|
|
}
|
|
|
|
|
2013-01-28 20:34:32 -06:00
|
|
|
// If it's a struct, we also have to check the fields' types
|
|
|
|
match it.node {
|
|
|
|
ast::item_struct(struct_def, _) => {
|
|
|
|
for struct_def.fields.each |struct_field| {
|
|
|
|
check_type(cx, struct_field.node.id, it.id,
|
|
|
|
struct_field.span,
|
|
|
|
ty::node_id_to_type(cx, struct_field.node.id));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
_ => ()
|
|
|
|
}
|
|
|
|
|
2013-01-08 16:00:45 -06:00
|
|
|
let visit = item_stopping_visitor(
|
|
|
|
visit::mk_simple_visitor(@visit::SimpleVisitor {
|
|
|
|
visit_expr: |e: @ast::expr| {
|
|
|
|
let ty = ty::expr_ty(cx, e);
|
|
|
|
check_type(cx, e.id, it.id, e.span, ty);
|
|
|
|
},
|
|
|
|
.. *visit::default_simple_visitor()
|
|
|
|
}));
|
2012-08-28 20:25:41 -05:00
|
|
|
visit::visit_item(it, (), visit);
|
|
|
|
}
|
|
|
|
|
2012-06-04 18:07:54 -05:00
|
|
|
fn check_item_path_statement(cx: ty::ctxt, it: @ast::item) {
|
2013-01-08 16:00:45 -06:00
|
|
|
let visit = item_stopping_visitor(
|
|
|
|
visit::mk_simple_visitor(@visit::SimpleVisitor {
|
|
|
|
visit_stmt: |s: @ast::stmt| {
|
|
|
|
match s.node {
|
2013-01-15 15:51:43 -06:00
|
|
|
ast::stmt_semi(
|
|
|
|
@ast::expr { id: id, node: ast::expr_path(_), _ },
|
|
|
|
_
|
|
|
|
) => {
|
2013-01-08 16:00:45 -06:00
|
|
|
cx.sess.span_lint(
|
|
|
|
path_statement, id, it.id,
|
|
|
|
s.span,
|
|
|
|
~"path statement with no effect");
|
|
|
|
}
|
|
|
|
_ => ()
|
|
|
|
}
|
|
|
|
},
|
|
|
|
.. *visit::default_simple_visitor()
|
|
|
|
}));
|
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) {
|
2012-07-18 18:18:02 -05:00
|
|
|
fn is_camel_case(cx: ty::ctxt, ident: ast::ident) -> bool {
|
|
|
|
let ident = cx.sess.str_of(ident);
|
2013-03-06 15:58:02 -06:00
|
|
|
fail_unless!(!ident.is_empty());
|
2013-02-16 12:35:05 -06:00
|
|
|
let ident = ident_without_trailing_underscores(*ident);
|
2012-08-15 16:54:33 -05:00
|
|
|
let ident = ident_without_leading_underscores(ident);
|
2012-08-08 17:05:49 -05:00
|
|
|
char::is_uppercase(str::char_at(ident, 0)) &&
|
2012-07-31 20:58:03 -05:00
|
|
|
!ident.contains_char('_')
|
|
|
|
}
|
|
|
|
|
2013-03-14 13:22:51 -05:00
|
|
|
fn ident_without_trailing_underscores(ident: &'r str) -> &'r str {
|
2012-08-15 16:54:33 -05:00
|
|
|
match str::rfind(ident, |c| c != '_') {
|
2013-02-16 12:35:05 -06:00
|
|
|
Some(idx) => str::view(ident, 0, idx + 1),
|
|
|
|
None => ident, // all underscores
|
2012-08-15 16:54:33 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-14 13:22:51 -05:00
|
|
|
fn ident_without_leading_underscores(ident: &'r str) -> &'r str {
|
2012-08-15 16:54:33 -05:00
|
|
|
match str::find(ident, |c| c != '_') {
|
2013-02-16 12:35:05 -06:00
|
|
|
Some(idx) => str::view(ident, idx, ident.len()),
|
|
|
|
None => ident // all underscores
|
2012-08-08 17:05:49 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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) {
|
2012-07-18 18:18:02 -05:00
|
|
|
if !is_camel_case(cx, ident) {
|
2012-07-31 20:58:03 -05:00
|
|
|
cx.sess.span_lint(
|
|
|
|
non_camel_case_types, expr_id, item_id, span,
|
2012-09-18 13:57:03 -05:00
|
|
|
~"type, variant, or trait should have \
|
|
|
|
a camel case identifier");
|
2012-07-31 20:58:03 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-06 14:34:08 -05:00
|
|
|
match it.node {
|
2013-02-16 12:36:09 -06:00
|
|
|
ast::item_ty(*) | ast::item_struct(*) |
|
|
|
|
ast::item_trait(*) => {
|
|
|
|
check_case(cx, it.ident, it.id, it.id, it.span)
|
2012-07-31 20:58:03 -05:00
|
|
|
}
|
2013-02-16 12:36:09 -06:00
|
|
|
ast::item_enum(ref enum_definition, _) => {
|
|
|
|
check_case(cx, it.ident, it.id, it.id, it.span);
|
|
|
|
for enum_definition.variants.each |variant| {
|
|
|
|
check_case(cx, variant.node.name,
|
|
|
|
variant.node.id, it.id, variant.span);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
_ => ()
|
2012-07-31 20:58:03 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-18 00:20:36 -06: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-08-22 19:24:52 -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
|
2013-02-18 23:25:44 -06: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-09-25 19:02:22 -05:00
|
|
|
check_fn_deprecated_modes(tcx, fn_ty, decl, span, id);
|
|
|
|
}
|
|
|
|
|
2013-02-18 00:20:36 -06:00
|
|
|
fn check_fn_deprecated_modes(tcx: ty::ctxt, fn_ty: ty::t, decl: &ast::fn_decl,
|
2012-09-25 19:02:22 -05:00
|
|
|
span: span, id: ast::node_id) {
|
2012-09-11 18:20:31 -05:00
|
|
|
match ty::get(fn_ty).sty {
|
2013-01-31 19:12:29 -06:00
|
|
|
ty::ty_closure(ty::ClosureTy {sig: ref sig, _}) |
|
|
|
|
ty::ty_bare_fn(ty::BareFnTy {sig: ref sig, _}) => {
|
2012-09-25 19:02:22 -05:00
|
|
|
let mut counter = 0;
|
2013-01-31 19:12:29 -06:00
|
|
|
for vec::each2(sig.inputs, decl.inputs) |arg_ty, arg_ast| {
|
2012-09-25 19:02:22 -05:00
|
|
|
counter += 1;
|
|
|
|
debug!("arg %d, ty=%s, mode=%s",
|
|
|
|
counter,
|
|
|
|
ty_to_str(tcx, arg_ty.ty),
|
|
|
|
mode_to_str(arg_ast.mode));
|
|
|
|
match arg_ast.mode {
|
|
|
|
ast::expl(ast::by_copy) => {
|
2012-10-02 13:37:37 -05:00
|
|
|
if !tcx.legacy_modes {
|
|
|
|
tcx.sess.span_lint(
|
|
|
|
deprecated_mode, id, id, span,
|
|
|
|
fmt!("argument %d uses by-copy mode",
|
|
|
|
counter));
|
|
|
|
}
|
2012-09-25 19:02:22 -05:00
|
|
|
}
|
2012-07-25 08:41:56 -05:00
|
|
|
|
2012-09-25 19:02:22 -05:00
|
|
|
ast::expl(_) => {
|
|
|
|
tcx.sess.span_lint(
|
|
|
|
deprecated_mode, id, id,
|
|
|
|
span,
|
2012-09-25 20:19:29 -05:00
|
|
|
fmt!("argument %d uses an explicit mode", counter));
|
2012-09-25 19:02:22 -05:00
|
|
|
}
|
2012-07-25 08:41:56 -05:00
|
|
|
|
2012-09-25 19:02:22 -05:00
|
|
|
ast::infer(_) => {
|
2012-10-01 18:43:45 -05:00
|
|
|
if tcx.legacy_modes {
|
2013-02-07 21:33:12 -06:00
|
|
|
let kind = ty::type_contents(tcx, arg_ty.ty);
|
|
|
|
if !kind.is_safe_for_default_mode(tcx) {
|
2012-10-01 18:43:45 -05:00
|
|
|
tcx.sess.span_lint(
|
|
|
|
deprecated_mode, id, id,
|
|
|
|
span,
|
|
|
|
fmt!("argument %d uses the default mode \
|
|
|
|
but shouldn't",
|
|
|
|
counter));
|
|
|
|
}
|
2012-09-25 19:02:22 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
match ty::get(arg_ty.ty).sty {
|
2013-01-31 19:12:29 -06:00
|
|
|
ty::ty_closure(*) | ty::ty_bare_fn(*) => {
|
2012-09-25 19:02:22 -05:00
|
|
|
let span = arg_ast.ty.span;
|
|
|
|
// Recurse to check fn-type argument
|
|
|
|
match arg_ast.ty.node {
|
2013-01-31 19:12:29 -06:00
|
|
|
ast::ty_closure(@ast::TyClosure{decl: ref d, _}) |
|
|
|
|
ast::ty_bare_fn(@ast::TyBareFn{decl: ref d, _})=>{
|
2012-09-25 19:02:22 -05:00
|
|
|
check_fn_deprecated_modes(tcx, arg_ty.ty,
|
2013-02-18 00:20:36 -06:00
|
|
|
d, span, id);
|
2012-09-25 19:02:22 -05:00
|
|
|
}
|
|
|
|
ast::ty_path(*) => {
|
|
|
|
// This is probably a typedef, so we can't
|
|
|
|
// see the actual fn decl
|
|
|
|
// e.g. fn foo(f: InitOp<T>)
|
|
|
|
}
|
|
|
|
_ => {
|
|
|
|
tcx.sess.span_warn(span, ~"what");
|
|
|
|
error!("arg %d, ty=%s, mode=%s",
|
|
|
|
counter,
|
|
|
|
ty_to_str(tcx, arg_ty.ty),
|
|
|
|
mode_to_str(arg_ast.mode));
|
|
|
|
error!("%?",arg_ast.ty.node);
|
2013-02-11 21:26:38 -06:00
|
|
|
fail!()
|
2012-09-25 19:02:22 -05:00
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
_ => ()
|
2012-07-25 08:41:56 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-09-25 19:02:22 -05:00
|
|
|
|
|
|
|
_ => tcx.sess.impossible_case(span, ~"check_fn: function has \
|
|
|
|
non-fn type")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn check_item_deprecated_modes(tcx: ty::ctxt, it: @ast::item) {
|
|
|
|
match it.node {
|
|
|
|
ast::item_ty(ty, _) => {
|
|
|
|
match ty.node {
|
2013-01-31 19:12:29 -06:00
|
|
|
ast::ty_closure(@ast::TyClosure {decl: ref decl, _}) |
|
|
|
|
ast::ty_bare_fn(@ast::TyBareFn {decl: ref decl, _}) => {
|
2012-09-25 19:02:22 -05:00
|
|
|
let fn_ty = ty::node_id_to_type(tcx, it.id);
|
|
|
|
check_fn_deprecated_modes(
|
2013-02-18 00:20:36 -06:00
|
|
|
tcx, fn_ty, decl, ty.span, it.id)
|
2012-09-25 19:02:22 -05:00
|
|
|
}
|
|
|
|
_ => ()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
_ => ()
|
2012-07-25 08:41:56 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-30 15:44:24 -06:00
|
|
|
pub fn check_crate(tcx: ty::ctxt, crate: @ast::crate) {
|
2013-01-08 16:00:45 -06:00
|
|
|
let v = visit::mk_simple_visitor(@visit::SimpleVisitor {
|
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),
|
2012-09-04 15:29:32 -05:00
|
|
|
.. *visit::default_simple_visitor()
|
2012-06-04 18:07:54 -05:00
|
|
|
});
|
|
|
|
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:
|
|
|
|
//
|