]> git.lizzy.rs Git - rust.git/blobdiff - clippy_lints/src/copy_iterator.rs
MutImmutable -> Immutable, MutMutable -> Mutable, CaptureClause -> CaptureBy
[rust.git] / clippy_lints / src / copy_iterator.rs
index 3fac6e78adbe8f2fc403b5e27e5da26752db6872..73de8add32d315e738683b0f47a7a52a174cb8ec 100644 (file)
@@ -1,50 +1,40 @@
 use crate::utils::{is_copy, match_path, paths, span_note_and_lint};
 use rustc::hir::{Item, ItemKind};
 use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
-use rustc::{declare_tool_lint, lint_array};
+use rustc::{declare_lint_pass, declare_tool_lint};
 
-/// **What it does:** Checks for types that implement `Copy` as well as
-/// `Iterator`.
-///
-/// **Why is this bad?** Implicit copies can be confusing when working with
-/// iterator combinators.
-///
-/// **Known problems:** None.
-///
-/// **Example:**
-/// ```rust
-/// #[derive(Copy, Clone)]
-/// struct Countdown(u8);
-///
-/// impl Iterator for Countdown {
-///     // ...
-/// }
-///
-/// let a: Vec<_> = my_iterator.take(1).collect();
-/// let b: Vec<_> = my_iterator.collect();
-/// ```
 declare_clippy_lint! {
+    /// **What it does:** Checks for types that implement `Copy` as well as
+    /// `Iterator`.
+    ///
+    /// **Why is this bad?** Implicit copies can be confusing when working with
+    /// iterator combinators.
+    ///
+    /// **Known problems:** None.
+    ///
+    /// **Example:**
+    /// ```rust,ignore
+    /// #[derive(Copy, Clone)]
+    /// struct Countdown(u8);
+    ///
+    /// impl Iterator for Countdown {
+    ///     // ...
+    /// }
+    ///
+    /// let a: Vec<_> = my_iterator.take(1).collect();
+    /// let b: Vec<_> = my_iterator.collect();
+    /// ```
     pub COPY_ITERATOR,
     pedantic,
     "implementing `Iterator` on a `Copy` type"
 }
 
-pub struct CopyIterator;
-
-impl LintPass for CopyIterator {
-    fn get_lints(&self) -> LintArray {
-        lint_array![COPY_ITERATOR]
-    }
-
-    fn name(&self) -> &'static str {
-        "CopyIterator"
-    }
-}
+declare_lint_pass!(CopyIterator => [COPY_ITERATOR]);
 
 impl<'a, 'tcx> LateLintPass<'a, 'tcx> for CopyIterator {
     fn check_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx Item) {
-        if let ItemKind::Impl(_, _, _, _, Some(ref trait_ref), _, _) = item.node {
-            let ty = cx.tcx.type_of(cx.tcx.hir().local_def_id_from_hir_id(item.hir_id));
+        if let ItemKind::Impl(_, _, _, _, Some(ref trait_ref), _, _) = item.kind {
+            let ty = cx.tcx.type_of(cx.tcx.hir().local_def_id(item.hir_id));
 
             if is_copy(cx, ty) && match_path(&trait_ref.path, &paths::ITERATOR) {
                 span_note_and_lint(