From 695bedbe270cbae05d19b7837a95d12d7bd9637a Mon Sep 17 00:00:00 2001 From: Alexey Zabelin Date: Thu, 24 Aug 2017 18:21:46 -0400 Subject: [PATCH] Rename `match_path_old` to `match_path` The old `match_path` was renamed to `match_qpath`. As per #1983. --- clippy_lints/src/derive.rs | 6 +++--- .../src/if_let_redundant_pattern_matching.rs | 10 +++++----- clippy_lints/src/map_clone.rs | 4 ++-- clippy_lints/src/methods.rs | 8 ++++---- clippy_lints/src/misc.rs | 4 ++-- clippy_lints/src/print.rs | 4 ++-- clippy_lints/src/ptr.rs | 4 ++-- clippy_lints/src/unused_io_amount.rs | 4 ++-- clippy_lints/src/utils/author.rs | 2 +- clippy_lints/src/utils/higher.rs | 14 +++++++------- clippy_lints/src/utils/internal_lints.rs | 6 +++--- clippy_lints/src/utils/mod.rs | 16 ++++++++-------- tests/ui/trailing_zeros.stdout | 2 +- 13 files changed, 42 insertions(+), 42 deletions(-) diff --git a/clippy_lints/src/derive.rs b/clippy_lints/src/derive.rs index e186dd5e4db..36576365eac 100644 --- a/clippy_lints/src/derive.rs +++ b/clippy_lints/src/derive.rs @@ -3,7 +3,7 @@ use rustc::hir::*; use syntax::codemap::Span; use utils::paths; -use utils::{is_automatically_derived, span_lint_and_then, match_path_old, is_copy}; +use utils::{is_automatically_derived, span_lint_and_then, match_path, is_copy}; /// **What it does:** Checks for deriving `Hash` but implementing `PartialEq` /// explicitly. @@ -92,7 +92,7 @@ fn check_hash_peq<'a, 'tcx>( hash_is_automatically_derived: bool, ) { if_let_chain! {[ - match_path_old(&trait_ref.path, &paths::HASH), + match_path(&trait_ref.path, &paths::HASH), let Some(peq_trait_def_id) = cx.tcx.lang_items.eq_trait() ], { // Look for the PartialEq implementations for `ty` @@ -132,7 +132,7 @@ fn check_hash_peq<'a, 'tcx>( /// Implementation of the `EXPL_IMPL_CLONE_ON_COPY` lint. fn check_copy_clone<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, item: &Item, trait_ref: &TraitRef, ty: Ty<'tcx>) { - if match_path_old(&trait_ref.path, &paths::CLONE_TRAIT) { + if match_path(&trait_ref.path, &paths::CLONE_TRAIT) { if !is_copy(cx, ty) { return; } diff --git a/clippy_lints/src/if_let_redundant_pattern_matching.rs b/clippy_lints/src/if_let_redundant_pattern_matching.rs index 058052769ef..0e1dd6449ab 100644 --- a/clippy_lints/src/if_let_redundant_pattern_matching.rs +++ b/clippy_lints/src/if_let_redundant_pattern_matching.rs @@ -1,7 +1,7 @@ use rustc::lint::*; use rustc::hir::*; use syntax::codemap::Span; -use utils::{paths, span_lint_and_then, match_path, snippet}; +use utils::{paths, span_lint_and_then, match_qpath, snippet}; /// **What it does:*** Lint for redundant pattern matching over `Result` or /// `Option` @@ -53,18 +53,18 @@ fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) { let good_method = match arms[0].pats[0].node { PatKind::TupleStruct(ref path, ref pats, _) if pats.len() == 1 && pats[0].node == PatKind::Wild => { - if match_path(path, &paths::RESULT_OK) { + if match_qpath(path, &paths::RESULT_OK) { "is_ok()" - } else if match_path(path, &paths::RESULT_ERR) { + } else if match_qpath(path, &paths::RESULT_ERR) { "is_err()" - } else if match_path(path, &paths::OPTION_SOME) { + } else if match_qpath(path, &paths::OPTION_SOME) { "is_some()" } else { return; } }, - PatKind::Path(ref path) if match_path(path, &paths::OPTION_NONE) => "is_none()", + PatKind::Path(ref path) if match_qpath(path, &paths::OPTION_NONE) => "is_none()", _ => return, }; diff --git a/clippy_lints/src/map_clone.rs b/clippy_lints/src/map_clone.rs index 457c6cc8d65..fcb84e90eb6 100644 --- a/clippy_lints/src/map_clone.rs +++ b/clippy_lints/src/map_clone.rs @@ -2,7 +2,7 @@ use rustc::hir::*; use rustc::ty; use syntax::ast; -use utils::{is_adjusted, match_path, match_trait_method, match_type, remove_blocks, paths, snippet, +use utils::{is_adjusted, match_qpath, match_trait_method, match_type, remove_blocks, paths, snippet, span_help_and_lint, walk_ptrs_ty, walk_ptrs_ty_depth, iter_input_pats}; /// **What it does:** Checks for mapping `clone()` over an iterator. @@ -74,7 +74,7 @@ fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) { }} }, ExprPath(ref path) => { - if match_path(path, &paths::CLONE) { + if match_qpath(path, &paths::CLONE) { let type_name = get_type_name(cx, expr, &args[0]).unwrap_or("_"); span_help_and_lint( cx, diff --git a/clippy_lints/src/methods.rs b/clippy_lints/src/methods.rs index a50d77f5521..1811142ae27 100644 --- a/clippy_lints/src/methods.rs +++ b/clippy_lints/src/methods.rs @@ -8,10 +8,10 @@ use std::borrow::Cow; use std::fmt; use syntax::codemap::Span; -use utils::{get_trait_def_id, implements_trait, in_external_macro, in_macro, is_copy, match_path, match_trait_method, +use utils::{get_trait_def_id, implements_trait, in_external_macro, in_macro, is_copy, match_qpath, match_trait_method, match_type, method_chain_args, return_ty, same_tys, snippet, span_lint, span_lint_and_then, span_lint_and_sugg, span_note_and_lint, walk_ptrs_ty, walk_ptrs_ty_depth, last_path_segment, - single_segment_path, match_def_path, is_self, is_self_ty, iter_input_pats, match_path_old}; + single_segment_path, match_def_path, is_self, is_self_ty, iter_input_pats, match_path}; use utils::paths; use utils::sugg; @@ -1462,7 +1462,7 @@ fn is_as_ref_or_mut_trait(ty: &hir::Ty, self_ty: &hir::Ty, generics: &hir::Gener param.bounds.iter().any(|bound| { if let hir::TyParamBound::TraitTyParamBound(ref ptr, ..) = *bound { let path = &ptr.trait_ref.path; - match_path_old(path, name) && + match_path(path, name) && path.segments.last().map_or(false, |s| { if let hir::PathParameters::AngleBracketedParameters(ref data) = s.parameters { data.types.len() == 1 && @@ -1540,7 +1540,7 @@ fn matches(&self, ty: &hir::FunctionRetTy) -> bool { fn is_bool(ty: &hir::Ty) -> bool { if let hir::TyPath(ref p) = ty.node { - match_path(p, &["bool"]) + match_qpath(p, &["bool"]) } else { false } diff --git a/clippy_lints/src/misc.rs b/clippy_lints/src/misc.rs index ef42bfe0b02..43c539a7a65 100644 --- a/clippy_lints/src/misc.rs +++ b/clippy_lints/src/misc.rs @@ -8,7 +8,7 @@ use rustc_const_eval::ConstContext; use rustc_const_math::ConstFloat; use syntax::codemap::{Span, ExpnFormat}; -use utils::{get_item_name, get_parent_expr, implements_trait, in_macro, is_integer_literal, match_path, snippet, +use utils::{get_item_name, get_parent_expr, implements_trait, in_macro, is_integer_literal, match_qpath, snippet, span_lint, span_lint_and_then, walk_ptrs_ty, last_path_segment, iter_input_pats, in_constant, match_trait_method, paths}; use utils::sugg::Sugg; @@ -486,7 +486,7 @@ fn check_to_owned(cx: &LateContext, expr: &Expr, other: &Expr) { }, ExprCall(ref path, ref v) if v.len() == 1 => { if let ExprPath(ref path) = path.node { - if match_path(path, &["String", "from_str"]) || match_path(path, &["String", "from"]) { + if match_qpath(path, &["String", "from_str"]) || match_qpath(path, &["String", "from"]) { (cx.tables.expr_ty_adjusted(&v[0]), snippet(cx, v[0].span, "..")) } else { return; diff --git a/clippy_lints/src/print.rs b/clippy_lints/src/print.rs index 4a427fc79bd..982b46e20d3 100644 --- a/clippy_lints/src/print.rs +++ b/clippy_lints/src/print.rs @@ -2,7 +2,7 @@ use rustc::hir::map::Node::{NodeItem, NodeImplItem}; use rustc::lint::*; use utils::paths; -use utils::{is_expn_of, match_def_path, resolve_node, span_lint, match_path_old}; +use utils::{is_expn_of, match_def_path, resolve_node, span_lint, match_path}; use format::get_argument_fmtstr_parts; /// **What it does:** This lint warns when you using `print!()` with a format @@ -144,7 +144,7 @@ fn is_in_debug_impl(cx: &LateContext, expr: &Expr) -> bool { // `Debug` impl if let Some(NodeItem(item)) = map.find(map.get_parent(item.id)) { if let ItemImpl(_, _, _, _, Some(ref tr), _, _) = item.node { - return match_path_old(&tr.path, &["Debug"]); + return match_path(&tr.path, &["Debug"]); } } } diff --git a/clippy_lints/src/ptr.rs b/clippy_lints/src/ptr.rs index 5b5c63c1aca..a21142a257d 100644 --- a/clippy_lints/src/ptr.rs +++ b/clippy_lints/src/ptr.rs @@ -7,7 +7,7 @@ use syntax::ast::NodeId; use syntax::codemap::Span; use syntax_pos::MultiSpan; -use utils::{match_path, match_type, paths, span_lint, span_lint_and_then}; +use utils::{match_qpath, match_type, paths, span_lint, span_lint_and_then}; /// **What it does:** This lint checks for function arguments of type `&String` /// or `&Vec` unless @@ -190,7 +190,7 @@ fn is_null_path(expr: &Expr) -> bool { if let ExprCall(ref pathexp, ref args) = expr.node { if args.is_empty() { if let ExprPath(ref path) = pathexp.node { - return match_path(path, &paths::PTR_NULL) || match_path(path, &paths::PTR_NULL_MUT); + return match_qpath(path, &paths::PTR_NULL) || match_qpath(path, &paths::PTR_NULL_MUT); } } } diff --git a/clippy_lints/src/unused_io_amount.rs b/clippy_lints/src/unused_io_amount.rs index ff2148c88a9..1ac775ce7c1 100644 --- a/clippy_lints/src/unused_io_amount.rs +++ b/clippy_lints/src/unused_io_amount.rs @@ -1,6 +1,6 @@ use rustc::lint::*; use rustc::hir; -use utils::{span_lint, match_path, match_trait_method, is_try, paths}; +use utils::{span_lint, match_qpath, match_trait_method, is_try, paths}; /// **What it does:** Checks for unused written/read amount. /// @@ -49,7 +49,7 @@ fn check_stmt(&mut self, cx: &LateContext, s: &hir::Stmt) { hir::ExprMatch(ref res, _, _) if is_try(expr).is_some() => { if let hir::ExprCall(ref func, ref args) = res.node { if let hir::ExprPath(ref path) = func.node { - if match_path(path, &paths::TRY_INTO_RESULT) && args.len() == 1 { + if match_qpath(path, &paths::TRY_INTO_RESULT) && args.len() == 1 { check_method_call(cx, &args[0], expr); } } diff --git a/clippy_lints/src/utils/author.rs b/clippy_lints/src/utils/author.rs index a7fdc3d281b..ba8f0022b32 100644 --- a/clippy_lints/src/utils/author.rs +++ b/clippy_lints/src/utils/author.rs @@ -428,7 +428,7 @@ fn visit_expr(&mut self, expr: &Expr) { } fn visit_qpath(&mut self, path: &QPath, _: NodeId, _: Span) { - print!(" match_path({}, &[", self.current); + print!(" match_qpath({}, &[", self.current); print_path(path, &mut true); println!("]),"); } diff --git a/clippy_lints/src/utils/higher.rs b/clippy_lints/src/utils/higher.rs index 67319f0c355..aa57e12bca8 100644 --- a/clippy_lints/src/utils/higher.rs +++ b/clippy_lints/src/utils/higher.rs @@ -6,7 +6,7 @@ use rustc::hir; use rustc::lint::LateContext; use syntax::ast; -use utils::{is_expn_of, match_path, match_def_path, resolve_node, paths}; +use utils::{is_expn_of, match_qpath, match_def_path, resolve_node, paths}; /// Convert a hir binary operator to the corresponding `ast` type. pub fn binop(op: hir::BinOp_) -> ast::BinOpKind { @@ -63,7 +63,7 @@ fn get_field<'a>(name: &str, fields: &'a [hir::Field]) -> Option<&'a hir::Expr> match expr.node { hir::ExprPath(ref path) => { - if match_path(path, &paths::RANGE_FULL_STD) || match_path(path, &paths::RANGE_FULL) { + if match_qpath(path, &paths::RANGE_FULL_STD) || match_qpath(path, &paths::RANGE_FULL) { Some(Range { start: None, end: None, @@ -74,31 +74,31 @@ fn get_field<'a>(name: &str, fields: &'a [hir::Field]) -> Option<&'a hir::Expr> } }, hir::ExprStruct(ref path, ref fields, None) => { - if match_path(path, &paths::RANGE_FROM_STD) || match_path(path, &paths::RANGE_FROM) { + if match_qpath(path, &paths::RANGE_FROM_STD) || match_qpath(path, &paths::RANGE_FROM) { Some(Range { start: get_field("start", fields), end: None, limits: ast::RangeLimits::HalfOpen, }) - } else if match_path(path, &paths::RANGE_INCLUSIVE_STD) || match_path(path, &paths::RANGE_INCLUSIVE) { + } else if match_qpath(path, &paths::RANGE_INCLUSIVE_STD) || match_qpath(path, &paths::RANGE_INCLUSIVE) { Some(Range { start: get_field("start", fields), end: get_field("end", fields), limits: ast::RangeLimits::Closed, }) - } else if match_path(path, &paths::RANGE_STD) || match_path(path, &paths::RANGE) { + } else if match_qpath(path, &paths::RANGE_STD) || match_qpath(path, &paths::RANGE) { Some(Range { start: get_field("start", fields), end: get_field("end", fields), limits: ast::RangeLimits::HalfOpen, }) - } else if match_path(path, &paths::RANGE_TO_INCLUSIVE_STD) || match_path(path, &paths::RANGE_TO_INCLUSIVE) { + } else if match_qpath(path, &paths::RANGE_TO_INCLUSIVE_STD) || match_qpath(path, &paths::RANGE_TO_INCLUSIVE) { Some(Range { start: None, end: get_field("end", fields), limits: ast::RangeLimits::Closed, }) - } else if match_path(path, &paths::RANGE_TO_STD) || match_path(path, &paths::RANGE_TO) { + } else if match_qpath(path, &paths::RANGE_TO_STD) || match_qpath(path, &paths::RANGE_TO) { Some(Range { start: None, end: get_field("end", fields), diff --git a/clippy_lints/src/utils/internal_lints.rs b/clippy_lints/src/utils/internal_lints.rs index f81aff24338..d83e094212a 100644 --- a/clippy_lints/src/utils/internal_lints.rs +++ b/clippy_lints/src/utils/internal_lints.rs @@ -1,7 +1,7 @@ use rustc::lint::*; use rustc::hir::*; use rustc::hir::intravisit::{Visitor, walk_expr, NestedVisitorMap}; -use utils::{paths, match_path, span_lint}; +use utils::{paths, match_qpath, span_lint}; use syntax::symbol::InternedString; use syntax::ast::{Name, NodeId, ItemKind, Crate as AstCrate}; use syntax::codemap::Span; @@ -167,7 +167,7 @@ fn is_lint_ref_type(ty: &Ty) -> bool { return false; } if let TyPath(ref path) = inner.node { - return match_path(path, &paths::LINT); + return match_qpath(path, &paths::LINT); } } false @@ -176,7 +176,7 @@ fn is_lint_ref_type(ty: &Ty) -> bool { fn is_lint_array_type(ty: &Ty) -> bool { if let TyPath(ref path) = ty.node { - match_path(path, &paths::LINT_ARRAY) + match_qpath(path, &paths::LINT_ARRAY) } else { false } diff --git a/clippy_lints/src/utils/mod.rs b/clippy_lints/src/utils/mod.rs index c24ccd5d573..c08f7d4254f 100644 --- a/clippy_lints/src/utils/mod.rs +++ b/clippy_lints/src/utils/mod.rs @@ -240,15 +240,15 @@ pub fn single_segment_path(path: &QPath) -> Option<&PathSegment> { /// /// # Examples /// ```rust,ignore -/// match_path(path, &["std", "rt", "begin_unwind"]) +/// match_qpath(path, &["std", "rt", "begin_unwind"]) /// ``` -pub fn match_path(path: &QPath, segments: &[&str]) -> bool { +pub fn match_qpath(path: &QPath, segments: &[&str]) -> bool { match *path { - QPath::Resolved(_, ref path) => match_path_old(path, segments), + QPath::Resolved(_, ref path) => match_path(path, segments), QPath::TypeRelative(ref ty, ref segment) => { match ty.node { TyPath(ref inner_path) => { - !segments.is_empty() && match_path(inner_path, &segments[..(segments.len() - 1)]) && + !segments.is_empty() && match_qpath(inner_path, &segments[..(segments.len() - 1)]) && segment.name == segments[segments.len() - 1] }, _ => false, @@ -257,7 +257,7 @@ pub fn match_path(path: &QPath, segments: &[&str]) -> bool { } } -pub fn match_path_old(path: &Path, segments: &[&str]) -> bool { +pub fn match_path(path: &Path, segments: &[&str]) -> bool { path.segments.iter().rev().zip(segments.iter().rev()).all( |(a, b)| a.name == *b, ) @@ -267,7 +267,7 @@ pub fn match_path_old(path: &Path, segments: &[&str]) -> bool { /// /// # Examples /// ```rust,ignore -/// match_path(path, &["std", "rt", "begin_unwind"]) +/// match_qpath(path, &["std", "rt", "begin_unwind"]) /// ``` pub fn match_path_ast(path: &ast::Path, segments: &[&str]) -> bool { path.segments.iter().rev().zip(segments.iter().rev()).all( @@ -988,7 +988,7 @@ pub fn is_try(expr: &Expr) -> Option<&Expr> { fn is_ok(arm: &Arm) -> bool { if_let_chain! {[ let PatKind::TupleStruct(ref path, ref pat, None) = arm.pats[0].node, - match_path(path, &paths::RESULT_OK[1..]), + match_qpath(path, &paths::RESULT_OK[1..]), let PatKind::Binding(_, defid, _, None) = pat[0].node, let ExprPath(QPath::Resolved(None, ref path)) = arm.body.node, path.def.def_id() == defid, @@ -1000,7 +1000,7 @@ fn is_ok(arm: &Arm) -> bool { fn is_err(arm: &Arm) -> bool { if let PatKind::TupleStruct(ref path, _, _) = arm.pats[0].node { - match_path(path, &paths::RESULT_ERR[1..]) + match_qpath(path, &paths::RESULT_ERR[1..]) } else { false } diff --git a/tests/ui/trailing_zeros.stdout b/tests/ui/trailing_zeros.stdout index 98025316da4..52ec01260be 100644 --- a/tests/ui/trailing_zeros.stdout +++ b/tests/ui/trailing_zeros.stdout @@ -4,7 +4,7 @@ if_let_chain!{[ let Expr_::ExprBinary(ref op1, ref left1, ref right1) = left.node, BinOp_::BiBitAnd == op1.node, let Expr_::ExprPath(ref path) = left1.node, - match_path(path, &["x"]), + match_qpath(path, &["x"]), let Expr_::ExprLit(ref lit) = right1.node, let LitKind::Int(15, _) = lit.node, let Expr_::ExprLit(ref lit1) = right.node, -- 2.44.0