]> git.lizzy.rs Git - rust.git/blobdiff - clippy_lints/src/methods.rs
Merge branch 'macro-use' into HEAD
[rust.git] / clippy_lints / src / methods.rs
index d1740081e67de274f34696e31ad45d3adf5aab2e..3ebad1d705b940ecae8750ab3341f3390470f2d7 100644 (file)
@@ -1,5 +1,8 @@
+use matches::matches;
 use rustc::hir;
 use rustc::lint::*;
+use rustc::{declare_lint, lint_array};
+use if_chain::if_chain;
 use rustc::ty::{self, Ty};
 use rustc::hir::def::Def;
 use std::borrow::Cow;
@@ -813,7 +816,7 @@ fn check_impl_item(&mut self, cx: &LateContext<'a, 'tcx>, implitem: &'tcx hir::I
             if let hir::ImplItemKind::Method(ref sig, id) = implitem.node;
             if let Some(first_arg_ty) = sig.decl.inputs.get(0);
             if let Some(first_arg) = iter_input_pats(&sig.decl, cx.tcx.hir.body(id)).next();
-            if let hir::ItemImpl(_, _, _, _, None, ref self_ty, _) = item.node;
+            if let hir::ItemKind::Impl(_, _, _, _, None, ref self_ty, _) = item.node;
             then {
                 if cx.access_levels.is_exported(implitem.id) {
                 // check missing trait implementations
@@ -1139,8 +1142,8 @@ fn lint_clone_on_copy(cx: &LateContext, expr: &hir::Expr, arg: &hir::Expr, arg_t
                         _ => {},
                     }
                     hir::map::NodeStmt(stmt) => {
-                        if let hir::StmtDecl(ref decl, _) = stmt.node {
-                            if let hir::DeclLocal(ref loc) = decl.node {
+                        if let hir::StmtKind::Decl(ref decl, _) = stmt.node {
+                            if let hir::DeclKind::Local(ref loc) = decl.node {
                                 if let hir::PatKind::Ref(..) = loc.pat.node {
                                     // let ref y = *x borrows x, let ref y = x.clone() does not
                                     return;
@@ -1338,7 +1341,7 @@ fn check_fold_with_op(
                     cx, fold_args, hir::BinOpKind::And, "all", true
                 ),
                 ast::LitKind::Int(0, _) => check_fold_with_op(
-                    cx, fold_args, hir::BinOpKindAdd, "sum", false
+                    cx, fold_args, hir::BinOpKind::Add, "sum", false
                 ),
                 ast::LitKind::Int(1, _) => check_fold_with_op(
                     cx, fold_args, hir::BinOpKind::Mul, "product", false
@@ -2057,7 +2060,7 @@ fn matches(
                         return true;
                     }
                     match ty.node {
-                        hir::TyRptr(_, ref mt_ty) => {
+                        hir::TyKind::Rptr(_, ref mt_ty) => {
                             let mutability_match = if self == SelfKind::Ref {
                                 mt_ty.mutbl == hir::MutImmutable
                             } else {
@@ -2128,8 +2131,8 @@ fn is_as_ref_or_mut_trait(ty: &hir::Ty, self_ty: &hir::Ty, generics: &hir::Gener
 fn is_ty(ty: &hir::Ty, self_ty: &hir::Ty) -> bool {
     match (&ty.node, &self_ty.node) {
         (
-            &hir::TyPath(hir::QPath::Resolved(_, ref ty_path)),
-            &hir::TyPath(hir::QPath::Resolved(_, ref self_ty_path)),
+            &hir::TyKind::Path(hir::QPath::Resolved(_, ref ty_path)),
+            &hir::TyKind::Path(hir::QPath::Resolved(_, ref self_ty_path)),
         ) => ty_path
             .segments
             .iter()
@@ -2140,7 +2143,7 @@ fn is_ty(ty: &hir::Ty, self_ty: &hir::Ty) -> bool {
 }
 
 fn single_segment_ty(ty: &hir::Ty) -> Option<&hir::PathSegment> {
-    if let hir::TyPath(ref path) = ty.node {
+    if let hir::TyKind::Path(ref path) = ty.node {
         single_segment_path(path)
     } else {
         None
@@ -2175,20 +2178,20 @@ enum OutType {
 
 impl OutType {
     fn matches(self, cx: &LateContext, ty: &hir::FunctionRetTy) -> bool {
-        let is_unit = |ty: &hir::Ty| SpanlessEq::new(cx).eq_ty_kind(&ty.node, &hir::TyTup(vec![].into()));
+        let is_unit = |ty: &hir::Ty| SpanlessEq::new(cx).eq_ty_kind(&ty.node, &hir::TyKind::Tup(vec![].into()));
         match (self, ty) {
             (OutType::Unit, &hir::DefaultReturn(_)) => true,
             (OutType::Unit, &hir::Return(ref ty)) if is_unit(ty) => true,
             (OutType::Bool, &hir::Return(ref ty)) if is_bool(ty) => true,
             (OutType::Any, &hir::Return(ref ty)) if !is_unit(ty) => true,
-            (OutType::Ref, &hir::Return(ref ty)) => matches!(ty.node, hir::TyRptr(_, _)),
+            (OutType::Ref, &hir::Return(ref ty)) => matches!(ty.node, hir::TyKind::Rptr(_, _)),
             _ => false,
         }
     }
 }
 
 fn is_bool(ty: &hir::Ty) -> bool {
-    if let hir::TyPath(ref p) = ty.node {
+    if let hir::TyKind::Path(ref p) = ty.node {
         match_qpath(p, &["bool"])
     } else {
         false