mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-10 23:24:24 +00:00
commit
6f3f25878f
43 changed files with 136 additions and 129 deletions
|
@ -202,9 +202,9 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AssignOps {
|
|||
};
|
||||
|
||||
let mut visitor = ExprVisitor {
|
||||
assignee: assignee,
|
||||
assignee,
|
||||
counter: 0,
|
||||
cx: cx
|
||||
cx
|
||||
};
|
||||
|
||||
walk_expr(&mut visitor, e);
|
||||
|
@ -253,7 +253,7 @@ struct ExprVisitor<'a, 'tcx: 'a> {
|
|||
|
||||
impl<'a, 'tcx: 'a> Visitor<'tcx> for ExprVisitor<'a, 'tcx> {
|
||||
fn visit_expr(&mut self, expr: &'tcx hir::Expr) {
|
||||
if SpanlessEq::new(self.cx).ignore_fn().eq_expr(self.assignee, &expr) {
|
||||
if SpanlessEq::new(self.cx).ignore_fn().eq_expr(self.assignee, expr) {
|
||||
self.counter += 1;
|
||||
}
|
||||
|
||||
|
|
|
@ -96,7 +96,7 @@ pub struct BitMask {
|
|||
impl BitMask {
|
||||
pub fn new(verbose_bit_mask_threshold: u64) -> Self {
|
||||
Self {
|
||||
verbose_bit_mask_threshold: verbose_bit_mask_threshold,
|
||||
verbose_bit_mask_threshold,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,7 +28,7 @@ pub struct BlackListedName {
|
|||
impl BlackListedName {
|
||||
pub fn new(blacklist: Vec<String>) -> Self {
|
||||
Self {
|
||||
blacklist: blacklist,
|
||||
blacklist,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -124,7 +124,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for BlockInIfCondition {
|
|||
} else {
|
||||
let mut visitor = ExVisitor {
|
||||
found_block: None,
|
||||
cx: cx,
|
||||
cx,
|
||||
};
|
||||
walk_expr(&mut visitor, check);
|
||||
if let Some(block) = visitor.found_block {
|
||||
|
|
|
@ -69,7 +69,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NonminimalBool {
|
|||
_: Span,
|
||||
_: NodeId,
|
||||
) {
|
||||
NonminimalBoolVisitor { cx: cx }.visit_body(body)
|
||||
NonminimalBoolVisitor { cx }.visit_body(body)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -261,8 +261,8 @@ impl<'a, 'tcx, 'v> SuggestContext<'a, 'tcx, 'v> {
|
|||
// The boolean part of the return indicates whether some simplifications have been applied.
|
||||
fn suggest(cx: &LateContext, suggestion: &Bool, terminals: &[&Expr]) -> (String, bool) {
|
||||
let mut suggest_context = SuggestContext {
|
||||
terminals: terminals,
|
||||
cx: cx,
|
||||
terminals,
|
||||
cx,
|
||||
output: String::new(),
|
||||
simplified: false,
|
||||
};
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#![allow(cast_possible_truncation)]
|
||||
#![allow(float_cmp)]
|
||||
|
||||
use rustc::lint::LateContext;
|
||||
use rustc::hir::def::Def;
|
||||
|
@ -73,7 +74,7 @@ impl PartialEq for Constant {
|
|||
// we want `Fw32 == FwAny` and `FwAny == Fw64`, by transitivity we must have
|
||||
// `Fw32 == Fw64` so don’t compare them
|
||||
// mem::transmute is required to catch non-matching 0.0, -0.0, and NaNs
|
||||
unsafe { mem::transmute::<f64, u64>(l as f64) == mem::transmute::<f64, u64>(r as f64) }
|
||||
unsafe { mem::transmute::<f64, u64>(f64::from(l)) == mem::transmute::<f64, u64>(f64::from(r)) }
|
||||
},
|
||||
(&Constant::Bool(l), &Constant::Bool(r)) => l == r,
|
||||
(&Constant::Vec(ref l), &Constant::Vec(ref r)) | (&Constant::Tuple(ref l), &Constant::Tuple(ref r)) => l == r,
|
||||
|
@ -102,7 +103,7 @@ impl Hash for Constant {
|
|||
i.hash(state);
|
||||
},
|
||||
Constant::F32(f) => {
|
||||
unsafe { mem::transmute::<f64, u64>(f as f64) }.hash(state);
|
||||
unsafe { mem::transmute::<f64, u64>(f64::from(f)) }.hash(state);
|
||||
},
|
||||
Constant::F64(f) => {
|
||||
unsafe { mem::transmute::<f64, u64>(f) }.hash(state);
|
||||
|
@ -143,12 +144,12 @@ impl PartialOrd for Constant {
|
|||
}
|
||||
|
||||
/// parse a `LitKind` to a `Constant`
|
||||
pub fn lit_to_constant<'a, 'tcx>(lit: &LitKind, ty: Ty<'tcx>) -> Constant {
|
||||
pub fn lit_to_constant<'tcx>(lit: &LitKind, ty: Ty<'tcx>) -> Constant {
|
||||
use syntax::ast::*;
|
||||
|
||||
match *lit {
|
||||
LitKind::Str(ref is, _) => Constant::Str(is.to_string()),
|
||||
LitKind::Byte(b) => Constant::Int(b as u128),
|
||||
LitKind::Byte(b) => Constant::Int(u128::from(b)),
|
||||
LitKind::ByteStr(ref s) => Constant::Binary(Rc::clone(s)),
|
||||
LitKind::Char(c) => Constant::Char(c),
|
||||
LitKind::Int(n, _) => Constant::Int(n),
|
||||
|
@ -177,7 +178,7 @@ pub fn constant_simple(lcx: &LateContext, e: &Expr) -> Option<Constant> {
|
|||
constant(lcx, e).and_then(|(cst, res)| if res { None } else { Some(cst) })
|
||||
}
|
||||
|
||||
/// Creates a ConstEvalLateContext from the given LateContext and TypeckTables
|
||||
/// Creates a `ConstEvalLateContext` from the given `LateContext` and `TypeckTables`
|
||||
pub fn constant_context<'c, 'cc>(lcx: &LateContext<'c, 'cc>, tables: &'cc ty::TypeckTables<'cc>) -> ConstEvalLateContext<'c, 'cc> {
|
||||
ConstEvalLateContext {
|
||||
tcx: lcx.tcx,
|
||||
|
@ -215,7 +216,7 @@ impl<'c, 'cc> ConstEvalLateContext<'c, 'cc> {
|
|||
},
|
||||
ExprUnary(op, ref operand) => self.expr(operand).and_then(|o| match op {
|
||||
UnNot => self.constant_not(&o, self.tables.expr_ty(e)),
|
||||
UnNeg => self.constant_negate(o, self.tables.expr_ty(e)),
|
||||
UnNeg => self.constant_negate(&o, self.tables.expr_ty(e)),
|
||||
UnDeref => Some(o),
|
||||
}),
|
||||
ExprBinary(op, ref left, ref right) => self.binop(op, left, right),
|
||||
|
@ -240,9 +241,9 @@ impl<'c, 'cc> ConstEvalLateContext<'c, 'cc> {
|
|||
}
|
||||
}
|
||||
|
||||
fn constant_negate(&self, o: Constant, ty: ty::Ty) -> Option<Constant> {
|
||||
fn constant_negate(&self, o: &Constant, ty: ty::Ty) -> Option<Constant> {
|
||||
use self::Constant::*;
|
||||
match o {
|
||||
match *o {
|
||||
Int(value) => {
|
||||
let ity = match ty.sty {
|
||||
ty::TyInt(ity) => ity,
|
||||
|
@ -377,7 +378,7 @@ impl<'c, 'cc> ConstEvalLateContext<'c, 'cc> {
|
|||
BiSub => Some(Constant::F32(l - r)),
|
||||
BiMul => Some(Constant::F32(l * r)),
|
||||
BiDiv => Some(Constant::F32(l / r)),
|
||||
BiRem => Some(Constant::F32(l * r)),
|
||||
BiRem => Some(Constant::F32(l % r)),
|
||||
BiEq => Some(Constant::Bool(l == r)),
|
||||
BiNe => Some(Constant::Bool(l != r)),
|
||||
BiLt => Some(Constant::Bool(l < r)),
|
||||
|
@ -391,7 +392,7 @@ impl<'c, 'cc> ConstEvalLateContext<'c, 'cc> {
|
|||
BiSub => Some(Constant::F64(l - r)),
|
||||
BiMul => Some(Constant::F64(l * r)),
|
||||
BiDiv => Some(Constant::F64(l / r)),
|
||||
BiRem => Some(Constant::F64(l * r)),
|
||||
BiRem => Some(Constant::F64(l % r)),
|
||||
BiEq => Some(Constant::Bool(l == r)),
|
||||
BiNe => Some(Constant::Bool(l != r)),
|
||||
BiLt => Some(Constant::Bool(l < r)),
|
||||
|
|
|
@ -63,7 +63,7 @@ impl CyclomaticComplexity {
|
|||
divergence: 0,
|
||||
short_circuits: 0,
|
||||
returns: 0,
|
||||
cx: cx,
|
||||
cx,
|
||||
};
|
||||
helper.visit_expr(expr);
|
||||
let CCHelper {
|
||||
|
|
|
@ -39,7 +39,7 @@ pub struct Doc {
|
|||
impl Doc {
|
||||
pub fn new(valid_idents: Vec<String>) -> Self {
|
||||
Self {
|
||||
valid_idents: valid_idents,
|
||||
valid_idents,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -66,7 +66,7 @@ struct Parser<'a> {
|
|||
|
||||
impl<'a> Parser<'a> {
|
||||
fn new(parser: pulldown_cmark::Parser<'a>) -> Self {
|
||||
Self { parser: parser }
|
||||
Self { parser }
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -55,12 +55,12 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for HashMapLint {
|
|||
};
|
||||
|
||||
let mut visitor = InsertVisitor {
|
||||
cx: cx,
|
||||
cx,
|
||||
span: expr.span,
|
||||
ty: ty,
|
||||
map: map,
|
||||
key: key,
|
||||
sole_expr: sole_expr,
|
||||
ty,
|
||||
map,
|
||||
key,
|
||||
sole_expr,
|
||||
};
|
||||
|
||||
walk_expr(&mut visitor, &**then_block);
|
||||
|
@ -68,11 +68,11 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for HashMapLint {
|
|||
} else if let Some(ref else_block) = *else_block {
|
||||
if let Some((ty, map, key)) = check_cond(cx, check) {
|
||||
let mut visitor = InsertVisitor {
|
||||
cx: cx,
|
||||
cx,
|
||||
span: expr.span,
|
||||
ty: ty,
|
||||
map: map,
|
||||
key: key,
|
||||
ty,
|
||||
map,
|
||||
key,
|
||||
sole_expr: false,
|
||||
};
|
||||
|
||||
|
|
|
@ -70,11 +70,11 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnportableVariant {
|
|||
match ty.sty {
|
||||
ty::TyInt(IntTy::Isize) => {
|
||||
let val = ((val as i128) << 64) >> 64;
|
||||
if val <= i32::max_value() as i128 && val >= i32::min_value() as i128 {
|
||||
if val <= i128::from(i32::max_value()) && val >= i128::from(i32::min_value()) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
ty::TyUint(UintTy::Usize) if val > u32::max_value() as u128 => {},
|
||||
ty::TyUint(UintTy::Usize) if val > u128::from(u32::max_value()) => {},
|
||||
_ => continue,
|
||||
}
|
||||
span_lint(
|
||||
|
|
|
@ -107,7 +107,7 @@ impl EnumVariantNames {
|
|||
pub fn new(threshold: u64) -> Self {
|
||||
Self {
|
||||
modules: Vec::new(),
|
||||
threshold: threshold,
|
||||
threshold,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -66,7 +66,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
|
|||
) {
|
||||
let fn_def_id = cx.tcx.hir.local_def_id(node_id);
|
||||
let mut v = EscapeDelegate {
|
||||
cx: cx,
|
||||
cx,
|
||||
set: NodeSet(),
|
||||
too_large_for_stack: self.too_large_for_stack,
|
||||
};
|
||||
|
|
|
@ -67,8 +67,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for EvalOrderDependence {
|
|||
if path.segments.len() == 1 {
|
||||
if let def::Def::Local(var) = cx.tables.qpath_def(qpath, lhs.hir_id) {
|
||||
let mut visitor = ReadVisitor {
|
||||
cx: cx,
|
||||
var: var,
|
||||
cx,
|
||||
var,
|
||||
write_expr: expr,
|
||||
last_expr: expr,
|
||||
};
|
||||
|
@ -82,13 +82,13 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for EvalOrderDependence {
|
|||
}
|
||||
fn check_stmt(&mut self, cx: &LateContext<'a, 'tcx>, stmt: &'tcx Stmt) {
|
||||
match stmt.node {
|
||||
StmtExpr(ref e, _) | StmtSemi(ref e, _) => DivergenceVisitor { cx: cx }.maybe_walk_expr(e),
|
||||
StmtExpr(ref e, _) | StmtSemi(ref e, _) => DivergenceVisitor { cx }.maybe_walk_expr(e),
|
||||
StmtDecl(ref d, _) => if let DeclLocal(ref local) = d.node {
|
||||
if let Local {
|
||||
init: Some(ref e), ..
|
||||
} = **local
|
||||
{
|
||||
DivergenceVisitor { cx: cx }.visit_expr(e);
|
||||
DivergenceVisitor { cx }.visit_expr(e);
|
||||
}
|
||||
},
|
||||
}
|
||||
|
|
|
@ -62,7 +62,7 @@ pub struct Functions {
|
|||
impl Functions {
|
||||
pub fn new(threshold: u64) -> Self {
|
||||
Self {
|
||||
threshold: threshold,
|
||||
threshold,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -156,7 +156,7 @@ impl<'a, 'tcx> Functions {
|
|||
if !raw_ptrs.is_empty() {
|
||||
let tables = cx.tcx.body_tables(body.id());
|
||||
let mut v = DerefVisitor {
|
||||
cx: cx,
|
||||
cx,
|
||||
ptrs: raw_ptrs,
|
||||
tables,
|
||||
};
|
||||
|
|
|
@ -37,11 +37,8 @@ impl LintPass for Pass {
|
|||
|
||||
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
|
||||
fn check_trait_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx TraitItem) {
|
||||
match item.node {
|
||||
TraitItemKind::Method(_, TraitMethod::Required(_)) => {
|
||||
check_attrs(cx, &item.name, &item.attrs);
|
||||
},
|
||||
_ => {},
|
||||
if let TraitItemKind::Method(_, TraitMethod::Required(_)) = item.node {
|
||||
check_attrs(cx, &item.name, &item.attrs);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -35,7 +35,7 @@ pub struct LargeEnumVariant {
|
|||
impl LargeEnumVariant {
|
||||
pub fn new(maximum_size_difference_allowed: u64) -> Self {
|
||||
Self {
|
||||
maximum_size_difference_allowed: maximum_size_difference_allowed,
|
||||
maximum_size_difference_allowed,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -170,7 +170,7 @@ fn check_assign<'a, 'tcx>(
|
|||
if decl == local_id;
|
||||
then {
|
||||
let mut v = UsedVisitor {
|
||||
cx: cx,
|
||||
cx,
|
||||
id: decl,
|
||||
used: false,
|
||||
};
|
||||
|
@ -192,8 +192,8 @@ fn check_assign<'a, 'tcx>(
|
|||
|
||||
fn used_in_expr<'a, 'tcx: 'a>(cx: &LateContext<'a, 'tcx>, id: ast::NodeId, expr: &'tcx hir::Expr) -> bool {
|
||||
let mut v = UsedVisitor {
|
||||
cx: cx,
|
||||
id: id,
|
||||
cx,
|
||||
id,
|
||||
used: false,
|
||||
};
|
||||
hir::intravisit::walk_expr(&mut v, expr);
|
||||
|
|
|
@ -8,9 +8,8 @@
|
|||
#![feature(slice_patterns)]
|
||||
#![feature(stmt_expr_attributes)]
|
||||
#![feature(conservative_impl_trait)]
|
||||
#![feature(inclusive_range_syntax, range_contains)]
|
||||
#![feature(range_contains)]
|
||||
#![feature(macro_vis_matcher)]
|
||||
#![feature(dotdoteq_in_patterns)]
|
||||
#![allow(unknown_lints, indexing_slicing, shadow_reuse, missing_docs_in_private_items)]
|
||||
#![recursion_limit = "256"]
|
||||
|
||||
|
|
|
@ -261,7 +261,7 @@ struct RefVisitor<'a, 'tcx: 'a> {
|
|||
impl<'v, 't> RefVisitor<'v, 't> {
|
||||
fn new(cx: &'v LateContext<'v, 't>) -> Self {
|
||||
Self {
|
||||
cx: cx,
|
||||
cx,
|
||||
lts: Vec::new(),
|
||||
abort: false,
|
||||
}
|
||||
|
|
|
@ -138,11 +138,11 @@ impl<'a> DigitInfo<'a> {
|
|||
let suffix_start = if last_d == '_' { d_idx - 1 } else { d_idx };
|
||||
let (digits, suffix) = sans_prefix.split_at(suffix_start);
|
||||
return Self {
|
||||
digits: digits,
|
||||
radix: radix,
|
||||
prefix: prefix,
|
||||
digits,
|
||||
radix,
|
||||
prefix,
|
||||
suffix: Some(suffix),
|
||||
float: float,
|
||||
float,
|
||||
};
|
||||
}
|
||||
last_d = d
|
||||
|
@ -151,10 +151,10 @@ impl<'a> DigitInfo<'a> {
|
|||
// No suffix found
|
||||
Self {
|
||||
digits: sans_prefix,
|
||||
radix: radix,
|
||||
prefix: prefix,
|
||||
radix,
|
||||
prefix,
|
||||
suffix: None,
|
||||
float: float,
|
||||
float,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -426,7 +426,7 @@ impl EarlyLintPass for LiteralRepresentation {
|
|||
impl LiteralRepresentation {
|
||||
pub fn new(threshold: u64) -> Self {
|
||||
Self {
|
||||
threshold: threshold,
|
||||
threshold,
|
||||
}
|
||||
}
|
||||
fn check_lit(&self, cx: &EarlyContext, lit: &Lit) {
|
||||
|
@ -444,7 +444,7 @@ impl LiteralRepresentation {
|
|||
.filter(|&c| c != '_')
|
||||
.collect::<String>()
|
||||
.parse::<u128>().unwrap();
|
||||
if val < self.threshold as u128 {
|
||||
if val < u128::from(self.threshold) {
|
||||
return
|
||||
}
|
||||
let hex = format!("{:#X}", val);
|
||||
|
|
|
@ -975,7 +975,7 @@ fn check_for_loop_range<'a, 'tcx>(
|
|||
// the var must be a single name
|
||||
if let PatKind::Binding(_, canonical_id, ref ident, _) = pat.node {
|
||||
let mut visitor = VarVisitor {
|
||||
cx: cx,
|
||||
cx,
|
||||
var: canonical_id,
|
||||
indexed_mut: HashSet::new(),
|
||||
indexed_indirectly: HashMap::new(),
|
||||
|
@ -1289,7 +1289,7 @@ fn check_for_loop_explicit_counter<'a, 'tcx>(
|
|||
) {
|
||||
// Look for variables that are incremented once per loop iteration.
|
||||
let mut visitor = IncrementVisitor {
|
||||
cx: cx,
|
||||
cx,
|
||||
states: HashMap::new(),
|
||||
depth: 0,
|
||||
done: false,
|
||||
|
@ -1309,7 +1309,7 @@ fn check_for_loop_explicit_counter<'a, 'tcx>(
|
|||
.filter(|&(_, v)| *v == VarState::IncrOnce)
|
||||
{
|
||||
let mut visitor2 = InitializeVisitor {
|
||||
cx: cx,
|
||||
cx,
|
||||
end_expr: expr,
|
||||
var_id: *id,
|
||||
state: VarState::IncrOnce,
|
||||
|
@ -1728,8 +1728,8 @@ fn is_iterator_used_after_while_let<'a, 'tcx: 'a>(cx: &LateContext<'a, 'tcx>, it
|
|||
None => return false,
|
||||
};
|
||||
let mut visitor = VarUsedAfterLoopVisitor {
|
||||
cx: cx,
|
||||
def_id: def_id,
|
||||
cx,
|
||||
def_id,
|
||||
iter_expr_id: iter_expr.id,
|
||||
past_while_let: false,
|
||||
var_used_after_while_let: false,
|
||||
|
@ -2048,7 +2048,7 @@ fn is_loop_nested(cx: &LateContext, loop_expr: &Expr, iter_expr: &Expr) -> bool
|
|||
},
|
||||
Some(NodeBlock(block)) => {
|
||||
let mut block_visitor = LoopNestVisitor {
|
||||
id: id,
|
||||
id,
|
||||
iterator: iter_name,
|
||||
nesting: Unknown,
|
||||
};
|
||||
|
@ -2189,7 +2189,7 @@ struct MutableVarsVisitor<'a, 'tcx: 'a> {
|
|||
impl<'a, 'tcx> Visitor<'tcx> for MutableVarsVisitor<'a, 'tcx> {
|
||||
fn visit_expr(&mut self, ex: &'tcx Expr) {
|
||||
match ex.node {
|
||||
ExprPath(_) => if let Some(node_id) = check_for_mutability(self.cx, &ex) {
|
||||
ExprPath(_) => if let Some(node_id) = check_for_mutability(self.cx, ex) {
|
||||
self.ids.insert(node_id, None);
|
||||
},
|
||||
|
||||
|
@ -2213,7 +2213,7 @@ struct MutVarsDelegate {
|
|||
|
||||
impl<'tcx> MutVarsDelegate {
|
||||
fn update(&mut self, cat: &'tcx Categorization, sp: Span) {
|
||||
if let &Categorization::Local(id) = cat {
|
||||
if let Categorization::Local(id) = *cat {
|
||||
if let Some(span) = self.mut_spans.get_mut(&id) {
|
||||
*span = Some(sp)
|
||||
}
|
||||
|
|
|
@ -760,7 +760,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
|
|||
},
|
||||
hir::ExprBinary(op, ref lhs, ref rhs) if op.node == hir::BiEq || op.node == hir::BiNe => {
|
||||
let mut info = BinaryExprInfo {
|
||||
expr: expr,
|
||||
expr,
|
||||
chain: lhs,
|
||||
other: rhs,
|
||||
eq: op.node == hir::BiEq,
|
||||
|
|
|
@ -33,13 +33,13 @@ impl LintPass for MutMut {
|
|||
|
||||
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MutMut {
|
||||
fn check_block(&mut self, cx: &LateContext<'a, 'tcx>, block: &'tcx hir::Block) {
|
||||
intravisit::walk_block(&mut MutVisitor { cx: cx }, block);
|
||||
intravisit::walk_block(&mut MutVisitor { cx }, block);
|
||||
}
|
||||
|
||||
fn check_ty(&mut self, cx: &LateContext<'a, 'tcx>, ty: &'tcx hir::Ty) {
|
||||
use rustc::hir::intravisit::Visitor;
|
||||
|
||||
MutVisitor { cx: cx }.visit_ty(ty);
|
||||
MutVisitor { cx }.visit_ty(ty);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -337,10 +337,10 @@ fn check_and_warn<'a>(ctx: &EarlyContext, expr: &'a ast::Expr) {
|
|||
with_if_expr(stmt, |if_expr, cond, then_block, else_expr| {
|
||||
let data = &LintData {
|
||||
stmt_idx: i,
|
||||
if_expr: if_expr,
|
||||
if_expr,
|
||||
if_cond: cond,
|
||||
if_block: then_block,
|
||||
else_expr: else_expr,
|
||||
else_expr,
|
||||
block_stmts: &loop_block.stmts,
|
||||
};
|
||||
if needless_continue_in_else(else_expr) {
|
||||
|
|
|
@ -203,7 +203,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NeedlessPassByValue {
|
|||
|
||||
// Dereference suggestion
|
||||
let sugg = |db: &mut DiagnosticBuilder| {
|
||||
if let ty::TypeVariants::TyAdt(ref def, ..) = ty.sty {
|
||||
if let ty::TypeVariants::TyAdt(def, ..) = ty.sty {
|
||||
if let Some(span) = cx.tcx.hir.span_if_local(def.did) {
|
||||
let param_env = ty::ParamEnv::empty();
|
||||
if param_env.can_type_implement_copy(cx.tcx, ty, span).is_ok() {
|
||||
|
@ -307,7 +307,7 @@ struct MovedVariablesCtxt<'a, 'tcx: 'a> {
|
|||
impl<'a, 'tcx> MovedVariablesCtxt<'a, 'tcx> {
|
||||
fn new(cx: &'a LateContext<'a, 'tcx>) -> Self {
|
||||
Self {
|
||||
cx: cx,
|
||||
cx,
|
||||
moved_vars: HashSet::new(),
|
||||
spans_need_deref: HashMap::new(),
|
||||
}
|
||||
|
|
|
@ -267,7 +267,7 @@ impl<'a, 'tcx, 'b> SimilarNamesNameVisitor<'a, 'tcx, 'b> {
|
|||
self.0.names.push(ExistingName {
|
||||
whitelist: get_whitelist(&interned_name).unwrap_or(&[]),
|
||||
interned: interned_name,
|
||||
span: span,
|
||||
span,
|
||||
len: count,
|
||||
});
|
||||
}
|
||||
|
@ -329,8 +329,8 @@ fn do_check(lint: &mut NonExpressiveNames, cx: &EarlyContext, attrs: &[Attribute
|
|||
if !attr::contains_name(attrs, "test") {
|
||||
let mut visitor = SimilarNamesLocalVisitor {
|
||||
names: Vec::new(),
|
||||
cx: cx,
|
||||
lint: lint,
|
||||
cx,
|
||||
lint,
|
||||
single_char_names: Vec::new(),
|
||||
};
|
||||
// initialize with function arguments
|
||||
|
|
|
@ -225,19 +225,16 @@ fn check_fn(cx: &LateContext, decl: &FnDecl, fn_id: NodeId, opt_body_id: Option<
|
|||
if let [ref inner] = *params.types;
|
||||
then {
|
||||
let replacement = snippet_opt(cx, inner.span);
|
||||
match replacement {
|
||||
Some(r) => {
|
||||
span_lint_and_then(
|
||||
cx,
|
||||
PTR_ARG,
|
||||
arg.span,
|
||||
"using a reference to `Cow` is not recommended.",
|
||||
|db| {
|
||||
db.span_suggestion(arg.span, "change this to", "&".to_owned() + &r);
|
||||
},
|
||||
);
|
||||
},
|
||||
None => (),
|
||||
if let Some(r) = replacement {
|
||||
span_lint_and_then(
|
||||
cx,
|
||||
PTR_ARG,
|
||||
arg.span,
|
||||
"using a reference to `Cow` is not recommended.",
|
||||
|db| {
|
||||
db.span_suggestion(arg.span, "change this to", "&".to_owned() + &r);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -55,7 +55,7 @@ impl QuestionMarkPass {
|
|||
if let ExprIf(ref if_expr, ref body, _) = expr.node;
|
||||
if let ExprMethodCall(ref segment, _, ref args) = if_expr.node;
|
||||
if segment.name == "is_none";
|
||||
if Self::expression_returns_none(cx, &body);
|
||||
if Self::expression_returns_none(cx, body);
|
||||
if let Some(subject) = args.get(0);
|
||||
if Self::is_option(cx, subject);
|
||||
|
||||
|
@ -64,7 +64,7 @@ impl QuestionMarkPass {
|
|||
cx,
|
||||
QUESTION_MARK,
|
||||
expr.span,
|
||||
&format!("this block may be rewritten with the `?` operator"),
|
||||
"this block may be rewritten with the `?` operator",
|
||||
|db| {
|
||||
let receiver_str = &Sugg::hir(cx, subject, "..");
|
||||
|
||||
|
@ -82,7 +82,7 @@ impl QuestionMarkPass {
|
|||
fn is_option(cx: &LateContext, expression: &Expr) -> bool {
|
||||
let expr_ty = cx.tables.expr_ty(expression);
|
||||
|
||||
return match_type(cx, expr_ty, &OPTION);
|
||||
match_type(cx, expr_ty, &OPTION)
|
||||
}
|
||||
|
||||
fn expression_returns_none(cx: &LateContext, expression: &Expr) -> bool {
|
||||
|
@ -127,7 +127,7 @@ impl QuestionMarkPass {
|
|||
return Some(ret_expr.clone());
|
||||
}
|
||||
|
||||
return None;
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -985,7 +985,7 @@ pub struct TypeComplexityPass {
|
|||
impl TypeComplexityPass {
|
||||
pub fn new(threshold: u64) -> Self {
|
||||
Self {
|
||||
threshold: threshold,
|
||||
threshold,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1241,7 +1241,7 @@ fn is_cast_between_fixed_and_target<'a, 'tcx>(
|
|||
return is_isize_or_usize(precast_ty) != is_isize_or_usize(cast_ty)
|
||||
}
|
||||
|
||||
return false;
|
||||
false
|
||||
}
|
||||
|
||||
fn detect_absurd_comparison<'a, 'tcx>(
|
||||
|
@ -1315,8 +1315,8 @@ fn detect_extreme_expr<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) -
|
|||
_ => return None,
|
||||
};
|
||||
Some(ExtremeExpr {
|
||||
which: which,
|
||||
expr: expr,
|
||||
which,
|
||||
expr,
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
@ -55,7 +55,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnusedLabel {
|
|||
}
|
||||
|
||||
let mut v = UnusedLabelVisitor {
|
||||
cx: cx,
|
||||
cx,
|
||||
labels: HashMap::new(),
|
||||
};
|
||||
walk_fn(&mut v, kind, decl, body.id(), span, fn_id);
|
||||
|
|
|
@ -66,8 +66,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UseSelf {
|
|||
};
|
||||
if should_check {
|
||||
let visitor = &mut UseSelfVisitor {
|
||||
item_path: item_path,
|
||||
cx: cx,
|
||||
item_path,
|
||||
cx,
|
||||
};
|
||||
for impl_item_ref in refs {
|
||||
visitor.visit_impl_item(cx.tcx.hir.impl_item(impl_item_ref.id));
|
||||
|
|
|
@ -274,7 +274,7 @@ impl<'tcx> Visitor<'tcx> for PrintVisitor {
|
|||
if let Ty_::TyPath(ref qp) = ty.node {
|
||||
println!(" if let Ty_::TyPath(ref {}) = {}.node;", qp_label, cast_ty);
|
||||
self.current = qp_label;
|
||||
self.print_qpath(&qp);
|
||||
self.print_qpath(qp);
|
||||
}
|
||||
self.current = cast_pat;
|
||||
self.visit_expr(expr);
|
||||
|
|
|
@ -24,7 +24,7 @@ pub struct SpanlessEq<'a, 'tcx: 'a> {
|
|||
impl<'a, 'tcx: 'a> SpanlessEq<'a, 'tcx> {
|
||||
pub fn new(cx: &'a LateContext<'a, 'tcx>) -> Self {
|
||||
Self {
|
||||
cx: cx,
|
||||
cx,
|
||||
ignore_fn: false,
|
||||
}
|
||||
}
|
||||
|
@ -295,7 +295,7 @@ pub struct SpanlessHash<'a, 'tcx: 'a> {
|
|||
impl<'a, 'tcx: 'a> SpanlessHash<'a, 'tcx> {
|
||||
pub fn new(cx: &'a LateContext<'a, 'tcx>) -> Self {
|
||||
Self {
|
||||
cx: cx,
|
||||
cx,
|
||||
s: DefaultHasher::new(),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -123,7 +123,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for LintWithoutLintPass {
|
|||
} else if is_lint_array_type(ty) && item.vis == Visibility::Inherited && item.name == "ARRAY" {
|
||||
let mut collector = LintCollector {
|
||||
output: &mut self.registered_lints,
|
||||
cx: cx,
|
||||
cx,
|
||||
};
|
||||
collector.visit_expr(&cx.tcx.hir.body(body_id).value);
|
||||
}
|
||||
|
|
|
@ -390,7 +390,7 @@ impl<'tcx> Visitor<'tcx> for ContainsName {
|
|||
/// check if an `Expr` contains a certain name
|
||||
pub fn contains_name(name: Name, expr: &Expr) -> bool {
|
||||
let mut cn = ContainsName {
|
||||
name: name,
|
||||
name,
|
||||
result: false,
|
||||
};
|
||||
cn.visit_expr(expr);
|
||||
|
|
|
@ -220,8 +220,8 @@ impl<T> ParenHelper<T> {
|
|||
/// Build a `ParenHelper`.
|
||||
fn new(paren: bool, wrapped: T) -> Self {
|
||||
Self {
|
||||
paren: paren,
|
||||
wrapped: wrapped,
|
||||
paren,
|
||||
wrapped,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -193,7 +193,5 @@ pub fn main() {
|
|||
}
|
||||
|
||||
let mut ccc = ClippyCompilerCalls::new(clippy_enabled);
|
||||
rustc_driver::run(move || {
|
||||
rustc_driver::run_compiler(&args, &mut ccc, None, None)
|
||||
});
|
||||
rustc_driver::run(move || rustc_driver::run_compiler(&args, &mut ccc, None, None));
|
||||
}
|
||||
|
|
|
@ -67,7 +67,10 @@ pub fn main() {
|
|||
let mut metadata = if let Ok(metadata) = cargo_metadata::metadata(manifest_path_arg.as_ref().map(AsRef::as_ref)) {
|
||||
metadata
|
||||
} else {
|
||||
println!("{:?}", cargo_metadata::metadata(manifest_path_arg.as_ref().map(AsRef::as_ref)));
|
||||
println!(
|
||||
"{:?}",
|
||||
cargo_metadata::metadata(manifest_path_arg.as_ref().map(AsRef::as_ref))
|
||||
);
|
||||
let _ = io::stderr().write_fmt(format_args!("error: Could not obtain cargo metadata.\n"));
|
||||
process::exit(101);
|
||||
};
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
extern crate compiletest_rs as compiletest;
|
||||
extern crate test;
|
||||
|
||||
use std::path::{PathBuf, Path};
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::env::{set_var, var};
|
||||
|
||||
fn clippy_driver_path() -> PathBuf {
|
||||
|
@ -43,7 +43,10 @@ fn config(dir: &'static str, mode: &'static str) -> compiletest::Config {
|
|||
config.run_lib_path = rustc_lib_path();
|
||||
config.compile_lib_path = rustc_lib_path();
|
||||
}
|
||||
config.target_rustcflags = Some(format!("-L {0} -L {0}/deps -Dwarnings", host_libs().display()));
|
||||
config.target_rustcflags = Some(format!(
|
||||
"-L {0} -L {0}/deps -Dwarnings",
|
||||
host_libs().display()
|
||||
));
|
||||
|
||||
config.mode = cfg_mode;
|
||||
config.build_base = if rustc_test_suite().is_some() {
|
||||
|
|
|
@ -11,9 +11,12 @@ fn dogfood() {
|
|||
std::env::set_current_dir(root_dir.join(d)).unwrap();
|
||||
let output = std::process::Command::new("cargo")
|
||||
.arg("run")
|
||||
.arg("--bin").arg("cargo-clippy")
|
||||
.arg("--manifest-path").arg(root_dir.join("Cargo.toml"))
|
||||
.output().unwrap();
|
||||
.arg("--bin")
|
||||
.arg("cargo-clippy")
|
||||
.arg("--manifest-path")
|
||||
.arg(root_dir.join("Cargo.toml"))
|
||||
.output()
|
||||
.unwrap();
|
||||
println!("status: {}", output.status);
|
||||
println!("stdout: {}", String::from_utf8_lossy(&output.stdout));
|
||||
println!("stderr: {}", String::from_utf8_lossy(&output.stderr));
|
||||
|
|
|
@ -9,16 +9,17 @@ fn test_overlapping() {
|
|||
use clippy_lints::matches::overlapping;
|
||||
use syntax::codemap::DUMMY_SP;
|
||||
|
||||
let sp = |s, e| {
|
||||
clippy_lints::matches::SpannedRange {
|
||||
span: DUMMY_SP,
|
||||
node: (s, e),
|
||||
}
|
||||
let sp = |s, e| clippy_lints::matches::SpannedRange {
|
||||
span: DUMMY_SP,
|
||||
node: (s, e),
|
||||
};
|
||||
|
||||
assert_eq!(None, overlapping::<u8>(&[]));
|
||||
assert_eq!(None, overlapping(&[sp(1, Bound::Included(4))]));
|
||||
assert_eq!(None, overlapping(&[sp(1, Bound::Included(4)), sp(5, Bound::Included(6))]));
|
||||
assert_eq!(
|
||||
None,
|
||||
overlapping(&[sp(1, Bound::Included(4)), sp(5, Bound::Included(6))])
|
||||
);
|
||||
assert_eq!(
|
||||
None,
|
||||
overlapping(&[
|
||||
|
|
|
@ -69,7 +69,6 @@ fn test_erode_from_front_no_brace() {
|
|||
assert_eq!(expected, got);
|
||||
}
|
||||
|
||||
|
||||
#[test]
|
||||
#[cfg_attr(rustfmt, rustfmt_skip)]
|
||||
fn test_erode_block() {
|
||||
|
|
|
@ -7,10 +7,16 @@ fn check_that_clippy_lints_has_the_same_version_as_clippy() {
|
|||
let clippy_meta = cargo_metadata::metadata(None).expect("could not obtain cargo metadata");
|
||||
std::env::set_current_dir(std::env::current_dir().unwrap().join("clippy_lints")).unwrap();
|
||||
let clippy_lints_meta = cargo_metadata::metadata(None).expect("could not obtain cargo metadata");
|
||||
assert_eq!(clippy_lints_meta.packages[0].version, clippy_meta.packages[0].version);
|
||||
assert_eq!(
|
||||
clippy_lints_meta.packages[0].version,
|
||||
clippy_meta.packages[0].version
|
||||
);
|
||||
for package in &clippy_meta.packages[0].dependencies {
|
||||
if package.name == "clippy_lints" {
|
||||
assert_eq!(VersionReq::parse(&clippy_lints_meta.packages[0].version).unwrap(), package.req);
|
||||
assert_eq!(
|
||||
VersionReq::parse(&clippy_lints_meta.packages[0].version).unwrap(),
|
||||
package.req
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue