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.
///
}
}
-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),
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};
}
}
-// 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,
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