From cfb9b982c539a7392030a78321187fa83eee9ad9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Miku=C5=82a?= Date: Thu, 15 Mar 2018 16:07:15 +0100 Subject: [PATCH 1/5] Apply clippy suggestions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mateusz Mikuła --- clippy_lints/src/assign_ops.rs | 6 +++--- clippy_lints/src/bit_mask.rs | 2 +- clippy_lints/src/blacklisted_name.rs | 2 +- clippy_lints/src/block_in_if_condition.rs | 2 +- clippy_lints/src/booleans.rs | 6 +++--- clippy_lints/src/consts.rs | 16 +++++++-------- clippy_lints/src/cyclomatic_complexity.rs | 2 +- clippy_lints/src/doc.rs | 4 ++-- clippy_lints/src/entry.rs | 18 ++++++++--------- clippy_lints/src/enum_clike.rs | 4 ++-- clippy_lints/src/enum_variants.rs | 2 +- clippy_lints/src/escape.rs | 2 +- clippy_lints/src/eval_order_dependence.rs | 8 ++++---- clippy_lints/src/functions.rs | 4 ++-- clippy_lints/src/inline_fn_without_body.rs | 7 ++----- clippy_lints/src/large_enum_variant.rs | 2 +- clippy_lints/src/let_if_seq.rs | 6 +++--- clippy_lints/src/lifetimes.rs | 2 +- clippy_lints/src/literal_representation.rs | 18 ++++++++--------- clippy_lints/src/loops.rs | 16 +++++++-------- clippy_lints/src/methods.rs | 2 +- clippy_lints/src/mut_mut.rs | 4 ++-- clippy_lints/src/needless_continue.rs | 4 ++-- clippy_lints/src/needless_pass_by_value.rs | 4 ++-- clippy_lints/src/non_expressive_names.rs | 6 +++--- clippy_lints/src/ptr.rs | 23 ++++++++++------------ clippy_lints/src/question_mark.rs | 8 ++++---- clippy_lints/src/types.rs | 8 ++++---- clippy_lints/src/unused_label.rs | 2 +- clippy_lints/src/use_self.rs | 4 ++-- clippy_lints/src/utils/author.rs | 2 +- clippy_lints/src/utils/hir_utils.rs | 4 ++-- clippy_lints/src/utils/internal_lints.rs | 2 +- clippy_lints/src/utils/mod.rs | 2 +- clippy_lints/src/utils/sugg.rs | 4 ++-- 35 files changed, 101 insertions(+), 107 deletions(-) diff --git a/clippy_lints/src/assign_ops.rs b/clippy_lints/src/assign_ops.rs index d285e71bd16..a3d9d5cbba8 100644 --- a/clippy_lints/src/assign_ops.rs +++ b/clippy_lints/src/assign_ops.rs @@ -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; } diff --git a/clippy_lints/src/bit_mask.rs b/clippy_lints/src/bit_mask.rs index 7eb6477b269..8989c5ca8cf 100644 --- a/clippy_lints/src/bit_mask.rs +++ b/clippy_lints/src/bit_mask.rs @@ -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, } } } diff --git a/clippy_lints/src/blacklisted_name.rs b/clippy_lints/src/blacklisted_name.rs index 114ba5fa782..dd5bf968bb3 100644 --- a/clippy_lints/src/blacklisted_name.rs +++ b/clippy_lints/src/blacklisted_name.rs @@ -28,7 +28,7 @@ pub struct BlackListedName { impl BlackListedName { pub fn new(blacklist: Vec) -> Self { Self { - blacklist: blacklist, + blacklist, } } } diff --git a/clippy_lints/src/block_in_if_condition.rs b/clippy_lints/src/block_in_if_condition.rs index a89959d9506..0afb8a73dfe 100644 --- a/clippy_lints/src/block_in_if_condition.rs +++ b/clippy_lints/src/block_in_if_condition.rs @@ -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 { diff --git a/clippy_lints/src/booleans.rs b/clippy_lints/src/booleans.rs index 50afd1b1e4f..cec569ec061 100644 --- a/clippy_lints/src/booleans.rs +++ b/clippy_lints/src/booleans.rs @@ -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, }; diff --git a/clippy_lints/src/consts.rs b/clippy_lints/src/consts.rs index 7c43cb668b3..af0cd8b35d4 100644 --- a/clippy_lints/src/consts.rs +++ b/clippy_lints/src/consts.rs @@ -73,7 +73,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::(l as f64) == mem::transmute::(r as f64) } + unsafe { mem::transmute::(f64::from(l)) == mem::transmute::(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 +102,7 @@ impl Hash for Constant { i.hash(state); }, Constant::F32(f) => { - unsafe { mem::transmute::(f as f64) }.hash(state); + unsafe { mem::transmute::(f64::from(f)) }.hash(state); }, Constant::F64(f) => { unsafe { mem::transmute::(f) }.hash(state); @@ -143,12 +143,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 +177,7 @@ pub fn constant_simple(lcx: &LateContext, e: &Expr) -> Option { 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 +215,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 +240,9 @@ impl<'c, 'cc> ConstEvalLateContext<'c, 'cc> { } } - fn constant_negate(&self, o: Constant, ty: ty::Ty) -> Option { + fn constant_negate(&self, o: &Constant, ty: ty::Ty) -> Option { use self::Constant::*; - match o { + match *o { Int(value) => { let ity = match ty.sty { ty::TyInt(ity) => ity, diff --git a/clippy_lints/src/cyclomatic_complexity.rs b/clippy_lints/src/cyclomatic_complexity.rs index ede9dcb1fbd..751fc13292c 100644 --- a/clippy_lints/src/cyclomatic_complexity.rs +++ b/clippy_lints/src/cyclomatic_complexity.rs @@ -63,7 +63,7 @@ impl CyclomaticComplexity { divergence: 0, short_circuits: 0, returns: 0, - cx: cx, + cx, }; helper.visit_expr(expr); let CCHelper { diff --git a/clippy_lints/src/doc.rs b/clippy_lints/src/doc.rs index ea8ecb91d0a..3e2c56f5fb9 100644 --- a/clippy_lints/src/doc.rs +++ b/clippy_lints/src/doc.rs @@ -39,7 +39,7 @@ pub struct Doc { impl Doc { pub fn new(valid_idents: Vec) -> 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 } } } diff --git a/clippy_lints/src/entry.rs b/clippy_lints/src/entry.rs index b86a4a43fb1..aeae5fc6ced 100644 --- a/clippy_lints/src/entry.rs +++ b/clippy_lints/src/entry.rs @@ -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, }; diff --git a/clippy_lints/src/enum_clike.rs b/clippy_lints/src/enum_clike.rs index 3abd42d37c9..f1572043024 100644 --- a/clippy_lints/src/enum_clike.rs +++ b/clippy_lints/src/enum_clike.rs @@ -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( diff --git a/clippy_lints/src/enum_variants.rs b/clippy_lints/src/enum_variants.rs index b72949a7381..4a5dc1cc286 100644 --- a/clippy_lints/src/enum_variants.rs +++ b/clippy_lints/src/enum_variants.rs @@ -107,7 +107,7 @@ impl EnumVariantNames { pub fn new(threshold: u64) -> Self { Self { modules: Vec::new(), - threshold: threshold, + threshold, } } } diff --git a/clippy_lints/src/escape.rs b/clippy_lints/src/escape.rs index d4c91eab1c3..8cd0aaee9af 100644 --- a/clippy_lints/src/escape.rs +++ b/clippy_lints/src/escape.rs @@ -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, }; diff --git a/clippy_lints/src/eval_order_dependence.rs b/clippy_lints/src/eval_order_dependence.rs index 847aec41500..1ca15e4d24f 100644 --- a/clippy_lints/src/eval_order_dependence.rs +++ b/clippy_lints/src/eval_order_dependence.rs @@ -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); } }, } diff --git a/clippy_lints/src/functions.rs b/clippy_lints/src/functions.rs index 3df037f3329..4bf4aafcc4e 100644 --- a/clippy_lints/src/functions.rs +++ b/clippy_lints/src/functions.rs @@ -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, }; diff --git a/clippy_lints/src/inline_fn_without_body.rs b/clippy_lints/src/inline_fn_without_body.rs index 1bb9519d304..99b7812472a 100644 --- a/clippy_lints/src/inline_fn_without_body.rs +++ b/clippy_lints/src/inline_fn_without_body.rs @@ -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); } } } diff --git a/clippy_lints/src/large_enum_variant.rs b/clippy_lints/src/large_enum_variant.rs index e13b771cf24..668e8e992ec 100644 --- a/clippy_lints/src/large_enum_variant.rs +++ b/clippy_lints/src/large_enum_variant.rs @@ -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, } } } diff --git a/clippy_lints/src/let_if_seq.rs b/clippy_lints/src/let_if_seq.rs index 34863208fde..257f619ec29 100644 --- a/clippy_lints/src/let_if_seq.rs +++ b/clippy_lints/src/let_if_seq.rs @@ -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); diff --git a/clippy_lints/src/lifetimes.rs b/clippy_lints/src/lifetimes.rs index 567b06a8ac1..f2381cc39eb 100644 --- a/clippy_lints/src/lifetimes.rs +++ b/clippy_lints/src/lifetimes.rs @@ -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, } diff --git a/clippy_lints/src/literal_representation.rs b/clippy_lints/src/literal_representation.rs index c534ef327c2..b505a4c30a5 100644 --- a/clippy_lints/src/literal_representation.rs +++ b/clippy_lints/src/literal_representation.rs @@ -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::() .parse::().unwrap(); - if val < self.threshold as u128 { + if val < u128::from(self.threshold) { return } let hex = format!("{:#X}", val); diff --git a/clippy_lints/src/loops.rs b/clippy_lints/src/loops.rs index a0f3db7b784..7bf814afa3d 100644 --- a/clippy_lints/src/loops.rs +++ b/clippy_lints/src/loops.rs @@ -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) } diff --git a/clippy_lints/src/methods.rs b/clippy_lints/src/methods.rs index 0e55d0f8a3a..2c401bd4994 100644 --- a/clippy_lints/src/methods.rs +++ b/clippy_lints/src/methods.rs @@ -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, diff --git a/clippy_lints/src/mut_mut.rs b/clippy_lints/src/mut_mut.rs index c12d3dde2be..ca1592271b3 100644 --- a/clippy_lints/src/mut_mut.rs +++ b/clippy_lints/src/mut_mut.rs @@ -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); } } diff --git a/clippy_lints/src/needless_continue.rs b/clippy_lints/src/needless_continue.rs index ccf9c62d93c..9c801ba7495 100644 --- a/clippy_lints/src/needless_continue.rs +++ b/clippy_lints/src/needless_continue.rs @@ -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) { diff --git a/clippy_lints/src/needless_pass_by_value.rs b/clippy_lints/src/needless_pass_by_value.rs index ca9044c6e8b..b189fcbff4f 100644 --- a/clippy_lints/src/needless_pass_by_value.rs +++ b/clippy_lints/src/needless_pass_by_value.rs @@ -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(), } diff --git a/clippy_lints/src/non_expressive_names.rs b/clippy_lints/src/non_expressive_names.rs index 9ef55907ecd..a267900fcbb 100644 --- a/clippy_lints/src/non_expressive_names.rs +++ b/clippy_lints/src/non_expressive_names.rs @@ -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 diff --git a/clippy_lints/src/ptr.rs b/clippy_lints/src/ptr.rs index 139b5883fb0..435812bf962 100644 --- a/clippy_lints/src/ptr.rs +++ b/clippy_lints/src/ptr.rs @@ -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); + }, + ); } } } diff --git a/clippy_lints/src/question_mark.rs b/clippy_lints/src/question_mark.rs index 4c01899936b..39fcc2b1b8f 100644 --- a/clippy_lints/src/question_mark.rs +++ b/clippy_lints/src/question_mark.rs @@ -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 } } diff --git a/clippy_lints/src/types.rs b/clippy_lints/src/types.rs index 251f0c588e8..82a1799ffd8 100644 --- a/clippy_lints/src/types.rs +++ b/clippy_lints/src/types.rs @@ -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, }) } diff --git a/clippy_lints/src/unused_label.rs b/clippy_lints/src/unused_label.rs index 37e7c5e3bd4..ee708eb13ae 100644 --- a/clippy_lints/src/unused_label.rs +++ b/clippy_lints/src/unused_label.rs @@ -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); diff --git a/clippy_lints/src/use_self.rs b/clippy_lints/src/use_self.rs index 8203377e465..a1390596cda 100644 --- a/clippy_lints/src/use_self.rs +++ b/clippy_lints/src/use_self.rs @@ -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)); diff --git a/clippy_lints/src/utils/author.rs b/clippy_lints/src/utils/author.rs index beae98f81f6..44e5e84c4a0 100644 --- a/clippy_lints/src/utils/author.rs +++ b/clippy_lints/src/utils/author.rs @@ -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); diff --git a/clippy_lints/src/utils/hir_utils.rs b/clippy_lints/src/utils/hir_utils.rs index cad6ec532a6..e790184a7ab 100644 --- a/clippy_lints/src/utils/hir_utils.rs +++ b/clippy_lints/src/utils/hir_utils.rs @@ -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(), } } diff --git a/clippy_lints/src/utils/internal_lints.rs b/clippy_lints/src/utils/internal_lints.rs index 6e62f96749e..625ef63a3dc 100644 --- a/clippy_lints/src/utils/internal_lints.rs +++ b/clippy_lints/src/utils/internal_lints.rs @@ -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); } diff --git a/clippy_lints/src/utils/mod.rs b/clippy_lints/src/utils/mod.rs index b171bdf4030..125602319f7 100644 --- a/clippy_lints/src/utils/mod.rs +++ b/clippy_lints/src/utils/mod.rs @@ -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); diff --git a/clippy_lints/src/utils/sugg.rs b/clippy_lints/src/utils/sugg.rs index e18c1274498..4ca6e5cbf73 100644 --- a/clippy_lints/src/utils/sugg.rs +++ b/clippy_lints/src/utils/sugg.rs @@ -220,8 +220,8 @@ impl ParenHelper { /// Build a `ParenHelper`. fn new(paren: bool, wrapped: T) -> Self { Self { - paren: paren, - wrapped: wrapped, + paren, + wrapped, } } } From 23bfa396a05564fb8e16db26bf5eb3c8d7e909b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Miku=C5=82a?= Date: Thu, 15 Mar 2018 16:08:49 +0100 Subject: [PATCH 2/5] Format code MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mateusz Mikuła --- src/driver.rs | 4 +--- src/main.rs | 5 ++++- tests/compile-test.rs | 7 +++++-- tests/dogfood.rs | 9 ++++++--- tests/matches.rs | 13 +++++++------ tests/needless_continue_helpers.rs | 1 - tests/versioncheck.rs | 10 ++++++++-- 7 files changed, 31 insertions(+), 18 deletions(-) diff --git a/src/driver.rs b/src/driver.rs index 7b7167cef70..78bccb74ab9 100644 --- a/src/driver.rs +++ b/src/driver.rs @@ -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)); } diff --git a/src/main.rs b/src/main.rs index ab2b3b9a4a0..95e1fc0c28c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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); }; diff --git a/tests/compile-test.rs b/tests/compile-test.rs index 5e059084da8..9b9820f2b52 100644 --- a/tests/compile-test.rs +++ b/tests/compile-test.rs @@ -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() { diff --git a/tests/dogfood.rs b/tests/dogfood.rs index 590027f8491..ed6451a3eb6 100644 --- a/tests/dogfood.rs +++ b/tests/dogfood.rs @@ -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)); diff --git a/tests/matches.rs b/tests/matches.rs index 42d1154bf1a..8dfb8e42d6f 100644 --- a/tests/matches.rs +++ b/tests/matches.rs @@ -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::(&[])); 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(&[ diff --git a/tests/needless_continue_helpers.rs b/tests/needless_continue_helpers.rs index 853f64b4698..588dc741d03 100644 --- a/tests/needless_continue_helpers.rs +++ b/tests/needless_continue_helpers.rs @@ -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() { diff --git a/tests/versioncheck.rs b/tests/versioncheck.rs index 6fe82ac792e..ff4af08a8a0 100644 --- a/tests/versioncheck.rs +++ b/tests/versioncheck.rs @@ -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; } } From 4c94dd238f9b5d6a186398fd51854937451e0656 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Miku=C5=82a?= Date: Fri, 16 Mar 2018 10:47:28 +0100 Subject: [PATCH 3/5] Fix BiRem for floats MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mateusz Mikuła --- clippy_lints/src/consts.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/clippy_lints/src/consts.rs b/clippy_lints/src/consts.rs index af0cd8b35d4..7ed2ac752e5 100644 --- a/clippy_lints/src/consts.rs +++ b/clippy_lints/src/consts.rs @@ -377,7 +377,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 +391,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)), From c7770bf907222c0874c56d96a202a76b1df183fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Miku=C5=82a?= Date: Fri, 16 Mar 2018 11:09:05 +0100 Subject: [PATCH 4/5] Remove attributes for stable features MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mateusz Mikuła --- clippy_lints/src/lib.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/clippy_lints/src/lib.rs b/clippy_lints/src/lib.rs index 5272fb0a48e..d508a17a264 100644 --- a/clippy_lints/src/lib.rs +++ b/clippy_lints/src/lib.rs @@ -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"] From 3b387eaabed1ed47503f44fd9fd54979b4024b64 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Miku=C5=82a?= Date: Fri, 16 Mar 2018 11:36:14 +0100 Subject: [PATCH 5/5] Allow float_cmp in consts lint code MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mateusz Mikuła --- clippy_lints/src/consts.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/clippy_lints/src/consts.rs b/clippy_lints/src/consts.rs index 7ed2ac752e5..675342645b8 100644 --- a/clippy_lints/src/consts.rs +++ b/clippy_lints/src/consts.rs @@ -1,4 +1,5 @@ #![allow(cast_possible_truncation)] +#![allow(float_cmp)] use rustc::lint::LateContext; use rustc::hir::def::Def;