diff --git a/src/approx_const.rs b/src/approx_const.rs index 3c39b79885c..cfd646765c9 100644 --- a/src/approx_const.rs +++ b/src/approx_const.rs @@ -1,12 +1,8 @@ -use rustc::plugin::Registry; use rustc::lint::*; -use rustc::middle::const_eval::lookup_const_by_id; -use rustc::middle::def::*; use syntax::ast::*; -use syntax::ast_util::{is_comparison_binop, binop_to_string}; -use syntax::ptr::P; use syntax::codemap::Span; use std::f64::consts as f64; + use utils::span_lint; declare_lint! { diff --git a/src/attrs.rs b/src/attrs.rs index ef3320d2543..3e451ac5eda 100644 --- a/src/attrs.rs +++ b/src/attrs.rs @@ -1,11 +1,9 @@ -/// checks for attributes +//! checks for attributes -use rustc::plugin::Registry; use rustc::lint::*; use syntax::ast::*; -use syntax::ptr::P; -use syntax::codemap::{Span, ExpnInfo}; -use syntax::parse::token::InternedString; +use syntax::codemap::ExpnInfo; + use utils::{in_macro, match_path, span_lint}; declare_lint! { pub INLINE_ALWAYS, Warn, @@ -103,7 +101,7 @@ fn check_attrs(cx: &Context, info: Option<&ExpnInfo>, ident: &Ident, span_lint(cx, INLINE_ALWAYS, attr.span, &format!( "you have declared `#[inline(always)]` on `{}`. This \ is usually a bad idea. Are you sure?", - ident.name.as_str())); + ident.name)); } } } diff --git a/src/bit_mask.rs b/src/bit_mask.rs index 169975001b9..ec937dbab6c 100644 --- a/src/bit_mask.rs +++ b/src/bit_mask.rs @@ -1,11 +1,10 @@ -use rustc::plugin::Registry; use rustc::lint::*; use rustc::middle::const_eval::lookup_const_by_id; use rustc::middle::def::*; use syntax::ast::*; -use syntax::ast_util::{is_comparison_binop, binop_to_string}; -use syntax::ptr::P; +use syntax::ast_util::is_comparison_binop; use syntax::codemap::Span; + use utils::span_lint; declare_lint! { diff --git a/src/collapsible_if.rs b/src/collapsible_if.rs index 8a41f208938..0b6dfc19e6b 100644 --- a/src/collapsible_if.rs +++ b/src/collapsible_if.rs @@ -12,12 +12,10 @@ //! //! This lint is **warn** by default -use rustc::plugin::Registry; use rustc::lint::*; -use rustc::middle::def::*; use syntax::ast::*; -use syntax::ptr::P; -use syntax::codemap::{Span, Spanned, ExpnInfo}; +use syntax::codemap::{Spanned, ExpnInfo}; + use utils::{in_macro, span_help_and_lint, snippet, snippet_block}; declare_lint! { diff --git a/src/eq_op.rs b/src/eq_op.rs index 495696b810c..50b61e23356 100644 --- a/src/eq_op.rs +++ b/src/eq_op.rs @@ -3,6 +3,7 @@ use syntax::ast::*; use syntax::ast_util as ast_util; use syntax::ptr::P; use syntax::codemap as code; + use utils::span_lint; declare_lint! { diff --git a/src/eta_reduction.rs b/src/eta_reduction.rs index e0d4182081f..6712e787278 100644 --- a/src/eta_reduction.rs +++ b/src/eta_reduction.rs @@ -1,6 +1,5 @@ +use rustc::lint::*; use syntax::ast::*; -use rustc::lint::{Context, LintPass, LintArray, Lint, Level}; -use syntax::codemap::{Span, Spanned}; use syntax::print::pprust::expr_to_string; use utils::span_lint; diff --git a/src/identity_op.rs b/src/identity_op.rs index 964675b765e..18a475bb737 100644 --- a/src/identity_op.rs +++ b/src/identity_op.rs @@ -1,10 +1,7 @@ -use rustc::plugin::Registry; use rustc::lint::*; use rustc::middle::const_eval::lookup_const_by_id; use rustc::middle::def::*; use syntax::ast::*; -use syntax::ast_util::{is_comparison_binop, binop_to_string}; -use syntax::ptr::P; use syntax::codemap::Span; use utils::{span_lint, snippet}; diff --git a/src/len_zero.rs b/src/len_zero.rs index d5f3d1ad810..073dcea582d 100644 --- a/src/len_zero.rs +++ b/src/len_zero.rs @@ -1,14 +1,9 @@ -extern crate rustc_typeck as typeck; - -use std::rc::Rc; -use std::cell::RefCell; -use syntax::ptr::P; -use rustc::lint::{Context, LintPass, LintArray, Lint}; -use rustc::util::nodemap::DefIdMap; -use rustc::middle::ty::{self, TypeVariants, TypeAndMut, MethodTraitItemId, ImplOrTraitItemId}; -use rustc::middle::def::{DefTy, DefStruct, DefTrait}; -use syntax::codemap::{Span, Spanned}; +use rustc::lint::*; use syntax::ast::*; +use syntax::ptr::P; +use syntax::codemap::{Span, Spanned}; +use rustc::middle::ty::{self, MethodTraitItemId, ImplOrTraitItemId}; + use utils::{span_lint, walk_ptrs_ty, snippet}; declare_lint!(pub LEN_ZERO, Warn, @@ -55,7 +50,7 @@ fn check_trait_items(cx: &Context, item: &Item, trait_items: &[P]) { } if !trait_items.iter().any(|i| is_named_self(i, "is_empty")) { - //span_lint(cx, LEN_WITHOUT_IS_EMPTY, item.span, &format!("trait {}", item.ident.as_str())); + //span_lint(cx, LEN_WITHOUT_IS_EMPTY, item.span, &format!("trait {}", item.ident)); for i in trait_items { if is_named_self(i, "len") { span_lint(cx, LEN_WITHOUT_IS_EMPTY, i.span, @@ -122,7 +117,7 @@ fn has_is_empty(cx: &Context, expr: &Expr) -> bool { if let &MethodTraitItemId(def_id) = id { if let ty::MethodTraitItem(ref method) = cx.tcx.impl_or_trait_item(def_id) { - method.name.as_str() == "is_empty" + method.name == "is_empty" && method.fty.sig.skip_binder().inputs.len() == 1 } else { false } } else { false } diff --git a/src/lib.rs b/src/lib.rs index 01a2d65606c..c45227f88f2 100755 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,7 +1,6 @@ #![feature(plugin_registrar, box_syntax)] -#![feature(rustc_private, collections)] +#![feature(rustc_private, core, collections)] #![feature(str_split_at)] -#![allow(unused_imports, unknown_lints)] #[macro_use] extern crate syntax; @@ -9,6 +8,7 @@ extern crate syntax; extern crate rustc; // Only for the compile time checking of paths +extern crate core; extern crate collections; use rustc::plugin::Registry; diff --git a/src/lifetimes.rs b/src/lifetimes.rs index 0127822dbde..9d07df4a3ed 100644 --- a/src/lifetimes.rs +++ b/src/lifetimes.rs @@ -1,10 +1,10 @@ use syntax::ast::*; -use rustc::lint::{Context, LintPass, LintArray, Lint}; +use rustc::lint::*; use syntax::codemap::Span; -use syntax::visit::{Visitor, FnKind, walk_ty}; -use utils::{in_external_macro, span_lint}; +use syntax::visit::{Visitor, walk_ty}; use std::collections::HashSet; -use std::iter::FromIterator; + +use utils::{in_external_macro, span_lint}; declare_lint!(pub NEEDLESS_LIFETIMES, Warn, "using explicit lifetimes for references in function arguments when elision rules \ @@ -153,7 +153,7 @@ struct RefVisitor(Vec); impl RefVisitor { fn record(&mut self, lifetime: &Option) { if let &Some(ref lt) = lifetime { - if lt.name.as_str() == "'static" { + if lt.name == "'static" { self.0.push(Static); } else { self.0.push(Named(lt.name)); diff --git a/src/loops.rs b/src/loops.rs index 74015bdc6be..092b5ce1196 100644 --- a/src/loops.rs +++ b/src/loops.rs @@ -36,13 +36,12 @@ impl LintPass for LoopsPass { span_lint(cx, NEEDLESS_RANGE_LOOP, expr.span, &format!( "the loop variable `{}` is used to index `{}`. Consider using \ `for ({}, item) in {}.iter().enumerate()` or similar iterators.", - ident.node.name.as_str(), indexed.as_str(), - ident.node.name.as_str(), indexed.as_str())); + ident.node.name, indexed, ident.node.name, indexed)); } else { span_lint(cx, NEEDLESS_RANGE_LOOP, expr.span, &format!( "the loop variable `{}` is only used to index `{}`. \ Consider using `for item in &{}` or similar iterators.", - ident.node.name.as_str(), indexed.as_str(), indexed.as_str())); + ident.node.name, indexed, indexed)); } } } @@ -52,7 +51,7 @@ impl LintPass for LoopsPass { if let ExprMethodCall(ref method, _, ref args) = arg.node { // just the receiver, no arguments to iter() or iter_mut() if args.len() == 1 { - let method_name = method.node.name.as_str(); + let method_name = method.node.name; if method_name == "iter" { let object = snippet(cx, args[0].span, "_"); span_lint(cx, EXPLICIT_ITER_LOOP, expr.span, &format!( diff --git a/src/methods.rs b/src/methods.rs index 02b181a46e7..f2df736bebc 100644 --- a/src/methods.rs +++ b/src/methods.rs @@ -1,5 +1,5 @@ use syntax::ast::*; -use rustc::lint::{Context, LintPass, LintArray}; +use rustc::lint::*; use rustc::middle::ty; use utils::{span_lint, match_def_path, walk_ptrs_ty}; @@ -16,12 +16,19 @@ declare_lint!(pub STR_TO_STRING, Warn, declare_lint!(pub STRING_TO_STRING, Warn, "calling `String.to_string()` which is a no-op"); +#[allow(unused_imports)] impl LintPass for MethodsPass { fn get_lints(&self) -> LintArray { lint_array!(OPTION_UNWRAP_USED, RESULT_UNWRAP_USED, STR_TO_STRING, STRING_TO_STRING) } fn check_expr(&mut self, cx: &Context, expr: &Expr) { + { + // In case stuff gets moved around + use core::option::Option; + use core::result::Result; + use collections::string::String; + } if let ExprMethodCall(ref ident, _, ref args) = expr.node { let ref obj_ty = walk_ptrs_ty(cx.tcx.expr_ty(&*args[0])).sty; if ident.node.name == "unwrap" { diff --git a/src/misc.rs b/src/misc.rs index 091ea36f2f5..1fc41cf4862 100644 --- a/src/misc.rs +++ b/src/misc.rs @@ -1,11 +1,11 @@ +use rustc::lint::*; use syntax::ptr::P; use syntax::ast; use syntax::ast::*; use syntax::ast_util::{is_comparison_binop, binop_to_string}; -use syntax::visit::{FnKind}; -use rustc::lint::{Context, LintPass, LintArray, Lint, Level}; -use rustc::middle::ty; use syntax::codemap::{Span, Spanned}; +use syntax::visit::FnKind; +use rustc::middle::ty; use std::borrow::Cow; use utils::{match_path, snippet, snippet_block, span_lint, span_help_and_lint, walk_ptrs_ty}; diff --git a/src/mut_mut.rs b/src/mut_mut.rs index a3c40d06f90..fbcb70e17d3 100644 --- a/src/mut_mut.rs +++ b/src/mut_mut.rs @@ -1,8 +1,8 @@ -use syntax::ptr::P; +use rustc::lint::*; use syntax::ast::*; -use rustc::lint::{Context, LintPass, LintArray, Lint}; -use rustc::middle::ty::{TypeVariants, TypeAndMut, TyRef}; -use syntax::codemap::{BytePos, ExpnInfo, Span}; +use syntax::codemap::ExpnInfo; +use rustc::middle::ty::{TypeAndMut, TyRef}; + use utils::{in_macro, span_lint}; declare_lint!(pub MUT_MUT, Warn, diff --git a/src/needless_bool.rs b/src/needless_bool.rs index 2a4ed50b93d..18d98f1f063 100644 --- a/src/needless_bool.rs +++ b/src/needless_bool.rs @@ -2,14 +2,9 @@ //! //! This lint is **warn** by default -use rustc::plugin::Registry; use rustc::lint::*; -use rustc::middle::const_eval::lookup_const_by_id; -use rustc::middle::def::*; use syntax::ast::*; -use syntax::ast_util::{is_comparison_binop, binop_to_string}; -use syntax::ptr::P; -use syntax::codemap::Span; + use utils::{de_p, span_lint, snippet}; declare_lint! { diff --git a/src/ptr_arg.rs b/src/ptr_arg.rs index 85db4aa7b21..2748d187a4e 100644 --- a/src/ptr_arg.rs +++ b/src/ptr_arg.rs @@ -2,14 +2,10 @@ //! //! This lint is **warn** by default -use rustc::plugin::Registry; use rustc::lint::*; -use rustc::middle::const_eval::lookup_const_by_id; -use rustc::middle::def::*; use syntax::ast::*; -use syntax::ast_util::{is_comparison_binop, binop_to_string}; -use syntax::ptr::P; use syntax::codemap::Span; + use types::match_ty_unwrap; use utils::span_lint; diff --git a/src/returns.rs b/src/returns.rs index 94b9ec9650f..df0b93f301e 100644 --- a/src/returns.rs +++ b/src/returns.rs @@ -1,8 +1,7 @@ -use syntax::ast; +use rustc::lint::*; use syntax::ast::*; use syntax::codemap::{Span, Spanned}; use syntax::visit::FnKind; -use rustc::lint::{Context, LintPass, LintArray, Level}; use utils::{span_lint, snippet, match_path}; @@ -101,7 +100,7 @@ impl LintPass for ReturnPass { } fn check_fn(&mut self, cx: &Context, _: FnKind, _: &FnDecl, - block: &Block, _: Span, _: ast::NodeId) { + block: &Block, _: Span, _: NodeId) { self.check_block_return(cx, block); self.check_let_return(cx, block); } diff --git a/src/strings.rs b/src/strings.rs index 7b7bab49b5d..7981b785850 100644 --- a/src/strings.rs +++ b/src/strings.rs @@ -6,9 +6,9 @@ use rustc::lint::*; use rustc::middle::ty::TypeVariants::TyStruct; use syntax::ast::*; -use syntax::codemap::{Span, Spanned}; +use syntax::codemap::Spanned; + use eq_op::is_exp_equal; -use types::match_ty_unwrap; use utils::{match_def_path, span_lint, walk_ptrs_ty, get_parent_expr}; declare_lint! { diff --git a/src/types.rs b/src/types.rs index 53d8850c59d..aa5f1d13471 100644 --- a/src/types.rs +++ b/src/types.rs @@ -1,9 +1,9 @@ -use syntax::ptr::P; +use rustc::lint::*; use syntax::ast; use syntax::ast::*; +use syntax::ptr::P; use rustc::middle::ty; -use rustc::lint::{Context, LintPass, LintArray, Lint, Level}; -use syntax::codemap::{ExpnInfo, Span}; +use syntax::codemap::ExpnInfo; use utils::{in_macro, snippet, span_lint, span_help_and_lint}; @@ -40,6 +40,7 @@ pub fn match_ty_unwrap<'a>(ty: &'a Ty, segments: &[&str]) -> Option<&'a [P]> } } +#[allow(unused_imports)] impl LintPass for TypePass { fn get_lints(&self) -> LintArray { lint_array!(BOX_VEC, LINKEDLIST) @@ -62,10 +63,8 @@ impl LintPass for TypePass { // In case stuff gets moved around use collections::linked_list::LinkedList as DL1; use std::collections::linked_list::LinkedList as DL2; - use std::collections::linked_list::LinkedList as DL3; } let dlists = [vec!["std","collections","linked_list","LinkedList"], - vec!["std","collections","linked_list","LinkedList"], vec!["collections","linked_list","LinkedList"]]; for path in &dlists { if match_ty_unwrap(ty, &path[..]).is_some() { diff --git a/src/unicode.rs b/src/unicode.rs index 62b4a9dadf5..ab48fd1bef2 100644 --- a/src/unicode.rs +++ b/src/unicode.rs @@ -1,6 +1,7 @@ use rustc::lint::*; use syntax::ast::*; use syntax::codemap::{BytePos, Span}; + use utils::span_lint; declare_lint!{ pub ZERO_WIDTH_SPACE, Deny, diff --git a/src/utils.rs b/src/utils.rs index 67a89b067e6..47e3a3456d6 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -1,11 +1,10 @@ -use rustc::lint::{Context, Lint, Level}; -use syntax::ast::{DefId, Expr, Name, NodeId, Path}; +use rustc::lint::*; +use syntax::ast::*; use syntax::codemap::{ExpnInfo, Span}; use syntax::ptr::P; use rustc::ast_map::Node::NodeExpr; use rustc::middle::ty; -use std::borrow::{Cow, IntoCow}; -use std::convert::From; +use std::borrow::Cow; /// returns true if the macro that expanded the crate was outside of /// the current crate or was a compiler plugin @@ -35,14 +34,14 @@ pub fn in_external_macro(cx: &Context, span: Span) -> bool { /// `match_def_path(cx, id, &["core", "option", "Option"])` pub fn match_def_path(cx: &Context, def_id: DefId, path: &[&str]) -> bool { cx.tcx.with_path(def_id, |iter| iter.map(|elem| elem.name()) - .zip(path.iter()).all(|(nm, p)| &nm.as_str() == p)) + .zip(path.iter()).all(|(nm, p)| nm == p)) } /// match a Path against a slice of segment string literals, e.g. /// `match_path(path, &["std", "rt", "begin_unwind"])` pub fn match_path(path: &Path, segments: &[&str]) -> bool { path.segments.iter().rev().zip(segments.iter().rev()).all( - |(a,b)| &a.identifier.name.as_str() == b) + |(a, b)| &a.identifier.name == b) } /// convert a span to a code snippet if available, otherwise use default, e.g.