Avoid looking regex crate up multiple times
This commit is contained in:
parent
d099ceddad
commit
6b34c8df2c
@ -3,7 +3,7 @@ use std::fmt::Display;
|
|||||||
use clippy_utils::consts::{ConstEvalCtxt, Constant};
|
use clippy_utils::consts::{ConstEvalCtxt, Constant};
|
||||||
use clippy_utils::diagnostics::{span_lint, span_lint_and_help};
|
use clippy_utils::diagnostics::{span_lint, span_lint_and_help};
|
||||||
use clippy_utils::source::SpanRangeExt;
|
use clippy_utils::source::SpanRangeExt;
|
||||||
use clippy_utils::{def_path_def_ids, path_def_id, paths};
|
use clippy_utils::{def_path_res_with_base, find_crates, path_def_id, paths};
|
||||||
use rustc_ast::ast::{LitKind, StrStyle};
|
use rustc_ast::ast::{LitKind, StrStyle};
|
||||||
use rustc_hir::def_id::DefIdMap;
|
use rustc_hir::def_id::DefIdMap;
|
||||||
use rustc_hir::{BorrowKind, Expr, ExprKind};
|
use rustc_hir::{BorrowKind, Expr, ExprKind};
|
||||||
@ -75,12 +75,15 @@ impl<'tcx> LateLintPass<'tcx> for Regex {
|
|||||||
// We don't use `match_def_path` here because that relies on matching the exact path, which changed
|
// We don't use `match_def_path` here because that relies on matching the exact path, which changed
|
||||||
// between regex 1.8 and 1.9
|
// between regex 1.8 and 1.9
|
||||||
//
|
//
|
||||||
// `def_path_def_ids` will resolve through re-exports but is relatively heavy, so we only perform
|
// `def_path_res_with_base` will resolve through re-exports but is relatively heavy, so we only
|
||||||
// the operation once and store the results
|
// perform the operation once and store the results
|
||||||
let mut resolve = |path, kind| {
|
let regex_crates = find_crates(cx.tcx, sym!(regex));
|
||||||
for id in def_path_def_ids(cx.tcx, path) {
|
let mut resolve = |path: &[&str], kind: RegexKind| {
|
||||||
|
for res in def_path_res_with_base(cx.tcx, regex_crates.clone(), &path[1..]) {
|
||||||
|
if let Some(id) = res.opt_def_id() {
|
||||||
self.definitions.insert(id, kind);
|
self.definitions.insert(id, kind);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
resolve(&paths::REGEX_NEW, RegexKind::Unicode);
|
resolve(&paths::REGEX_NEW, RegexKind::Unicode);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user