Skip to content

Commit

Permalink
Avoid looking regex crate up multiple times
Browse files Browse the repository at this point in the history
  • Loading branch information
GnomedDev committed Sep 23, 2024
1 parent d099ced commit 6b34c8d
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions clippy_lints/src/regex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::fmt::Display;
use clippy_utils::consts::{ConstEvalCtxt, Constant};
use clippy_utils::diagnostics::{span_lint, span_lint_and_help};
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_hir::def_id::DefIdMap;
use rustc_hir::{BorrowKind, Expr, ExprKind};
Expand Down Expand Up @@ -75,11 +75,14 @@ impl<'tcx> LateLintPass<'tcx> for Regex {
// 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
//
// `def_path_def_ids` will resolve through re-exports but is relatively heavy, so we only perform
// the operation once and store the results
let mut resolve = |path, kind| {
for id in def_path_def_ids(cx.tcx, path) {
self.definitions.insert(id, kind);
// `def_path_res_with_base` will resolve through re-exports but is relatively heavy, so we only
// perform the operation once and store the results
let regex_crates = find_crates(cx.tcx, sym!(regex));
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);
}
}
};

Expand Down

0 comments on commit 6b34c8d

Please sign in to comment.