The old `match_path` was renamed to `match_qpath`.
As per #1983.
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.
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`
/// 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;
}
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`
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,
};
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.
}}
},
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,
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;
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 &&
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
}
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;
},
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;
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
// `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"]);
}
}
}
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
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);
}
}
}
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.
///
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);
}
}
}
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!("]),");
}
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 {
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,
}
},
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),
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;
return false;
}
if let TyPath(ref path) = inner.node {
- return match_path(path, &paths::LINT);
+ return match_qpath(path, &paths::LINT);
}
}
false
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
}
///
/// # 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,
}
}
-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,
)
///
/// # 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(
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,
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
}
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,