-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! {
-/// 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,
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));
}
}
}
-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! {
//!
//! 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! {
use syntax::ast_util as ast_util;
use syntax::ptr::P;
use syntax::codemap as code;
+
use utils::span_lint;
declare_lint! {
+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;
-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};
-extern crate rustc_typeck as typeck;
-
-use std::rc::Rc;
-use std::cell::RefCell;
+use rustc::lint::*;
+use syntax::ast::*;
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 syntax::ast::*;
+use rustc::middle::ty::{self, MethodTraitItemId, ImplOrTraitItemId};
+
use utils::{span_lint, walk_ptrs_ty, snippet};
declare_lint!(pub LEN_ZERO, Warn,
}
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,
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 }
#![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;
extern crate rustc;
// Only for the compile time checking of paths
+extern crate core;
extern crate collections;
use rustc::plugin::Registry;
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 \
impl RefVisitor {
fn record(&mut self, lifetime: &Option<Lifetime>) {
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));
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));
}
}
}
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!(
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};
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" {
+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};
lint_array!(TOPLEVEL_REF_ARG)
}
- fn check_fn(&mut self, cx: &Context, _: FnKind, decl: &FnDecl, _: &Block, _: Span, _: NodeId) {
+ fn check_fn(&mut self, cx: &Context, k: FnKind, decl: &FnDecl, _: &Block, _: Span, _: NodeId) {
+ if let FnKind::FkFnBlock = k {
+ // Does not apply to closures
+ return
+ }
for ref arg in &decl.inputs {
if let PatIdent(BindByRef(_), _, _) = arg.pat.node {
span_lint(cx,
-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,
//!
//! 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! {
//!
//! 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;
-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};
}
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);
}
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! {
-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};
}
}
+#[allow(unused_imports)]
impl LintPass for TypePass {
fn get_lints(&self) -> LintArray {
lint_array!(BOX_VEC, LINKEDLIST)
// 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() {
use rustc::lint::*;
use syntax::ast::*;
use syntax::codemap::{BytePos, Span};
+
use utils::span_lint;
declare_lint!{ pub ZERO_WIDTH_SPACE, Deny,
-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
/// `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.
fn main() {
let mut x = 0;
the_answer(x);
+ // Closures should not warn
+ let y = |ref x| { println!("{:?}", x) };
+ y(1u8);
println!("The answer is {}.", x);
}