diff --git a/clippy_lints/src/map_clone.rs b/clippy_lints/src/map_clone.rs index e126d5c07d7..3bcaccf345a 100644 --- a/clippy_lints/src/map_clone.rs +++ b/clippy_lints/src/map_clone.rs @@ -2,8 +2,8 @@ use rustc::lint::*; 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 { - 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), diff --git a/clippy_lints/src/methods.rs b/clippy_lints/src/methods.rs index 36e6fb4b1a2..67bbed48741 100644 --- a/clippy_lints/src/methods.rs +++ b/clippy_lints/src/methods.rs @@ -10,7 +10,7 @@ use std::fmt; 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 { - 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, diff --git a/clippy_lints/src/utils/mod.rs b/clippy_lints/src/utils/mod.rs index 0c1b10f05c8..94d2caf9c50 100644 --- a/clippy_lints/src/utils/mod.rs +++ b/clippy_lints/src/utils/mod.rs @@ -1034,3 +1034,11 @@ pub fn type_size<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, ty: Ty<'tcx>) -> Option bool { cx.tcx.lint_level_at_node(lint, id).0 == Level::Allow } + +pub fn get_arg_name(pat: &Pat) -> Option { + 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