]> git.lizzy.rs Git - rust.git/commitdiff
Move get_arg_name into utils
authorPhil Ellison <phil.j.ellison@gmail.com>
Sun, 14 Jan 2018 10:05:01 +0000 (10:05 +0000)
committerPhil Ellison <phil.j.ellison@gmail.com>
Sun, 14 Jan 2018 10:05:01 +0000 (10:05 +0000)
clippy_lints/src/map_clone.rs
clippy_lints/src/methods.rs
clippy_lints/src/utils/mod.rs

index e126d5c07d700ae6887ef457402165399affa301..3bcaccf345a9796c9f0bea15ff7f4c4813f71459 100644 (file)
@@ -2,8 +2,8 @@
 use rustc::hir::*;
 use rustc::ty;
 use syntax::ast;
-use utils::{is_adjusted, iter_input_pats, match_qpath, match_trait_method, match_type, paths, remove_blocks, snippet,
-            span_help_and_lint, walk_ptrs_ty, walk_ptrs_ty_depth};
+use utils::{get_arg_name, is_adjusted, iter_input_pats, match_qpath, match_trait_method, match_type,
+            paths, remove_blocks, snippet, span_help_and_lint, walk_ptrs_ty, walk_ptrs_ty_depth};
 
 /// **What it does:** Checks for mapping `clone()` over an iterator.
 ///
@@ -121,14 +121,6 @@ fn get_type_name(cx: &LateContext, expr: &Expr, arg: &Expr) -> Option<&'static s
     }
 }
 
-fn get_arg_name(pat: &Pat) -> Option<ast::Name> {
-    match pat.node {
-        PatKind::Binding(_, _, name, None) => Some(name.node),
-        PatKind::Ref(ref subpat, _) => get_arg_name(subpat),
-        _ => None,
-    }
-}
-
 fn only_derefs(cx: &LateContext, expr: &Expr, id: ast::Name) -> bool {
     match expr.node {
         ExprUnary(UnDeref, ref subexpr) if !is_adjusted(cx, subexpr) => only_derefs(cx, subexpr, id),
index 36e6fb4b1a29a11b6ddd242a0ff45181908dd0f5..67bbed487419eb9efcb7379de23df4762d50ddd4 100644 (file)
@@ -10,7 +10,7 @@
 use std::iter;
 use syntax::ast;
 use syntax::codemap::Span;
-use utils::{get_trait_def_id, implements_trait, in_external_macro, in_macro, is_copy, is_self, is_self_ty,
+use utils::{get_arg_name, get_trait_def_id, implements_trait, in_external_macro, in_macro, is_copy, is_self, is_self_ty,
             iter_input_pats, last_path_segment, match_def_path, match_path, match_qpath, match_trait_method,
             match_type, method_chain_args, return_ty, remove_blocks, same_tys, single_segment_path, snippet, span_lint,
             span_lint_and_sugg, span_lint_and_then, span_note_and_lint, walk_ptrs_ty, walk_ptrs_ty_depth};
@@ -1125,15 +1125,6 @@ fn lint_iter_cloned_collect(cx: &LateContext, expr: &hir::Expr, iter_args: &[hir
     }
 }
 
-// DONOTMERGE: copy-pasted from map_clone
-fn get_arg_name(pat: &hir::Pat) -> Option<ast::Name> {
-    match pat.node {
-        hir::PatKind::Binding(_, _, name, None) => Some(name.node),
-        hir::PatKind::Ref(ref subpat, _) => get_arg_name(subpat),
-        _ => None,
-    }
-}
-
 fn lint_fold_any(cx: &LateContext, expr: &hir::Expr, fold_args: &[hir::Expr]) {
     // DONOTMERGE: What if this is just some other method called fold?
     assert!(fold_args.len() == 3,
index 0c1b10f05c89e77dd2243ad0d1d2c1bfb0145e8e..94d2caf9c50f6c135bd567a7cfc513e6cc4f76b8 100644 (file)
@@ -1034,3 +1034,11 @@ pub fn type_size<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, ty: Ty<'tcx>) -> Option<u
 pub fn is_allowed(cx: &LateContext, lint: &'static Lint, id: NodeId) -> bool {
     cx.tcx.lint_level_at_node(lint, id).0 == Level::Allow
 }
+
+pub fn get_arg_name(pat: &Pat) -> Option<ast::Name> {
+    match pat.node {
+        PatKind::Binding(_, _, name, None) => Some(name.node),
+        PatKind::Ref(ref subpat, _) => get_arg_name(subpat),
+        _ => None,
+    }
+}
\ No newline at end of file