mirror of
https://github.com/rust-lang/rust.git
synced 2025-02-09 13:33:43 +00:00
commit
7a870ad46b
@ -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! {
|
||||
|
10
src/attrs.rs
10
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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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! {
|
||||
|
@ -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! {
|
||||
|
@ -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! {
|
||||
|
@ -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;
|
||||
|
@ -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};
|
||||
|
@ -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<TraitItem>]) {
|
||||
}
|
||||
|
||||
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 }
|
||||
|
@ -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;
|
||||
|
@ -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<RefLt>);
|
||||
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));
|
||||
|
@ -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!(
|
||||
|
@ -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" {
|
||||
|
@ -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};
|
||||
|
@ -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,
|
||||
|
@ -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! {
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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! {
|
||||
|
@ -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<Ty>]>
|
||||
}
|
||||
}
|
||||
|
||||
#[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() {
|
||||
|
@ -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,
|
||||
|
11
src/utils.rs
11
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.
|
||||
|
Loading…
Reference in New Issue
Block a user