]> git.lizzy.rs Git - rust.git/commitdiff
Move linked_list to its own module
authorYoshitomo Nakanishi <yurayura.rounin.3@gmail.com>
Fri, 12 Feb 2021 05:28:17 +0000 (14:28 +0900)
committerYoshitomo Nakanishi <yurayura.rounin.3@gmail.com>
Mon, 8 Mar 2021 15:50:22 +0000 (00:50 +0900)
clippy_lints/src/types/linked_list.rs [new file with mode: 0644]
clippy_lints/src/types/mod.rs
clippy_lints/src/types/option_option.rs

diff --git a/clippy_lints/src/types/linked_list.rs b/clippy_lints/src/types/linked_list.rs
new file mode 100644 (file)
index 0000000..74be895
--- /dev/null
@@ -0,0 +1,20 @@
+use rustc_hir::{self as hir, def_id::DefId};
+use rustc_lint::LateContext;
+
+use crate::utils::{match_def_path, paths, span_lint_and_help};
+
+pub(super) fn check(cx: &LateContext<'_>, hir_ty: &hir::Ty<'_>, def_id: DefId) -> bool {
+    if match_def_path(cx, def_id, &paths::LINKED_LIST) {
+        span_lint_and_help(
+            cx,
+            super::LINKEDLIST,
+            hir_ty.span,
+            "you seem to be using a `LinkedList`! Perhaps you meant some other data structure?",
+            None,
+            "a `VecDeque` might work",
+        );
+        true
+    } else {
+        false
+    }
+}
index 55f1d86bc56b6f5b8e6cb89824effa2ee8c2ab89..86a12b8ffa984e2a65f08578ce36430e475b790b 100644 (file)
@@ -1,6 +1,7 @@
 #![allow(rustc::default_hash_types)]
 
 mod box_vec;
+mod linked_list;
 mod option_option;
 mod rc_buffer;
 mod redundant_allocation;
 use crate::utils::sugg::Sugg;
 use crate::utils::{
     clip, comparisons, differing_macro_contexts, higher, in_constant, indent_of, int_bits, is_hir_ty_cfg_dependant,
-    is_ty_param_diagnostic_item, is_type_diagnostic_item, match_def_path, match_path, meets_msrv, method_chain_args,
-    multispan_sugg, numeric_literal::NumericLiteral, reindent_multiline, sext, snippet, snippet_opt,
-    snippet_with_applicability, snippet_with_macro_callsite, span_lint, span_lint_and_help, span_lint_and_sugg,
-    span_lint_and_then, unsext,
+    is_type_diagnostic_item, match_path, meets_msrv, method_chain_args, multispan_sugg,
+    numeric_literal::NumericLiteral, reindent_multiline, sext, snippet, snippet_opt, snippet_with_applicability,
+    snippet_with_macro_callsite, span_lint, span_lint_and_help, span_lint_and_sugg, span_lint_and_then, unsext,
 };
 
 declare_clippy_lint! {
@@ -313,7 +313,6 @@ fn check_fn_decl(&mut self, cx: &LateContext<'_>, decl: &FnDecl<'_>) {
     ///
     /// The parameter `is_local` distinguishes the context of the type; types from
     /// local bindings should only be checked for the `BORROWED_BOX` lint.
-    #[allow(clippy::too_many_lines)]
     fn check_ty(&mut self, cx: &LateContext<'_>, hir_ty: &hir::Ty<'_>, is_local: bool) {
         if hir_ty.span.from_expansion() {
             return;
@@ -329,18 +328,7 @@ fn check_ty(&mut self, cx: &LateContext<'_>, hir_ty: &hir::Ty<'_>, is_local: boo
                     triggered |= rc_buffer::check(cx, hir_ty, qpath, def_id);
                     triggered |= vec_box::check(cx, hir_ty, qpath, def_id, self.vec_box_size_threshold);
                     triggered |= option_option::check(cx, hir_ty, qpath, def_id);
-
-                    if match_def_path(cx, def_id, &paths::LINKED_LIST) {
-                        span_lint_and_help(
-                            cx,
-                            LINKEDLIST,
-                            hir_ty.span,
-                            "you seem to be using a `LinkedList`! Perhaps you meant some other data structure?",
-                            None,
-                            "a `VecDeque` might work",
-                        );
-                        return; // don't recurse into the type
-                    }
+                    triggered |= linked_list::check(cx, hir_ty, def_id);
 
                     if triggered {
                         return;
@@ -389,7 +377,6 @@ fn check_ty(&mut self, cx: &LateContext<'_>, hir_ty: &hir::Ty<'_>, is_local: boo
                 }
             },
             TyKind::Rptr(ref lt, ref mut_ty) => self.check_ty_rptr(cx, hir_ty, is_local, lt, mut_ty),
-            // recurse
             TyKind::Slice(ref ty) | TyKind::Array(ref ty, _) | TyKind::Ptr(MutTy { ref ty, .. }) => {
                 self.check_ty(cx, ty, is_local)
             },
index 42aad70438b5f4dfaee3b4e5a2bd0aa588ba29bd..d91132aaeb2bd99007441f608a8b4a15ff69ebd0 100644 (file)
@@ -2,13 +2,11 @@
 use rustc_lint::LateContext;
 use rustc_span::symbol::sym;
 
-use crate::utils::span_lint;
-
-use super::utils;
+use crate::utils::{is_ty_param_diagnostic_item, span_lint};
 
 pub(super) fn check(cx: &LateContext<'_>, hir_ty: &hir::Ty<'_>, qpath: &QPath<'_>, def_id: DefId) -> bool {
     if cx.tcx.is_diagnostic_item(sym::option_type, def_id) {
-        if utils::is_ty_param_diagnostic_item(cx, qpath, sym::option_type).is_some() {
+        if is_ty_param_diagnostic_item(cx, qpath, sym::option_type).is_some() {
             span_lint(
                 cx,
                 super::OPTION_OPTION,