]> git.lizzy.rs Git - rust.git/blobdiff - clippy_lints/src/new_without_default.rs
Merge branch 'macro-use' into HEAD
[rust.git] / clippy_lints / src / new_without_default.rs
index 8df4577650f3e575e335063a9c4d96bb90f76779..a21927102923c7350323e67d3d8ae25d5afa98ae 100644 (file)
@@ -1,6 +1,8 @@
 use rustc::hir::def_id::DefId;
 use rustc::hir;
 use rustc::lint::*;
+use rustc::{declare_lint, lint_array};
+use if_chain::if_chain;
 use rustc::ty::{self, Ty};
 use syntax::codemap::Span;
 use crate::utils::paths;
@@ -89,7 +91,7 @@ fn get_lints(&self) -> LintArray {
 
 impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NewWithoutDefault {
     fn check_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx hir::Item) {
-        if let hir::ItemImpl(_, _, _, _, None, _, ref items) = item.node {
+        if let hir::ItemKind::Impl(_, _, _, _, None, _, ref items) = item.node {
             for assoc_item in items {
                 if let hir::AssociatedItemKind::Method { has_self: false } = assoc_item.kind {
                     let impl_item = cx.tcx.hir.impl_item(assoc_item.id);
@@ -97,13 +99,16 @@ fn check_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx hir::Item) {
                         return;
                     }
                     if let hir::ImplItemKind::Method(ref sig, _) = impl_item.node {
-                        let name = impl_item.name;
+                        let name = impl_item.ident.name;
                         let id = impl_item.id;
-                        if sig.constness == hir::Constness::Const {
+                        if sig.header.constness == hir::Constness::Const {
                             // can't be implemented by default
                             return;
                         }
-                        if impl_item.generics.params.iter().any(|gen| gen.is_type_param()) {
+                        if impl_item.generics.params.iter().any(|gen| match gen.kind {
+                            hir::GenericParamKind::Type { .. } => true,
+                            _ => false
+                        }) {
                             // when the result of `new()` depends on a type parameter we should not require
                             // an
                             // impl of `Default`