]> 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 54b00081973d9f7ab0cbb3fcb2c73a46c68882f3..a21927102923c7350323e67d3d8ae25d5afa98ae 100644 (file)
@@ -1,11 +1,13 @@
 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 utils::paths;
-use utils::{get_trait_def_id, implements_trait, in_external_macro, return_ty, same_tys, span_lint_and_then};
-use utils::sugg::DiagnosticBuilderExt;
+use crate::utils::paths;
+use crate::utils::{get_trait_def_id, implements_trait, in_external_macro, return_ty, same_tys, span_lint_and_then};
+use crate::utils::sugg::DiagnosticBuilderExt;
 
 /// **What it does:** Checks for types with a `fn new() -> Self` method and no
 /// implementation of
@@ -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`
@@ -153,7 +158,7 @@ fn check_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx hir::Item) {
 }
 
 fn create_new_without_default_suggest_msg(ty: Ty) -> String {
-    #[rustfmt_skip]
+    #[cfg_attr(rustfmt, rustfmt_skip)]
     format!(
 "impl Default for {} {{
     fn default() -> Self {{