diff --git a/clippy_lints/src/collapsible_if.rs b/clippy_lints/src/collapsible_if.rs index 239a24b6b3c..06db5319d21 100644 --- a/clippy_lints/src/collapsible_if.rs +++ b/clippy_lints/src/collapsible_if.rs @@ -103,7 +103,7 @@ fn check_if(cx: &EarlyContext, expr: &ast::Expr) { fn check_collapsible_maybe_if_let(cx: &EarlyContext, else_: &ast::Expr) { if_let_chain! {[ let ast::ExprKind::Block(ref block) = else_.node, - let Some(ref else_) = expr_block(block), + let Some(else_) = expr_block(block), !in_macro(else_.span), ], { match else_.node { diff --git a/clippy_lints/src/copies.rs b/clippy_lints/src/copies.rs index 730c0ac9633..ea7bbfe81e0 100644 --- a/clippy_lints/src/copies.rs +++ b/clippy_lints/src/copies.rs @@ -228,7 +228,7 @@ fn if_sequence(mut expr: &Expr) -> (SmallVector<&Expr>, SmallVector<&Block>) { while let ExprIf(ref cond, ref then_expr, ref else_expr) = expr.node { conds.push(&**cond); if let ExprBlock(ref block) = then_expr.node { - blocks.push(&block); + blocks.push(block); } else { panic!("ExprIf node is not an ExprBlock"); } diff --git a/clippy_lints/src/loops.rs b/clippy_lints/src/loops.rs index ff57afb7324..d7760a30622 100644 --- a/clippy_lints/src/loops.rs +++ b/clippy_lints/src/loops.rs @@ -894,7 +894,7 @@ impl<'a, 'tcx> Visitor<'tcx> for VarVisitor<'a, 'tcx> { match def { Def::Local(..) | Def::Upvar(..) => { let def_id = def.def_id(); - let node_id = self.cx.tcx.hir.as_local_node_id(def_id).unwrap(); + let node_id = self.cx.tcx.hir.as_local_node_id(def_id).expect("local/upvar are local nodes"); let extent = self.cx.tcx.region_maps.var_scope(node_id); self.indexed.insert(seqvar.segments[0].name, Some(extent)); diff --git a/clippy_lints/src/methods.rs b/clippy_lints/src/methods.rs index bc4c2b037e9..84897da7412 100644 --- a/clippy_lints/src/methods.rs +++ b/clippy_lints/src/methods.rs @@ -649,7 +649,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass { if name == method_name && sig.decl.inputs.len() == n_args && out_type.matches(&sig.decl.output) && - self_kind.matches(&first_arg_ty, &first_arg, &self_ty, false) { + self_kind.matches(first_arg_ty, first_arg, self_ty, false) { span_lint(cx, SHOULD_IMPLEMENT_TRAIT, implitem.span, &format!( "defining a method called `{}` on this type; consider implementing \ the `{}` trait or choosing a less ambiguous name", name, trait_name)); @@ -662,7 +662,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass { for &(ref conv, self_kinds) in &CONVENTIONS { if_let_chain! {[ conv.check(&name.as_str()), - !self_kinds.iter().any(|k| k.matches(&first_arg_ty, &first_arg, &self_ty, is_copy)), + !self_kinds.iter().any(|k| k.matches(first_arg_ty, first_arg, self_ty, is_copy)), ], { let lint = if item.vis == hir::Visibility::Public { WRONG_PUB_SELF_CONVENTION diff --git a/clippy_lints/src/misc.rs b/clippy_lints/src/misc.rs index 5d3f07ecba9..e84fd196874 100644 --- a/clippy_lints/src/misc.rs +++ b/clippy_lints/src/misc.rs @@ -499,9 +499,9 @@ fn is_used(cx: &LateContext, expr: &Expr) -> bool { /// Test whether an expression is in a macro expansion (e.g. something generated by /// `#[derive(...)`] or the like). fn in_attributes_expansion(expr: &Expr) -> bool { - expr.span.ctxt.outer().expn_info().map(|info| { + expr.span.ctxt.outer().expn_info().map_or(false, |info| { matches!(info.callee.format, ExpnFormat::MacroAttribute(_)) - }).unwrap_or(false) + }) } /// Test whether `def` is a variable defined outside a macro. diff --git a/clippy_lints/src/partialeq_ne_impl.rs b/clippy_lints/src/partialeq_ne_impl.rs index 6989eb79f8e..5fee08a0c49 100644 --- a/clippy_lints/src/partialeq_ne_impl.rs +++ b/clippy_lints/src/partialeq_ne_impl.rs @@ -40,7 +40,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass { if_let_chain! {[ let ItemImpl(_, _, _, Some(ref trait_ref), _, ref impl_items) = item.node, !is_automatically_derived(&*item.attrs), - trait_ref.path.def.def_id() == cx.tcx.lang_items.eq_trait().unwrap(), + let Some(eq_trait) = cx.tcx.lang_items.eq_trait(), + trait_ref.path.def.def_id() == eq_trait ], { for impl_item in impl_items { if impl_item.name == "ne" { diff --git a/clippy_lints/src/ranges.rs b/clippy_lints/src/ranges.rs index aa190402f29..5b7cb9aa86f 100644 --- a/clippy_lints/src/ranges.rs +++ b/clippy_lints/src/ranges.rs @@ -66,7 +66,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for StepByZero { let ExprMethodCall( Spanned { node: iter_name, .. }, _, ref iter_args ) = *iter, iter_name == "iter", // range expression in .zip() call: 0..x.len() - let Some(higher::Range { start: Some(ref start), end: Some(ref end), .. }) = higher::range(zip_arg), + let Some(higher::Range { start: Some(start), end: Some(end), .. }) = higher::range(zip_arg), is_integer_literal(start, 0), // .len() call let ExprMethodCall(Spanned { node: len_name, .. }, _, ref len_args) = end.node, diff --git a/clippy_lints/src/returns.rs b/clippy_lints/src/returns.rs index 031e3f8cf2c..16f582c77c9 100644 --- a/clippy_lints/src/returns.rs +++ b/clippy_lints/src/returns.rs @@ -107,7 +107,7 @@ impl ReturnPass { // we need both a let-binding stmt and an expr if_let_chain! {[ - let Some(ref retexpr) = it.next_back(), + let Some(retexpr) = it.next_back(), let ast::StmtKind::Expr(ref retexpr) = retexpr.node, let Some(stmt) = it.next_back(), let ast::StmtKind::Local(ref local) = stmt.node, diff --git a/clippy_lints/src/swap.rs b/clippy_lints/src/swap.rs index d17b8987d2c..b2c56fe8bf3 100644 --- a/clippy_lints/src/swap.rs +++ b/clippy_lints/src/swap.rs @@ -115,13 +115,11 @@ fn check_manual_swap(cx: &LateContext, block: &Block) { } else { (false, "".to_owned(), "".to_owned()) } + } else if let (Some(first), Some(second)) = (Sugg::hir_opt(cx, lhs1), Sugg::hir_opt(cx, rhs1)) { + (true, format!(" `{}` and `{}`", first, second), + format!("std::mem::swap({}, {})", first.mut_addr(), second.mut_addr())) } else { - if let (Some(first), Some(second)) = (Sugg::hir_opt(cx, lhs1), Sugg::hir_opt(cx, rhs1)) { - (true, format!(" `{}` and `{}`", first, second), - format!("std::mem::swap({}, {})", first.mut_addr(), second.mut_addr())) - } else { - (true, "".to_owned(), "".to_owned()) - } + (true, "".to_owned(), "".to_owned()) }; let span = Span { lo: w[0].span.lo, hi: second.span.hi, ctxt: NO_EXPANSION}; diff --git a/clippy_lints/src/types.rs b/clippy_lints/src/types.rs index de90ff323d9..005c508f123 100644 --- a/clippy_lints/src/types.rs +++ b/clippy_lints/src/types.rs @@ -118,7 +118,7 @@ fn check_ty(cx: &LateContext, ast_ty: &Ty) { let last = last_path_segment(qpath); if_let_chain! {[ let PathParameters::AngleBracketedParameters(ref ag) = last.parameters, - let Some(ref vec) = ag.types.get(0), + let Some(vec) = ag.types.get(0), let TyPath(ref qpath) = vec.node, let def::Def::Struct(..) = cx.tables.qpath_def(qpath, vec.id), let Some(did) = opt_def_id(cx.tables.qpath_def(qpath, vec.id)), diff --git a/clippy_lints/src/utils/mod.rs b/clippy_lints/src/utils/mod.rs index ce5065a916b..db595b07969 100644 --- a/clippy_lints/src/utils/mod.rs +++ b/clippy_lints/src/utils/mod.rs @@ -112,12 +112,12 @@ pub fn in_constant(cx: &LateContext, id: NodeId) -> bool { /// Returns true if this `expn_info` was expanded by any macro. pub fn in_macro(span: Span) -> bool { - span.ctxt.outer().expn_info().map(|info| { + span.ctxt.outer().expn_info().map_or(false, |info| { match info.callee.format {// don't treat range expressions desugared to structs as "in_macro" ExpnFormat::CompilerDesugaring(name) => name != "...", _ => true, } - }).unwrap_or(false) + }) } /// Returns true if the macro that expanded the crate was outside of the current crate or was a @@ -138,7 +138,7 @@ pub fn in_external_macro<'a, T: LintContext<'a>>(cx: &T, span: Span) -> bool { }) } - span.ctxt.outer().expn_info().map(|info| in_macro_ext(cx, &info)).unwrap_or(false) + span.ctxt.outer().expn_info().map_or(false, |info| in_macro_ext(cx, &info)) } /// Check if a `DefId`'s path matches the given absolute type path usage.