diff --git a/clippy_lints/src/consts.rs b/clippy_lints/src/consts.rs index ec8ba70bf741..fc26755a3754 100644 --- a/clippy_lints/src/consts.rs +++ b/clippy_lints/src/consts.rs @@ -320,7 +320,7 @@ impl<'c, 'cc> ConstEvalLateContext<'c, 'cc> { fn fetch_path(&mut self, qpath: &QPath<'_>, id: HirId, ty: Ty<'cc>) -> Option { let res = self.tables.qpath_res(qpath, id); match res { - Res::Def(DefKind::Const, def_id) | Res::Def(DefKind::AssocConst, def_id) => { + Res::Def(DefKind::Const | DefKind::AssocConst, def_id) => { let substs = self.tables.node_substs(id); let substs = if self.substs.is_empty() { substs diff --git a/clippy_lints/src/eval_order_dependence.rs b/clippy_lints/src/eval_order_dependence.rs index 9292dba3bd25..9cf0d3ba26f6 100644 --- a/clippy_lints/src/eval_order_dependence.rs +++ b/clippy_lints/src/eval_order_dependence.rs @@ -106,10 +106,8 @@ impl<'a, 'tcx> DivergenceVisitor<'a, 'tcx> { ExprKind::Match(ref e, arms, _) => { self.visit_expr(e); for arm in arms { - if let Some(ref guard) = arm.guard { - match guard { - Guard::If(if_expr) => self.visit_expr(if_expr), - } + if let Some(Guard::If(if_expr)) = arm.guard { + self.visit_expr(if_expr) } // make sure top level arm expressions aren't linted self.maybe_walk_expr(&*arm.body); diff --git a/clippy_lints/src/lib.rs b/clippy_lints/src/lib.rs index 791307ba43f4..fb79ad271e0a 100644 --- a/clippy_lints/src/lib.rs +++ b/clippy_lints/src/lib.rs @@ -2,6 +2,7 @@ #![feature(box_syntax)] #![feature(box_patterns)] +#![feature(or_patterns)] #![feature(rustc_private)] #![feature(stmt_expr_attributes)] #![allow(clippy::missing_docs_in_private_items, clippy::must_use_candidate)] diff --git a/clippy_lints/src/lifetimes.rs b/clippy_lints/src/lifetimes.rs index a9408e369b39..30ad32c8ed16 100644 --- a/clippy_lints/src/lifetimes.rs +++ b/clippy_lints/src/lifetimes.rs @@ -346,7 +346,7 @@ impl<'v, 't> RefVisitor<'v, 't> { { let hir_id = ty.hir_id; match self.cx.tables.qpath_res(qpath, hir_id) { - Res::Def(DefKind::TyAlias, def_id) | Res::Def(DefKind::Struct, def_id) => { + Res::Def(DefKind::TyAlias | DefKind::Struct, def_id) => { let generics = self.cx.tcx.generics_of(def_id); for _ in generics.params.as_slice() { self.record(&None); diff --git a/clippy_lints/src/loops.rs b/clippy_lints/src/loops.rs index bd71d68848d6..211d9034ffb7 100644 --- a/clippy_lints/src/loops.rs +++ b/clippy_lints/src/loops.rs @@ -1780,7 +1780,7 @@ impl<'a, 'tcx> VarVisitor<'a, 'tcx> { } return false; // no need to walk further *on the variable* } - Res::Def(DefKind::Static, ..) | Res::Def(DefKind::Const, ..) => { + Res::Def(DefKind::Static | DefKind::Const, ..) => { if indexed_indirectly { self.indexed_indirectly.insert(seqvar.segments[0].ident.name, None); } diff --git a/clippy_lints/src/methods/mod.rs b/clippy_lints/src/methods/mod.rs index 7109cd5cf914..ab51ecfb1b5d 100644 --- a/clippy_lints/src/methods/mod.rs +++ b/clippy_lints/src/methods/mod.rs @@ -1755,9 +1755,7 @@ fn lint_expect_fun_call( ) }), hir::ExprKind::Path(ref p) => match cx.tables.qpath_res(p, arg.hir_id) { - hir::def::Res::Def(hir::def::DefKind::Const, _) | hir::def::Res::Def(hir::def::DefKind::Static, _) => { - true - }, + hir::def::Res::Def(hir::def::DefKind::Const | hir::def::DefKind::Static, _) => true, _ => false, }, _ => false, diff --git a/clippy_lints/src/no_effect.rs b/clippy_lints/src/no_effect.rs index 6383d3ca2454..b8bfa676a160 100644 --- a/clippy_lints/src/no_effect.rs +++ b/clippy_lints/src/no_effect.rs @@ -69,7 +69,7 @@ fn has_no_effect(cx: &LateContext<'_, '_>, expr: &Expr<'_>) -> bool { if let ExprKind::Path(ref qpath) = callee.kind { let res = qpath_res(cx, qpath, callee.hir_id); match res { - Res::Def(DefKind::Struct, ..) | Res::Def(DefKind::Variant, ..) | Res::Def(DefKind::Ctor(..), _) => { + Res::Def(DefKind::Struct | DefKind::Variant | DefKind::Ctor(..), ..) => { !has_drop(cx, cx.tables.expr_ty(expr)) && args.iter().all(|arg| has_no_effect(cx, arg)) }, _ => false, diff --git a/clippy_lints/src/non_copy_const.rs b/clippy_lints/src/non_copy_const.rs index 908d1fe286d4..43d76d0cbbdd 100644 --- a/clippy_lints/src/non_copy_const.rs +++ b/clippy_lints/src/non_copy_const.rs @@ -191,7 +191,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NonCopyConst { // Make sure it is a const item. match qpath_res(cx, qpath, expr.hir_id) { - Res::Def(DefKind::Const, _) | Res::Def(DefKind::AssocConst, _) => {}, + Res::Def(DefKind::Const | DefKind::AssocConst, _) => {}, _ => return, }; diff --git a/clippy_lints/src/utils/mod.rs b/clippy_lints/src/utils/mod.rs index 62c47f0afd1d..2a8e172663d2 100644 --- a/clippy_lints/src/utils/mod.rs +++ b/clippy_lints/src/utils/mod.rs @@ -315,7 +315,7 @@ pub fn get_trait_def_id(cx: &LateContext<'_, '_>, path: &[&str]) -> Option Some(trait_id), + Res::Def(DefKind::Trait | DefKind::TraitAlias, trait_id) => Some(trait_id), Res::Err => unreachable!("this trait resolution is impossible: {:?}", &path), _ => None, } @@ -448,10 +448,11 @@ pub fn is_entrypoint_fn(cx: &LateContext<'_, '_>, def_id: DefId) -> bool { pub fn get_item_name(cx: &LateContext<'_, '_>, expr: &Expr<'_>) -> Option { let parent_id = cx.tcx.hir().get_parent_item(expr.hir_id); match cx.tcx.hir().find(parent_id) { - Some(Node::Item(&Item { ref ident, .. })) => Some(ident.name), - Some(Node::TraitItem(&TraitItem { ident, .. })) | Some(Node::ImplItem(&ImplItem { ident, .. })) => { - Some(ident.name) - }, + Some( + Node::Item(Item { ident, .. }) + | Node::TraitItem(TraitItem { ident, .. }) + | Node::ImplItem(ImplItem { ident, .. }), + ) => Some(ident.name), _ => None, } } @@ -925,7 +926,7 @@ pub fn is_ctor_or_promotable_const_function(cx: &LateContext<'_, '_>, expr: &Exp if let ExprKind::Path(ref qp) = fun.kind { let res = cx.tables.qpath_res(qp, fun.hir_id); return match res { - def::Res::Def(DefKind::Variant, ..) | Res::Def(DefKind::Ctor(..), _) => true, + def::Res::Def(DefKind::Variant | DefKind::Ctor(..), ..) => true, def::Res::Def(_, def_id) => cx.tcx.is_promotable_const_fn(def_id), _ => false, };