auto merge of #18044 : aturon/rust/lint-conventions, r=pcwalton
[RFC 344](https://github.com/rust-lang/rfcs/pull/344) proposes a set of naming conventions for lints. This PR renames existing lints to follow the conventions. Use the following sed script to bring your code up to date: ``` s/unnecessary_typecast/unused_typecasts/g s/unsigned_negate/unsigned_negation/g s/type_limits/unused_comparisons/g s/type_overflow/overflowing_literals/g s/ctypes/improper_ctypes/g s/owned_heap_memory/box_pointers/g s/unused_attribute/unused_attributes/g s/path_statement/path_statements/g s/unused_must_use/unused_must_use/g s/unused_result/unused_results/g s/non_uppercase_statics/non_upper_case_globals/g s/unnecessary_parens/unused_parens/g s/unnecessary_import_braces/unused_import_braces/g s/unused_unsafe/unused_unsafe/g s/unsafe_block/unsafe_blocks/g s/unused_mut/unused_mut/g s/unnecessary_allocation/unused_allocation/g s/missing_doc/missing_docs/g s/unused_imports/unused_imports/g s/unused_extern_crate/unused_extern_crates/g s/unnecessary_qualification/unused_qualifications/g s/unrecognized_lint/unknown_lints/g s/unused_variable/unused_variables/g s/dead_assignment/unused_assignments/g s/unknown_crate_type/unknown_crate_types/g s/variant_size_difference/variant_size_differences/g s/transmute_fat_ptr/fat_ptr_transmutes/g ``` Since a large number of lints are being renamed for RFC 344, this PR adds some basic deprecation/renaming functionality to the pluggable lint system. It allows a simple mapping of old to new names, and can warn when old names are being used. This change needs to be rolled out in stages. In this PR, the deprecation warning is commented out, but the old name is forwarded to the new one. Once the PR lands and we have generated a new snapshot of the compiler, we can add the deprecation warning and rename all uses of the lints in the rust codebase. I will file a PR to do so. Closes #16545 Closes #17932 r? @pcwalton
This commit is contained in:
commit
ea8a5df431
7 changed files with 191 additions and 126 deletions
|
@ -704,7 +704,7 @@ pub fn collect_crate_types(session: &Session,
|
||||||
}
|
}
|
||||||
Some(ref n) if n.equiv(&("bin")) => Some(config::CrateTypeExecutable),
|
Some(ref n) if n.equiv(&("bin")) => Some(config::CrateTypeExecutable),
|
||||||
Some(_) => {
|
Some(_) => {
|
||||||
session.add_lint(lint::builtin::UNKNOWN_CRATE_TYPE,
|
session.add_lint(lint::builtin::UNKNOWN_CRATE_TYPES,
|
||||||
ast::CRATE_NODE_ID,
|
ast::CRATE_NODE_ID,
|
||||||
a.span,
|
a.span,
|
||||||
"invalid `crate_type` \
|
"invalid `crate_type` \
|
||||||
|
@ -712,7 +712,7 @@ pub fn collect_crate_types(session: &Session,
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
session.add_lint(lint::builtin::UNKNOWN_CRATE_TYPE,
|
session.add_lint(lint::builtin::UNKNOWN_CRATE_TYPES,
|
||||||
ast::CRATE_NODE_ID,
|
ast::CRATE_NODE_ID,
|
||||||
a.span,
|
a.span,
|
||||||
"`crate_type` requires a \
|
"`crate_type` requires a \
|
||||||
|
|
|
@ -81,14 +81,14 @@ impl LintPass for WhileTrue {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
declare_lint!(UNNECESSARY_TYPECAST, Allow,
|
declare_lint!(UNUSED_TYPECASTS, Allow,
|
||||||
"detects unnecessary type casts, that can be removed")
|
"detects unnecessary type casts, that can be removed")
|
||||||
|
|
||||||
pub struct UnusedCasts;
|
pub struct UnusedCasts;
|
||||||
|
|
||||||
impl LintPass for UnusedCasts {
|
impl LintPass for UnusedCasts {
|
||||||
fn get_lints(&self) -> LintArray {
|
fn get_lints(&self) -> LintArray {
|
||||||
lint_array!(UNNECESSARY_TYPECAST)
|
lint_array!(UNUSED_TYPECASTS)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn check_expr(&mut self, cx: &Context, e: &ast::Expr) {
|
fn check_expr(&mut self, cx: &Context, e: &ast::Expr) {
|
||||||
|
@ -96,7 +96,7 @@ impl LintPass for UnusedCasts {
|
||||||
ast::ExprCast(ref expr, ref ty) => {
|
ast::ExprCast(ref expr, ref ty) => {
|
||||||
let t_t = ast_ty_to_ty(cx, &infer::new_infer_ctxt(cx.tcx), &**ty);
|
let t_t = ast_ty_to_ty(cx, &infer::new_infer_ctxt(cx.tcx), &**ty);
|
||||||
if ty::get(ty::expr_ty(cx.tcx, &**expr)).sty == ty::get(t_t).sty {
|
if ty::get(ty::expr_ty(cx.tcx, &**expr)).sty == ty::get(t_t).sty {
|
||||||
cx.span_lint(UNNECESSARY_TYPECAST, ty.span, "unnecessary type cast");
|
cx.span_lint(UNUSED_TYPECASTS, ty.span, "unnecessary type cast");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => ()
|
_ => ()
|
||||||
|
@ -104,13 +104,13 @@ impl LintPass for UnusedCasts {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
declare_lint!(UNSIGNED_NEGATE, Warn,
|
declare_lint!(UNSIGNED_NEGATION, Warn,
|
||||||
"using an unary minus operator on unsigned type")
|
"using an unary minus operator on unsigned type")
|
||||||
|
|
||||||
declare_lint!(TYPE_LIMITS, Warn,
|
declare_lint!(UNUSED_COMPARISONS, Warn,
|
||||||
"comparisons made useless by limits of the types involved")
|
"comparisons made useless by limits of the types involved")
|
||||||
|
|
||||||
declare_lint!(TYPE_OVERFLOW, Warn,
|
declare_lint!(OVERFLOWING_LITERALS, Warn,
|
||||||
"literal out of range for its type")
|
"literal out of range for its type")
|
||||||
|
|
||||||
pub struct TypeLimits {
|
pub struct TypeLimits {
|
||||||
|
@ -128,7 +128,7 @@ impl TypeLimits {
|
||||||
|
|
||||||
impl LintPass for TypeLimits {
|
impl LintPass for TypeLimits {
|
||||||
fn get_lints(&self) -> LintArray {
|
fn get_lints(&self) -> LintArray {
|
||||||
lint_array!(UNSIGNED_NEGATE, TYPE_LIMITS, TYPE_OVERFLOW)
|
lint_array!(UNSIGNED_NEGATION, UNUSED_COMPARISONS, OVERFLOWING_LITERALS)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn check_expr(&mut self, cx: &Context, e: &ast::Expr) {
|
fn check_expr(&mut self, cx: &Context, e: &ast::Expr) {
|
||||||
|
@ -138,7 +138,7 @@ impl LintPass for TypeLimits {
|
||||||
ast::ExprLit(ref lit) => {
|
ast::ExprLit(ref lit) => {
|
||||||
match lit.node {
|
match lit.node {
|
||||||
ast::LitInt(_, ast::UnsignedIntLit(_)) => {
|
ast::LitInt(_, ast::UnsignedIntLit(_)) => {
|
||||||
cx.span_lint(UNSIGNED_NEGATE, e.span,
|
cx.span_lint(UNSIGNED_NEGATION, e.span,
|
||||||
"negation of unsigned int literal may \
|
"negation of unsigned int literal may \
|
||||||
be unintentional");
|
be unintentional");
|
||||||
},
|
},
|
||||||
|
@ -149,7 +149,7 @@ impl LintPass for TypeLimits {
|
||||||
let t = ty::expr_ty(cx.tcx, &**expr);
|
let t = ty::expr_ty(cx.tcx, &**expr);
|
||||||
match ty::get(t).sty {
|
match ty::get(t).sty {
|
||||||
ty::ty_uint(_) => {
|
ty::ty_uint(_) => {
|
||||||
cx.span_lint(UNSIGNED_NEGATE, e.span,
|
cx.span_lint(UNSIGNED_NEGATION, e.span,
|
||||||
"negation of unsigned int variable may \
|
"negation of unsigned int variable may \
|
||||||
be unintentional");
|
be unintentional");
|
||||||
},
|
},
|
||||||
|
@ -167,7 +167,7 @@ impl LintPass for TypeLimits {
|
||||||
},
|
},
|
||||||
ast::ExprBinary(binop, ref l, ref r) => {
|
ast::ExprBinary(binop, ref l, ref r) => {
|
||||||
if is_comparison(binop) && !check_limits(cx.tcx, binop, &**l, &**r) {
|
if is_comparison(binop) && !check_limits(cx.tcx, binop, &**l, &**r) {
|
||||||
cx.span_lint(TYPE_LIMITS, e.span,
|
cx.span_lint(UNUSED_COMPARISONS, e.span,
|
||||||
"comparison is useless due to type limits");
|
"comparison is useless due to type limits");
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -185,7 +185,7 @@ impl LintPass for TypeLimits {
|
||||||
|
|
||||||
if (negative && v > (min.abs() as u64)) ||
|
if (negative && v > (min.abs() as u64)) ||
|
||||||
(!negative && v > (max.abs() as u64)) {
|
(!negative && v > (max.abs() as u64)) {
|
||||||
cx.span_lint(TYPE_OVERFLOW, e.span,
|
cx.span_lint(OVERFLOWING_LITERALS, e.span,
|
||||||
"literal out of range for its type");
|
"literal out of range for its type");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -204,7 +204,7 @@ impl LintPass for TypeLimits {
|
||||||
_ => fail!()
|
_ => fail!()
|
||||||
};
|
};
|
||||||
if lit_val < min || lit_val > max {
|
if lit_val < min || lit_val > max {
|
||||||
cx.span_lint(TYPE_OVERFLOW, e.span,
|
cx.span_lint(OVERFLOWING_LITERALS, e.span,
|
||||||
"literal out of range for its type");
|
"literal out of range for its type");
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -219,7 +219,7 @@ impl LintPass for TypeLimits {
|
||||||
_ => fail!()
|
_ => fail!()
|
||||||
};
|
};
|
||||||
if lit_val < min || lit_val > max {
|
if lit_val < min || lit_val > max {
|
||||||
cx.span_lint(TYPE_OVERFLOW, e.span,
|
cx.span_lint(OVERFLOWING_LITERALS, e.span,
|
||||||
"literal out of range for its type");
|
"literal out of range for its type");
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -330,23 +330,23 @@ impl LintPass for TypeLimits {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
declare_lint!(CTYPES, Warn,
|
declare_lint!(IMPROPER_CTYPES, Warn,
|
||||||
"proper use of libc types in foreign modules")
|
"proper use of libc types in foreign modules")
|
||||||
|
|
||||||
struct CTypesVisitor<'a, 'tcx: 'a> {
|
struct ImproperCTypesVisitor<'a, 'tcx: 'a> {
|
||||||
cx: &'a Context<'a, 'tcx>
|
cx: &'a Context<'a, 'tcx>
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, 'tcx> CTypesVisitor<'a, 'tcx> {
|
impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> {
|
||||||
fn check_def(&mut self, sp: Span, ty_id: ast::NodeId, path_id: ast::NodeId) {
|
fn check_def(&mut self, sp: Span, ty_id: ast::NodeId, path_id: ast::NodeId) {
|
||||||
match self.cx.tcx.def_map.borrow().get_copy(&path_id) {
|
match self.cx.tcx.def_map.borrow().get_copy(&path_id) {
|
||||||
def::DefPrimTy(ast::TyInt(ast::TyI)) => {
|
def::DefPrimTy(ast::TyInt(ast::TyI)) => {
|
||||||
self.cx.span_lint(CTYPES, sp,
|
self.cx.span_lint(IMPROPER_CTYPES, sp,
|
||||||
"found rust type `int` in foreign module, while \
|
"found rust type `int` in foreign module, while \
|
||||||
libc::c_int or libc::c_long should be used");
|
libc::c_int or libc::c_long should be used");
|
||||||
}
|
}
|
||||||
def::DefPrimTy(ast::TyUint(ast::TyU)) => {
|
def::DefPrimTy(ast::TyUint(ast::TyU)) => {
|
||||||
self.cx.span_lint(CTYPES, sp,
|
self.cx.span_lint(IMPROPER_CTYPES, sp,
|
||||||
"found rust type `uint` in foreign module, while \
|
"found rust type `uint` in foreign module, while \
|
||||||
libc::c_uint or libc::c_ulong should be used");
|
libc::c_uint or libc::c_ulong should be used");
|
||||||
}
|
}
|
||||||
|
@ -357,7 +357,7 @@ impl<'a, 'tcx> CTypesVisitor<'a, 'tcx> {
|
||||||
};
|
};
|
||||||
|
|
||||||
if !ty::is_ffi_safe(self.cx.tcx, tty) {
|
if !ty::is_ffi_safe(self.cx.tcx, tty) {
|
||||||
self.cx.span_lint(CTYPES, sp,
|
self.cx.span_lint(IMPROPER_CTYPES, sp,
|
||||||
"found type without foreign-function-safe
|
"found type without foreign-function-safe
|
||||||
representation annotation in foreign module, consider \
|
representation annotation in foreign module, consider \
|
||||||
adding a #[repr(...)] attribute to the type");
|
adding a #[repr(...)] attribute to the type");
|
||||||
|
@ -368,7 +368,7 @@ impl<'a, 'tcx> CTypesVisitor<'a, 'tcx> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, 'tcx, 'v> Visitor<'v> for CTypesVisitor<'a, 'tcx> {
|
impl<'a, 'tcx, 'v> Visitor<'v> for ImproperCTypesVisitor<'a, 'tcx> {
|
||||||
fn visit_ty(&mut self, ty: &ast::Ty) {
|
fn visit_ty(&mut self, ty: &ast::Ty) {
|
||||||
match ty.node {
|
match ty.node {
|
||||||
ast::TyPath(_, _, id) => self.check_def(ty.span, ty.id, id),
|
ast::TyPath(_, _, id) => self.check_def(ty.span, ty.id, id),
|
||||||
|
@ -378,16 +378,16 @@ impl<'a, 'tcx, 'v> Visitor<'v> for CTypesVisitor<'a, 'tcx> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct CTypes;
|
pub struct ImproperCTypes;
|
||||||
|
|
||||||
impl LintPass for CTypes {
|
impl LintPass for ImproperCTypes {
|
||||||
fn get_lints(&self) -> LintArray {
|
fn get_lints(&self) -> LintArray {
|
||||||
lint_array!(CTYPES)
|
lint_array!(IMPROPER_CTYPES)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn check_item(&mut self, cx: &Context, it: &ast::Item) {
|
fn check_item(&mut self, cx: &Context, it: &ast::Item) {
|
||||||
fn check_ty(cx: &Context, ty: &ast::Ty) {
|
fn check_ty(cx: &Context, ty: &ast::Ty) {
|
||||||
let mut vis = CTypesVisitor { cx: cx };
|
let mut vis = ImproperCTypesVisitor { cx: cx };
|
||||||
vis.visit_ty(ty);
|
vis.visit_ty(ty);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -412,12 +412,12 @@ impl LintPass for CTypes {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
declare_lint!(OWNED_HEAP_MEMORY, Allow,
|
declare_lint!(BOX_POINTERS, Allow,
|
||||||
"use of owned (Box type) heap memory")
|
"use of owned (Box type) heap memory")
|
||||||
|
|
||||||
pub struct HeapMemory;
|
pub struct BoxPointers;
|
||||||
|
|
||||||
impl HeapMemory {
|
impl BoxPointers {
|
||||||
fn check_heap_type(&self, cx: &Context, span: Span, ty: ty::t) {
|
fn check_heap_type(&self, cx: &Context, span: Span, ty: ty::t) {
|
||||||
let mut n_uniq = 0i;
|
let mut n_uniq = 0i;
|
||||||
ty::fold_ty(cx.tcx, ty, |t| {
|
ty::fold_ty(cx.tcx, ty, |t| {
|
||||||
|
@ -438,14 +438,14 @@ impl HeapMemory {
|
||||||
if n_uniq > 0 {
|
if n_uniq > 0 {
|
||||||
let s = ty_to_string(cx.tcx, ty);
|
let s = ty_to_string(cx.tcx, ty);
|
||||||
let m = format!("type uses owned (Box type) pointers: {}", s);
|
let m = format!("type uses owned (Box type) pointers: {}", s);
|
||||||
cx.span_lint(OWNED_HEAP_MEMORY, span, m.as_slice());
|
cx.span_lint(BOX_POINTERS, span, m.as_slice());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl LintPass for HeapMemory {
|
impl LintPass for BoxPointers {
|
||||||
fn get_lints(&self) -> LintArray {
|
fn get_lints(&self) -> LintArray {
|
||||||
lint_array!(OWNED_HEAP_MEMORY)
|
lint_array!(BOX_POINTERS)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn check_item(&mut self, cx: &Context, it: &ast::Item) {
|
fn check_item(&mut self, cx: &Context, it: &ast::Item) {
|
||||||
|
@ -545,14 +545,14 @@ impl LintPass for RawPointerDeriving {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
declare_lint!(UNUSED_ATTRIBUTE, Warn,
|
declare_lint!(UNUSED_ATTRIBUTES, Warn,
|
||||||
"detects attributes that were not used by the compiler")
|
"detects attributes that were not used by the compiler")
|
||||||
|
|
||||||
pub struct UnusedAttribute;
|
pub struct UnusedAttributes;
|
||||||
|
|
||||||
impl LintPass for UnusedAttribute {
|
impl LintPass for UnusedAttributes {
|
||||||
fn get_lints(&self) -> LintArray {
|
fn get_lints(&self) -> LintArray {
|
||||||
lint_array!(UNUSED_ATTRIBUTE)
|
lint_array!(UNUSED_ATTRIBUTES)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn check_attribute(&mut self, cx: &Context, attr: &ast::Attribute) {
|
fn check_attribute(&mut self, cx: &Context, attr: &ast::Attribute) {
|
||||||
|
@ -618,7 +618,7 @@ impl LintPass for UnusedAttribute {
|
||||||
}
|
}
|
||||||
|
|
||||||
if !attr::is_used(attr) {
|
if !attr::is_used(attr) {
|
||||||
cx.span_lint(UNUSED_ATTRIBUTE, attr.span, "unused attribute");
|
cx.span_lint(UNUSED_ATTRIBUTES, attr.span, "unused attribute");
|
||||||
if CRATE_ATTRS.contains(&attr.name().get()) {
|
if CRATE_ATTRS.contains(&attr.name().get()) {
|
||||||
let msg = match attr.node.style {
|
let msg = match attr.node.style {
|
||||||
ast::AttrOuter => "crate-level attribute should be an inner \
|
ast::AttrOuter => "crate-level attribute should be an inner \
|
||||||
|
@ -626,27 +626,27 @@ impl LintPass for UnusedAttribute {
|
||||||
ast::AttrInner => "crate-level attribute should be in the \
|
ast::AttrInner => "crate-level attribute should be in the \
|
||||||
root module",
|
root module",
|
||||||
};
|
};
|
||||||
cx.span_lint(UNUSED_ATTRIBUTE, attr.span, msg);
|
cx.span_lint(UNUSED_ATTRIBUTES, attr.span, msg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
declare_lint!(pub PATH_STATEMENT, Warn,
|
declare_lint!(pub PATH_STATEMENTS, Warn,
|
||||||
"path statements with no effect")
|
"path statements with no effect")
|
||||||
|
|
||||||
pub struct PathStatement;
|
pub struct PathStatements;
|
||||||
|
|
||||||
impl LintPass for PathStatement {
|
impl LintPass for PathStatements {
|
||||||
fn get_lints(&self) -> LintArray {
|
fn get_lints(&self) -> LintArray {
|
||||||
lint_array!(PATH_STATEMENT)
|
lint_array!(PATH_STATEMENTS)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn check_stmt(&mut self, cx: &Context, s: &ast::Stmt) {
|
fn check_stmt(&mut self, cx: &Context, s: &ast::Stmt) {
|
||||||
match s.node {
|
match s.node {
|
||||||
ast::StmtSemi(ref expr, _) => {
|
ast::StmtSemi(ref expr, _) => {
|
||||||
match expr.node {
|
match expr.node {
|
||||||
ast::ExprPath(_) => cx.span_lint(PATH_STATEMENT, s.span,
|
ast::ExprPath(_) => cx.span_lint(PATH_STATEMENTS, s.span,
|
||||||
"path statement with no effect"),
|
"path statement with no effect"),
|
||||||
_ => ()
|
_ => ()
|
||||||
}
|
}
|
||||||
|
@ -659,14 +659,14 @@ impl LintPass for PathStatement {
|
||||||
declare_lint!(pub UNUSED_MUST_USE, Warn,
|
declare_lint!(pub UNUSED_MUST_USE, Warn,
|
||||||
"unused result of a type flagged as #[must_use]")
|
"unused result of a type flagged as #[must_use]")
|
||||||
|
|
||||||
declare_lint!(pub UNUSED_RESULT, Allow,
|
declare_lint!(pub UNUSED_RESULTS, Allow,
|
||||||
"unused result of an expression in a statement")
|
"unused result of an expression in a statement")
|
||||||
|
|
||||||
pub struct UnusedResult;
|
pub struct UnusedResults;
|
||||||
|
|
||||||
impl LintPass for UnusedResult {
|
impl LintPass for UnusedResults {
|
||||||
fn get_lints(&self) -> LintArray {
|
fn get_lints(&self) -> LintArray {
|
||||||
lint_array!(UNUSED_MUST_USE, UNUSED_RESULT)
|
lint_array!(UNUSED_MUST_USE, UNUSED_RESULTS)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn check_stmt(&mut self, cx: &Context, s: &ast::Stmt) {
|
fn check_stmt(&mut self, cx: &Context, s: &ast::Stmt) {
|
||||||
|
@ -702,7 +702,7 @@ impl LintPass for UnusedResult {
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
if !warned {
|
if !warned {
|
||||||
cx.span_lint(UNUSED_RESULT, s.span, "unused result");
|
cx.span_lint(UNUSED_RESULTS, s.span, "unused result");
|
||||||
}
|
}
|
||||||
|
|
||||||
fn check_must_use(cx: &Context, attrs: &[ast::Attribute], sp: Span) -> bool {
|
fn check_must_use(cx: &Context, attrs: &[ast::Attribute], sp: Span) -> bool {
|
||||||
|
@ -966,14 +966,14 @@ impl LintPass for NonSnakeCase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
declare_lint!(pub NON_UPPERCASE_STATICS, Warn,
|
declare_lint!(pub NON_UPPER_CASE_GLOBALS, Warn,
|
||||||
"static constants should have uppercase identifiers")
|
"static constants should have uppercase identifiers")
|
||||||
|
|
||||||
pub struct NonUppercaseStatics;
|
pub struct NonUpperCaseGlobals;
|
||||||
|
|
||||||
impl LintPass for NonUppercaseStatics {
|
impl LintPass for NonUpperCaseGlobals {
|
||||||
fn get_lints(&self) -> LintArray {
|
fn get_lints(&self) -> LintArray {
|
||||||
lint_array!(NON_UPPERCASE_STATICS)
|
lint_array!(NON_UPPER_CASE_GLOBALS)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn check_item(&mut self, cx: &Context, it: &ast::Item) {
|
fn check_item(&mut self, cx: &Context, it: &ast::Item) {
|
||||||
|
@ -986,7 +986,7 @@ impl LintPass for NonUppercaseStatics {
|
||||||
// ones (some scripts don't have a concept of
|
// ones (some scripts don't have a concept of
|
||||||
// upper/lowercase)
|
// upper/lowercase)
|
||||||
if s.get().chars().any(|c| c.is_lowercase()) {
|
if s.get().chars().any(|c| c.is_lowercase()) {
|
||||||
cx.span_lint(NON_UPPERCASE_STATICS, it.span,
|
cx.span_lint(NON_UPPER_CASE_GLOBALS, it.span,
|
||||||
format!("static constant `{}` should have an uppercase name \
|
format!("static constant `{}` should have an uppercase name \
|
||||||
such as `{}`",
|
such as `{}`",
|
||||||
s.get(), s.get().chars().map(|c| c.to_uppercase())
|
s.get(), s.get().chars().map(|c| c.to_uppercase())
|
||||||
|
@ -1003,7 +1003,7 @@ impl LintPass for NonUppercaseStatics {
|
||||||
(&ast::PatIdent(_, ref path1, _), Some(&def::DefConst(..))) => {
|
(&ast::PatIdent(_, ref path1, _), Some(&def::DefConst(..))) => {
|
||||||
let s = token::get_ident(path1.node);
|
let s = token::get_ident(path1.node);
|
||||||
if s.get().chars().any(|c| c.is_lowercase()) {
|
if s.get().chars().any(|c| c.is_lowercase()) {
|
||||||
cx.span_lint(NON_UPPERCASE_STATICS, path1.span,
|
cx.span_lint(NON_UPPER_CASE_GLOBALS, path1.span,
|
||||||
format!("static constant in pattern `{}` should have an uppercase \
|
format!("static constant in pattern `{}` should have an uppercase \
|
||||||
name such as `{}`",
|
name such as `{}`",
|
||||||
s.get(), s.get().chars().map(|c| c.to_uppercase())
|
s.get(), s.get().chars().map(|c| c.to_uppercase())
|
||||||
|
@ -1015,19 +1015,19 @@ impl LintPass for NonUppercaseStatics {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
declare_lint!(UNNECESSARY_PARENS, Warn,
|
declare_lint!(UNUSED_PARENS, Warn,
|
||||||
"`if`, `match`, `while` and `return` do not need parentheses")
|
"`if`, `match`, `while` and `return` do not need parentheses")
|
||||||
|
|
||||||
pub struct UnnecessaryParens;
|
pub struct UnusedParens;
|
||||||
|
|
||||||
impl UnnecessaryParens {
|
impl UnusedParens {
|
||||||
fn check_unnecessary_parens_core(&self, cx: &Context, value: &ast::Expr, msg: &str,
|
fn check_unnecessary_parens_core(&self, cx: &Context, value: &ast::Expr, msg: &str,
|
||||||
struct_lit_needs_parens: bool) {
|
struct_lit_needs_parens: bool) {
|
||||||
match value.node {
|
match value.node {
|
||||||
ast::ExprParen(ref inner) => {
|
ast::ExprParen(ref inner) => {
|
||||||
let necessary = struct_lit_needs_parens && contains_exterior_struct_lit(&**inner);
|
let necessary = struct_lit_needs_parens && contains_exterior_struct_lit(&**inner);
|
||||||
if !necessary {
|
if !necessary {
|
||||||
cx.span_lint(UNNECESSARY_PARENS, value.span,
|
cx.span_lint(UNUSED_PARENS, value.span,
|
||||||
format!("unnecessary parentheses around {}",
|
format!("unnecessary parentheses around {}",
|
||||||
msg).as_slice())
|
msg).as_slice())
|
||||||
}
|
}
|
||||||
|
@ -1071,9 +1071,9 @@ impl UnnecessaryParens {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl LintPass for UnnecessaryParens {
|
impl LintPass for UnusedParens {
|
||||||
fn get_lints(&self) -> LintArray {
|
fn get_lints(&self) -> LintArray {
|
||||||
lint_array!(UNNECESSARY_PARENS)
|
lint_array!(UNUSED_PARENS)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn check_expr(&mut self, cx: &Context, e: &ast::Expr) {
|
fn check_expr(&mut self, cx: &Context, e: &ast::Expr) {
|
||||||
|
@ -1108,14 +1108,14 @@ impl LintPass for UnnecessaryParens {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
declare_lint!(UNNECESSARY_IMPORT_BRACES, Allow,
|
declare_lint!(UNUSED_IMPORT_BRACES, Allow,
|
||||||
"unnecessary braces around an imported item")
|
"unnecessary braces around an imported item")
|
||||||
|
|
||||||
pub struct UnnecessaryImportBraces;
|
pub struct UnusedImportBraces;
|
||||||
|
|
||||||
impl LintPass for UnnecessaryImportBraces {
|
impl LintPass for UnusedImportBraces {
|
||||||
fn get_lints(&self) -> LintArray {
|
fn get_lints(&self) -> LintArray {
|
||||||
lint_array!(UNNECESSARY_IMPORT_BRACES)
|
lint_array!(UNUSED_IMPORT_BRACES)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn check_view_item(&mut self, cx: &Context, view_item: &ast::ViewItem) {
|
fn check_view_item(&mut self, cx: &Context, view_item: &ast::ViewItem) {
|
||||||
|
@ -1128,7 +1128,7 @@ impl LintPass for UnnecessaryImportBraces {
|
||||||
ast::PathListIdent {ref name, ..} => {
|
ast::PathListIdent {ref name, ..} => {
|
||||||
let m = format!("braces around {} is unnecessary",
|
let m = format!("braces around {} is unnecessary",
|
||||||
token::get_ident(*name).get());
|
token::get_ident(*name).get());
|
||||||
cx.span_lint(UNNECESSARY_IMPORT_BRACES, view_item.span,
|
cx.span_lint(UNUSED_IMPORT_BRACES, view_item.span,
|
||||||
m.as_slice());
|
m.as_slice());
|
||||||
},
|
},
|
||||||
_ => ()
|
_ => ()
|
||||||
|
@ -1167,21 +1167,21 @@ impl LintPass for UnusedUnsafe {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
declare_lint!(UNSAFE_BLOCK, Allow,
|
declare_lint!(UNSAFE_BLOCKS, Allow,
|
||||||
"usage of an `unsafe` block")
|
"usage of an `unsafe` block")
|
||||||
|
|
||||||
pub struct UnsafeBlock;
|
pub struct UnsafeBlocks;
|
||||||
|
|
||||||
impl LintPass for UnsafeBlock {
|
impl LintPass for UnsafeBlocks {
|
||||||
fn get_lints(&self) -> LintArray {
|
fn get_lints(&self) -> LintArray {
|
||||||
lint_array!(UNSAFE_BLOCK)
|
lint_array!(UNSAFE_BLOCKS)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn check_expr(&mut self, cx: &Context, e: &ast::Expr) {
|
fn check_expr(&mut self, cx: &Context, e: &ast::Expr) {
|
||||||
match e.node {
|
match e.node {
|
||||||
// Don't warn about generated blocks, that'll just pollute the output.
|
// Don't warn about generated blocks, that'll just pollute the output.
|
||||||
ast::ExprBlock(ref blk) if blk.rules == ast::UnsafeBlock(ast::UserProvided) => {
|
ast::ExprBlock(ref blk) if blk.rules == ast::UnsafeBlock(ast::UserProvided) => {
|
||||||
cx.span_lint(UNSAFE_BLOCK, blk.span, "usage of an `unsafe` block");
|
cx.span_lint(UNSAFE_BLOCKS, blk.span, "usage of an `unsafe` block");
|
||||||
}
|
}
|
||||||
_ => ()
|
_ => ()
|
||||||
}
|
}
|
||||||
|
@ -1266,14 +1266,14 @@ impl LintPass for UnusedMut {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
declare_lint!(UNNECESSARY_ALLOCATION, Warn,
|
declare_lint!(UNUSED_ALLOCATION, Warn,
|
||||||
"detects unnecessary allocations that can be eliminated")
|
"detects unnecessary allocations that can be eliminated")
|
||||||
|
|
||||||
pub struct UnnecessaryAllocation;
|
pub struct UnusedAllocation;
|
||||||
|
|
||||||
impl LintPass for UnnecessaryAllocation {
|
impl LintPass for UnusedAllocation {
|
||||||
fn get_lints(&self) -> LintArray {
|
fn get_lints(&self) -> LintArray {
|
||||||
lint_array!(UNNECESSARY_ALLOCATION)
|
lint_array!(UNUSED_ALLOCATION)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn check_expr(&mut self, cx: &Context, e: &ast::Expr) {
|
fn check_expr(&mut self, cx: &Context, e: &ast::Expr) {
|
||||||
|
@ -1288,11 +1288,11 @@ impl LintPass for UnnecessaryAllocation {
|
||||||
ty::AdjustDerefRef(ty::AutoDerefRef { ref autoref, .. }) => {
|
ty::AdjustDerefRef(ty::AutoDerefRef { ref autoref, .. }) => {
|
||||||
match autoref {
|
match autoref {
|
||||||
&Some(ty::AutoPtr(_, ast::MutImmutable, None)) => {
|
&Some(ty::AutoPtr(_, ast::MutImmutable, None)) => {
|
||||||
cx.span_lint(UNNECESSARY_ALLOCATION, e.span,
|
cx.span_lint(UNUSED_ALLOCATION, e.span,
|
||||||
"unnecessary allocation, use & instead");
|
"unnecessary allocation, use & instead");
|
||||||
}
|
}
|
||||||
&Some(ty::AutoPtr(_, ast::MutMutable, None)) => {
|
&Some(ty::AutoPtr(_, ast::MutMutable, None)) => {
|
||||||
cx.span_lint(UNNECESSARY_ALLOCATION, e.span,
|
cx.span_lint(UNUSED_ALLOCATION, e.span,
|
||||||
"unnecessary allocation, use &mut instead");
|
"unnecessary allocation, use &mut instead");
|
||||||
}
|
}
|
||||||
_ => ()
|
_ => ()
|
||||||
|
@ -1306,7 +1306,7 @@ impl LintPass for UnnecessaryAllocation {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
declare_lint!(MISSING_DOC, Allow,
|
declare_lint!(MISSING_DOCS, Allow,
|
||||||
"detects missing documentation for public members")
|
"detects missing documentation for public members")
|
||||||
|
|
||||||
pub struct MissingDoc {
|
pub struct MissingDoc {
|
||||||
|
@ -1358,7 +1358,7 @@ impl MissingDoc {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
if !has_doc {
|
if !has_doc {
|
||||||
cx.span_lint(MISSING_DOC, sp,
|
cx.span_lint(MISSING_DOCS, sp,
|
||||||
format!("missing documentation for {}", desc).as_slice());
|
format!("missing documentation for {}", desc).as_slice());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1366,7 +1366,7 @@ impl MissingDoc {
|
||||||
|
|
||||||
impl LintPass for MissingDoc {
|
impl LintPass for MissingDoc {
|
||||||
fn get_lints(&self) -> LintArray {
|
fn get_lints(&self) -> LintArray {
|
||||||
lint_array!(MISSING_DOC)
|
lint_array!(MISSING_DOCS)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn enter_lint_attrs(&mut self, _: &Context, attrs: &[ast::Attribute]) {
|
fn enter_lint_attrs(&mut self, _: &Context, attrs: &[ast::Attribute]) {
|
||||||
|
@ -1569,26 +1569,26 @@ impl LintPass for Stability {
|
||||||
declare_lint!(pub UNUSED_IMPORTS, Warn,
|
declare_lint!(pub UNUSED_IMPORTS, Warn,
|
||||||
"imports that are never used")
|
"imports that are never used")
|
||||||
|
|
||||||
declare_lint!(pub UNUSED_EXTERN_CRATE, Allow,
|
declare_lint!(pub UNUSED_EXTERN_CRATES, Allow,
|
||||||
"extern crates that are never used")
|
"extern crates that are never used")
|
||||||
|
|
||||||
declare_lint!(pub UNNECESSARY_QUALIFICATION, Allow,
|
declare_lint!(pub UNUSED_QUALIFICATIONS, Allow,
|
||||||
"detects unnecessarily qualified names")
|
"detects unnecessarily qualified names")
|
||||||
|
|
||||||
declare_lint!(pub UNRECOGNIZED_LINT, Warn,
|
declare_lint!(pub UNKNOWN_LINTS, Warn,
|
||||||
"unrecognized lint attribute")
|
"unrecognized lint attribute")
|
||||||
|
|
||||||
declare_lint!(pub UNUSED_VARIABLE, Warn,
|
declare_lint!(pub UNUSED_VARIABLES, Warn,
|
||||||
"detect variables which are not used in any way")
|
"detect variables which are not used in any way")
|
||||||
|
|
||||||
declare_lint!(pub DEAD_ASSIGNMENT, Warn,
|
declare_lint!(pub UNUSED_ASSIGNMENTS, Warn,
|
||||||
"detect assignments that will never be read")
|
"detect assignments that will never be read")
|
||||||
|
|
||||||
declare_lint!(pub DEAD_CODE, Warn,
|
declare_lint!(pub DEAD_CODE, Warn,
|
||||||
"detect piece of code that will never be used")
|
"detect unused, unexported items")
|
||||||
|
|
||||||
declare_lint!(pub UNREACHABLE_CODE, Warn,
|
declare_lint!(pub UNREACHABLE_CODE, Warn,
|
||||||
"detects unreachable code")
|
"detects unreachable code paths")
|
||||||
|
|
||||||
declare_lint!(pub WARNINGS, Warn,
|
declare_lint!(pub WARNINGS, Warn,
|
||||||
"mass-change the level for lints which produce warnings")
|
"mass-change the level for lints which produce warnings")
|
||||||
|
@ -1596,13 +1596,13 @@ declare_lint!(pub WARNINGS, Warn,
|
||||||
declare_lint!(pub UNKNOWN_FEATURES, Deny,
|
declare_lint!(pub UNKNOWN_FEATURES, Deny,
|
||||||
"unknown features found in crate-level #[feature] directives")
|
"unknown features found in crate-level #[feature] directives")
|
||||||
|
|
||||||
declare_lint!(pub UNKNOWN_CRATE_TYPE, Deny,
|
declare_lint!(pub UNKNOWN_CRATE_TYPES, Deny,
|
||||||
"unknown crate type found in #[crate_type] directive")
|
"unknown crate type found in #[crate_type] directive")
|
||||||
|
|
||||||
declare_lint!(pub VARIANT_SIZE_DIFFERENCE, Allow,
|
declare_lint!(pub VARIANT_SIZE_DIFFERENCES, Allow,
|
||||||
"detects enums with widely varying variant sizes")
|
"detects enums with widely varying variant sizes")
|
||||||
|
|
||||||
declare_lint!(pub TRANSMUTE_FAT_PTR, Allow,
|
declare_lint!(pub FAT_PTR_TRANSMUTES, Allow,
|
||||||
"detects transmutes of fat pointers")
|
"detects transmutes of fat pointers")
|
||||||
|
|
||||||
/// Does nothing as a lint pass, but registers some `Lint`s
|
/// Does nothing as a lint pass, but registers some `Lint`s
|
||||||
|
@ -1613,17 +1613,18 @@ impl LintPass for HardwiredLints {
|
||||||
fn get_lints(&self) -> LintArray {
|
fn get_lints(&self) -> LintArray {
|
||||||
lint_array!(
|
lint_array!(
|
||||||
UNUSED_IMPORTS,
|
UNUSED_IMPORTS,
|
||||||
UNUSED_EXTERN_CRATE,
|
UNUSED_EXTERN_CRATES,
|
||||||
UNNECESSARY_QUALIFICATION,
|
UNUSED_QUALIFICATIONS,
|
||||||
UNRECOGNIZED_LINT,
|
UNKNOWN_LINTS,
|
||||||
UNUSED_VARIABLE,
|
UNUSED_VARIABLES,
|
||||||
DEAD_ASSIGNMENT,
|
UNUSED_ASSIGNMENTS,
|
||||||
DEAD_CODE,
|
DEAD_CODE,
|
||||||
UNREACHABLE_CODE,
|
UNREACHABLE_CODE,
|
||||||
WARNINGS,
|
WARNINGS,
|
||||||
UNKNOWN_FEATURES,
|
UNKNOWN_FEATURES,
|
||||||
UNKNOWN_CRATE_TYPE,
|
UNKNOWN_CRATE_TYPES,
|
||||||
VARIANT_SIZE_DIFFERENCE
|
VARIANT_SIZE_DIFFERENCES,
|
||||||
|
FAT_PTR_TRANSMUTES
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -63,7 +63,7 @@ pub struct LintStore {
|
||||||
passes: Option<Vec<LintPassObject>>,
|
passes: Option<Vec<LintPassObject>>,
|
||||||
|
|
||||||
/// Lints indexed by name.
|
/// Lints indexed by name.
|
||||||
by_name: HashMap<String, LintId>,
|
by_name: HashMap<String, TargetLint>,
|
||||||
|
|
||||||
/// Current levels of each lint, and where they were set.
|
/// Current levels of each lint, and where they were set.
|
||||||
levels: HashMap<LintId, LevelSource>,
|
levels: HashMap<LintId, LevelSource>,
|
||||||
|
@ -73,6 +73,15 @@ pub struct LintStore {
|
||||||
lint_groups: HashMap<&'static str, (Vec<LintId>, bool)>,
|
lint_groups: HashMap<&'static str, (Vec<LintId>, bool)>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// The targed of the `by_name` map, which accounts for renaming/deprecation.
|
||||||
|
enum TargetLint {
|
||||||
|
/// A direct lint target
|
||||||
|
Id(LintId),
|
||||||
|
|
||||||
|
/// Temporary renaming, used for easing migration pain; see #16545
|
||||||
|
Renamed(String, LintId),
|
||||||
|
}
|
||||||
|
|
||||||
impl LintStore {
|
impl LintStore {
|
||||||
fn get_level_source(&self, lint: LintId) -> LevelSource {
|
fn get_level_source(&self, lint: LintId) -> LevelSource {
|
||||||
match self.levels.find(&lint) {
|
match self.levels.find(&lint) {
|
||||||
|
@ -115,7 +124,7 @@ impl LintStore {
|
||||||
self.lints.push((*lint, from_plugin));
|
self.lints.push((*lint, from_plugin));
|
||||||
|
|
||||||
let id = LintId::of(*lint);
|
let id = LintId::of(*lint);
|
||||||
if !self.by_name.insert(lint.name_lower(), id) {
|
if !self.by_name.insert(lint.name_lower(), Id(id)) {
|
||||||
let msg = format!("duplicate specification of lint {}", lint.name_lower());
|
let msg = format!("duplicate specification of lint {}", lint.name_lower());
|
||||||
match (sess, from_plugin) {
|
match (sess, from_plugin) {
|
||||||
// We load builtin lints first, so a duplicate is a compiler bug.
|
// We load builtin lints first, so a duplicate is a compiler bug.
|
||||||
|
@ -154,6 +163,14 @@ impl LintStore {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn register_renamed(&mut self, old_name: &str, new_name: &str) {
|
||||||
|
let target = match self.by_name.find_equiv(&new_name) {
|
||||||
|
Some(&Id(lint_id)) => lint_id.clone(),
|
||||||
|
_ => fail!("invalid lint renaming of {} to {}", old_name, new_name)
|
||||||
|
};
|
||||||
|
self.by_name.insert(old_name.to_string(), Renamed(new_name.to_string(), target));
|
||||||
|
}
|
||||||
|
|
||||||
pub fn register_builtin(&mut self, sess: Option<&Session>) {
|
pub fn register_builtin(&mut self, sess: Option<&Session>) {
|
||||||
macro_rules! add_builtin ( ( $sess:ident, $($name:ident),*, ) => (
|
macro_rules! add_builtin ( ( $sess:ident, $($name:ident),*, ) => (
|
||||||
{$(
|
{$(
|
||||||
|
@ -175,20 +192,20 @@ impl LintStore {
|
||||||
HardwiredLints,
|
HardwiredLints,
|
||||||
WhileTrue,
|
WhileTrue,
|
||||||
UnusedCasts,
|
UnusedCasts,
|
||||||
CTypes,
|
ImproperCTypes,
|
||||||
HeapMemory,
|
BoxPointers,
|
||||||
UnusedAttribute,
|
UnusedAttributes,
|
||||||
PathStatement,
|
PathStatements,
|
||||||
UnusedResult,
|
UnusedResults,
|
||||||
NonCamelCaseTypes,
|
NonCamelCaseTypes,
|
||||||
NonSnakeCase,
|
NonSnakeCase,
|
||||||
NonUppercaseStatics,
|
NonUpperCaseGlobals,
|
||||||
UnnecessaryParens,
|
UnusedParens,
|
||||||
UnnecessaryImportBraces,
|
UnusedImportBraces,
|
||||||
UnusedUnsafe,
|
UnusedUnsafe,
|
||||||
UnsafeBlock,
|
UnsafeBlocks,
|
||||||
UnusedMut,
|
UnusedMut,
|
||||||
UnnecessaryAllocation,
|
UnusedAllocation,
|
||||||
Stability,
|
Stability,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -199,21 +216,68 @@ impl LintStore {
|
||||||
)
|
)
|
||||||
|
|
||||||
add_lint_group!(sess, "bad_style",
|
add_lint_group!(sess, "bad_style",
|
||||||
NON_CAMEL_CASE_TYPES, NON_SNAKE_CASE, NON_UPPERCASE_STATICS)
|
NON_CAMEL_CASE_TYPES, NON_SNAKE_CASE, NON_UPPER_CASE_GLOBALS)
|
||||||
|
|
||||||
add_lint_group!(sess, "unused",
|
add_lint_group!(sess, "unused",
|
||||||
UNUSED_IMPORTS, UNUSED_VARIABLE, DEAD_ASSIGNMENT, DEAD_CODE,
|
UNUSED_IMPORTS, UNUSED_VARIABLES, UNUSED_ASSIGNMENTS, DEAD_CODE,
|
||||||
UNUSED_MUT, UNREACHABLE_CODE, UNUSED_EXTERN_CRATE, UNUSED_MUST_USE,
|
UNUSED_MUT, UNREACHABLE_CODE, UNUSED_EXTERN_CRATES, UNUSED_MUST_USE,
|
||||||
UNUSED_UNSAFE, UNUSED_RESULT, PATH_STATEMENT)
|
UNUSED_UNSAFE, UNUSED_RESULTS, PATH_STATEMENTS)
|
||||||
|
|
||||||
// We have one lint pass defined in this module.
|
// We have one lint pass defined in this module.
|
||||||
self.register_pass(sess, false, box GatherNodeLevels as LintPassObject);
|
self.register_pass(sess, false, box GatherNodeLevels as LintPassObject);
|
||||||
|
|
||||||
|
// Insert temporary renamings for a one-time deprecation (#16545)
|
||||||
|
self.register_renamed("unnecessary_typecast", "unused_typecasts");
|
||||||
|
self.register_renamed("unsigned_negate", "unsigned_negation");
|
||||||
|
self.register_renamed("type_limits", "unused_comparisons");
|
||||||
|
self.register_renamed("type_overflow", "overflowing_literals");
|
||||||
|
self.register_renamed("ctypes", "improper_ctypes");
|
||||||
|
self.register_renamed("owned_heap_memory", "box_pointers");
|
||||||
|
self.register_renamed("unused_attribute", "unused_attributes");
|
||||||
|
self.register_renamed("path_statement", "path_statements");
|
||||||
|
self.register_renamed("unused_result", "unused_results");
|
||||||
|
self.register_renamed("non_uppercase_statics", "non_upper_case_globals");
|
||||||
|
self.register_renamed("unnecessary_parens", "unused_parens");
|
||||||
|
self.register_renamed("unnecessary_import_braces", "unused_import_braces");
|
||||||
|
self.register_renamed("unsafe_block", "unsafe_blocks");
|
||||||
|
self.register_renamed("unnecessary_allocation", "unused_allocation");
|
||||||
|
self.register_renamed("missing_doc", "missing_docs");
|
||||||
|
self.register_renamed("unused_extern_crate", "unused_extern_crates");
|
||||||
|
self.register_renamed("unnecessary_qualification", "unused_qualifications");
|
||||||
|
self.register_renamed("unrecognized_lint", "unknown_lints");
|
||||||
|
self.register_renamed("unused_variable", "unused_variables");
|
||||||
|
self.register_renamed("dead_assignment", "unused_assignments");
|
||||||
|
self.register_renamed("unknown_crate_type", "unknown_crate_types");
|
||||||
|
self.register_renamed("variant_size_difference", "variant_size_differences");
|
||||||
|
self.register_renamed("transmute_fat_ptr", "fat_ptr_transmutes");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#[allow(unused_variable)]
|
||||||
|
fn find_lint(&self, lint_name: &str, sess: &Session, span: Option<Span>)
|
||||||
|
-> Option<LintId>
|
||||||
|
{
|
||||||
|
match self.by_name.find_equiv(&lint_name) {
|
||||||
|
Some(&Id(lint_id)) => Some(lint_id),
|
||||||
|
Some(&Renamed(ref new_name, lint_id)) => {
|
||||||
|
// NOTE(stage0): add the following code after the next snapshot
|
||||||
|
|
||||||
|
// let warning = format!("lint {} has been renamed to {}",
|
||||||
|
// lint_name, new_name);
|
||||||
|
// match span {
|
||||||
|
// Some(span) => sess.span_warn(span, warning.as_slice()),
|
||||||
|
// None => sess.warn(warning.as_slice()),
|
||||||
|
// };
|
||||||
|
Some(lint_id)
|
||||||
|
}
|
||||||
|
None => None
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn process_command_line(&mut self, sess: &Session) {
|
pub fn process_command_line(&mut self, sess: &Session) {
|
||||||
for &(ref lint_name, level) in sess.opts.lint_opts.iter() {
|
for &(ref lint_name, level) in sess.opts.lint_opts.iter() {
|
||||||
match self.by_name.find_equiv(&lint_name.as_slice()) {
|
match self.find_lint(lint_name.as_slice(), sess, None) {
|
||||||
Some(&lint_id) => self.set_level(lint_id, (level, CommandLine)),
|
Some(lint_id) => self.set_level(lint_id, (level, CommandLine)),
|
||||||
None => {
|
None => {
|
||||||
match self.lint_groups.iter().map(|(&x, pair)| (x, pair.ref0().clone()))
|
match self.lint_groups.iter().map(|(&x, pair)| (x, pair.ref0().clone()))
|
||||||
.collect::<HashMap<&'static str, Vec<LintId>>>()
|
.collect::<HashMap<&'static str, Vec<LintId>>>()
|
||||||
|
@ -421,8 +485,8 @@ impl<'a, 'tcx> Context<'a, 'tcx> {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
Ok((lint_name, level, span)) => {
|
Ok((lint_name, level, span)) => {
|
||||||
match self.lints.by_name.find_equiv(&lint_name.get()) {
|
match self.lints.find_lint(lint_name.get(), &self.tcx.sess, Some(span)) {
|
||||||
Some(&lint_id) => vec![(lint_id, level, span)],
|
Some(lint_id) => vec![(lint_id, level, span)],
|
||||||
None => {
|
None => {
|
||||||
match self.lints.lint_groups.find_equiv(&lint_name.get()) {
|
match self.lints.lint_groups.find_equiv(&lint_name.get()) {
|
||||||
Some(&(ref v, _)) => v.iter()
|
Some(&(ref v, _)) => v.iter()
|
||||||
|
@ -430,7 +494,7 @@ impl<'a, 'tcx> Context<'a, 'tcx> {
|
||||||
(*lint_id, level, span))
|
(*lint_id, level, span))
|
||||||
.collect(),
|
.collect(),
|
||||||
None => {
|
None => {
|
||||||
self.span_lint(builtin::UNRECOGNIZED_LINT, span,
|
self.span_lint(builtin::UNKNOWN_LINTS, span,
|
||||||
format!("unknown `{}` attribute: `{}`",
|
format!("unknown `{}` attribute: `{}`",
|
||||||
level.as_str(), lint_name).as_slice());
|
level.as_str(), lint_name).as_slice());
|
||||||
continue;
|
continue;
|
||||||
|
@ -713,7 +777,7 @@ impl LintPass for GatherNodeLevels {
|
||||||
fn check_item(&mut self, cx: &Context, it: &ast::Item) {
|
fn check_item(&mut self, cx: &Context, it: &ast::Item) {
|
||||||
match it.node {
|
match it.node {
|
||||||
ast::ItemEnum(..) => {
|
ast::ItemEnum(..) => {
|
||||||
let lint_id = LintId::of(builtin::VARIANT_SIZE_DIFFERENCE);
|
let lint_id = LintId::of(builtin::VARIANT_SIZE_DIFFERENCES);
|
||||||
let lvlsrc = cx.lints.get_level_source(lint_id);
|
let lvlsrc = cx.lints.get_level_source(lint_id);
|
||||||
match lvlsrc {
|
match lvlsrc {
|
||||||
(lvl, _) if lvl != Allow => {
|
(lvl, _) if lvl != Allow => {
|
||||||
|
|
|
@ -1629,11 +1629,11 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
|
||||||
};
|
};
|
||||||
|
|
||||||
if is_assigned {
|
if is_assigned {
|
||||||
self.ir.tcx.sess.add_lint(lint::builtin::UNUSED_VARIABLE, id, sp,
|
self.ir.tcx.sess.add_lint(lint::builtin::UNUSED_VARIABLES, id, sp,
|
||||||
format!("variable `{}` is assigned to, but never used",
|
format!("variable `{}` is assigned to, but never used",
|
||||||
*name));
|
*name));
|
||||||
} else {
|
} else {
|
||||||
self.ir.tcx.sess.add_lint(lint::builtin::UNUSED_VARIABLE, id, sp,
|
self.ir.tcx.sess.add_lint(lint::builtin::UNUSED_VARIABLES, id, sp,
|
||||||
format!("unused variable: `{}`", *name));
|
format!("unused variable: `{}`", *name));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1651,7 +1651,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
|
||||||
if self.live_on_exit(ln, var).is_none() {
|
if self.live_on_exit(ln, var).is_none() {
|
||||||
let r = self.should_warn(var);
|
let r = self.should_warn(var);
|
||||||
for name in r.iter() {
|
for name in r.iter() {
|
||||||
self.ir.tcx.sess.add_lint(lint::builtin::DEAD_ASSIGNMENT, id, sp,
|
self.ir.tcx.sess.add_lint(lint::builtin::UNUSED_ASSIGNMENTS, id, sp,
|
||||||
format!("value assigned to `{}` is never read", *name));
|
format!("value assigned to `{}` is never read", *name));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5232,7 +5232,7 @@ impl<'a> Resolver<'a> {
|
||||||
match (def, unqualified_def) {
|
match (def, unqualified_def) {
|
||||||
(Some((ref d, _)), Some((ref ud, _))) if *d == *ud => {
|
(Some((ref d, _)), Some((ref ud, _))) if *d == *ud => {
|
||||||
self.session
|
self.session
|
||||||
.add_lint(lint::builtin::UNNECESSARY_QUALIFICATION,
|
.add_lint(lint::builtin::UNUSED_QUALIFICATIONS,
|
||||||
id,
|
id,
|
||||||
path.span,
|
path.span,
|
||||||
"unnecessary qualification".to_string());
|
"unnecessary qualification".to_string());
|
||||||
|
@ -6125,7 +6125,7 @@ impl<'a> Resolver<'a> {
|
||||||
match self.session.cstore.find_extern_mod_stmt_cnum(id)
|
match self.session.cstore.find_extern_mod_stmt_cnum(id)
|
||||||
{
|
{
|
||||||
Some(crate_num) => if !self.used_crates.contains(&crate_num) {
|
Some(crate_num) => if !self.used_crates.contains(&crate_num) {
|
||||||
self.session.add_lint(lint::builtin::UNUSED_EXTERN_CRATE,
|
self.session.add_lint(lint::builtin::UNUSED_EXTERN_CRATES,
|
||||||
id,
|
id,
|
||||||
vi.span,
|
vi.span,
|
||||||
"unused extern crate".to_string());
|
"unused extern crate".to_string());
|
||||||
|
|
|
@ -2078,7 +2078,7 @@ fn enum_variant_size_lint(ccx: &CrateContext, enum_def: &ast::EnumDef, sp: Span,
|
||||||
let mut sizes = Vec::new(); // does no allocation if no pushes, thankfully
|
let mut sizes = Vec::new(); // does no allocation if no pushes, thankfully
|
||||||
|
|
||||||
let levels = ccx.tcx().node_lint_levels.borrow();
|
let levels = ccx.tcx().node_lint_levels.borrow();
|
||||||
let lint_id = lint::LintId::of(lint::builtin::VARIANT_SIZE_DIFFERENCE);
|
let lint_id = lint::LintId::of(lint::builtin::VARIANT_SIZE_DIFFERENCES);
|
||||||
let lvlsrc = match levels.find(&(id, lint_id)) {
|
let lvlsrc = match levels.find(&(id, lint_id)) {
|
||||||
None | Some(&(lint::Allow, _)) => return,
|
None | Some(&(lint::Allow, _)) => return,
|
||||||
Some(&lvlsrc) => lvlsrc,
|
Some(&lvlsrc) => lvlsrc,
|
||||||
|
@ -2115,7 +2115,7 @@ fn enum_variant_size_lint(ccx: &CrateContext, enum_def: &ast::EnumDef, sp: Span,
|
||||||
if largest > slargest * 3 && slargest > 0 {
|
if largest > slargest * 3 && slargest > 0 {
|
||||||
// Use lint::raw_emit_lint rather than sess.add_lint because the lint-printing
|
// Use lint::raw_emit_lint rather than sess.add_lint because the lint-printing
|
||||||
// pass for the latter already ran.
|
// pass for the latter already ran.
|
||||||
lint::raw_emit_lint(&ccx.tcx().sess, lint::builtin::VARIANT_SIZE_DIFFERENCE,
|
lint::raw_emit_lint(&ccx.tcx().sess, lint::builtin::VARIANT_SIZE_DIFFERENCES,
|
||||||
lvlsrc, Some(sp),
|
lvlsrc, Some(sp),
|
||||||
format!("enum variant is more than three times larger \
|
format!("enum variant is more than three times larger \
|
||||||
({} bytes) than the next largest (ignoring padding)",
|
({} bytes) than the next largest (ignoring padding)",
|
||||||
|
|
|
@ -122,7 +122,7 @@ pub fn check_intrinsics(ccx: &CrateContext) {
|
||||||
if ty::type_is_fat_ptr(ccx.tcx(), transmute_restriction.to) ||
|
if ty::type_is_fat_ptr(ccx.tcx(), transmute_restriction.to) ||
|
||||||
ty::type_is_fat_ptr(ccx.tcx(), transmute_restriction.from) {
|
ty::type_is_fat_ptr(ccx.tcx(), transmute_restriction.from) {
|
||||||
ccx.sess()
|
ccx.sess()
|
||||||
.add_lint(::lint::builtin::TRANSMUTE_FAT_PTR,
|
.add_lint(::lint::builtin::FAT_PTR_TRANSMUTES,
|
||||||
transmute_restriction.id,
|
transmute_restriction.id,
|
||||||
transmute_restriction.span,
|
transmute_restriction.span,
|
||||||
format!("Transmuting fat pointer types; {} to {}.\
|
format!("Transmuting fat pointer types; {} to {}.\
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue