Use {get,match}_def_path from LateContext
This commit is contained in:
parent
2f100e04af
commit
840eac2c05
25 changed files with 122 additions and 128 deletions
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
#![deny(clippy::missing_docs_in_private_items)]
|
||||
|
||||
use crate::utils::{is_expn_of, match_def_path, match_qpath, paths, resolve_node};
|
||||
use crate::utils::{is_expn_of, match_qpath, paths, resolve_node};
|
||||
use if_chain::if_chain;
|
||||
use rustc::lint::LateContext;
|
||||
use rustc::{hir, ty};
|
||||
|
|
@ -216,11 +216,11 @@ pub fn vec_macro<'e>(cx: &LateContext<'_, '_>, expr: &'e hir::Expr) -> Option<Ve
|
|||
if is_expn_of(fun.span, "vec").is_some();
|
||||
if let Some(fun_def_id) = resolve_node(cx, path, fun.hir_id).opt_def_id();
|
||||
then {
|
||||
return if match_def_path(cx.tcx, fun_def_id, &paths::VEC_FROM_ELEM) && args.len() == 2 {
|
||||
return if cx.match_def_path(fun_def_id, &paths::VEC_FROM_ELEM) && args.len() == 2 {
|
||||
// `vec![elem; size]` case
|
||||
Some(VecArgs::Repeat(&args[0], &args[1]))
|
||||
}
|
||||
else if match_def_path(cx.tcx, fun_def_id, &paths::SLICE_INTO_VEC) && args.len() == 1 {
|
||||
else if cx.match_def_path(fun_def_id, &paths::SLICE_INTO_VEC) && args.len() == 1 {
|
||||
// `vec![a, b, c]` case
|
||||
if_chain! {
|
||||
if let hir::ExprKind::Box(ref boxed) = args[0].node;
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
use crate::utils::{match_def_path, match_type, paths, span_help_and_lint, span_lint, walk_ptrs_ty};
|
||||
use crate::utils::{match_type, paths, span_help_and_lint, span_lint, walk_ptrs_ty};
|
||||
use if_chain::if_chain;
|
||||
use rustc::hir;
|
||||
use rustc::hir::def::Def;
|
||||
|
|
@ -144,7 +144,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for LintWithoutLintPass {
|
|||
if_chain! {
|
||||
if let hir::TraitRef{path, ..} = trait_ref;
|
||||
if let Def::Trait(def_id) = path.def;
|
||||
if match_def_path(cx.tcx, def_id, &paths::LINT_PASS);
|
||||
if cx.match_def_path(def_id, &paths::LINT_PASS);
|
||||
then {
|
||||
let mut collector = LintCollector {
|
||||
output: &mut self.registered_lints,
|
||||
|
|
@ -196,7 +196,7 @@ fn is_lint_ref_type<'tcx>(cx: &LateContext<'_, 'tcx>, ty: &Ty) -> bool {
|
|||
{
|
||||
if let TyKind::Path(ref path) = inner.node {
|
||||
if let Def::Struct(def_id) = cx.tables.qpath_def(path, inner.hir_id) {
|
||||
return match_def_path(cx.tcx, def_id, &paths::LINT);
|
||||
return cx.match_def_path(def_id, &paths::LINT);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -96,7 +96,7 @@ pub fn in_macro(span: Span) -> bool {
|
|||
/// Checks if type is struct, enum or union type with the given def path.
|
||||
pub fn match_type(cx: &LateContext<'_, '_>, ty: Ty<'_>, path: &[&str]) -> bool {
|
||||
match ty.sty {
|
||||
ty::Adt(adt, _) => match_def_path(cx.tcx, adt.did, path),
|
||||
ty::Adt(adt, _) => cx.match_def_path(adt.did, path),
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
|
@ -106,7 +106,7 @@ pub fn match_trait_method(cx: &LateContext<'_, '_>, expr: &Expr, path: &[&str])
|
|||
let def_id = cx.tables.type_dependent_def_id(expr.hir_id).unwrap();
|
||||
let trt_id = cx.tcx.trait_of_item(def_id);
|
||||
if let Some(trt_id) = trt_id {
|
||||
match_def_path(cx.tcx, trt_id, path)
|
||||
cx.match_def_path(trt_id, path)
|
||||
} else {
|
||||
false
|
||||
}
|
||||
|
|
@ -989,7 +989,7 @@ pub fn has_iter_method(cx: &LateContext<'_, '_>, probably_ref_ty: Ty<'_>) -> Opt
|
|||
};
|
||||
|
||||
for path in &INTO_ITER_COLLECTIONS {
|
||||
if match_def_path(cx.tcx, def_id, path) {
|
||||
if cx.match_def_path(def_id, path) {
|
||||
return Some(path.last().unwrap());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue