-impl_lint_pass!(Regex => [INVALID_REGEX, REGEX_MACRO, TRIVIAL_REGEX]);
-
-impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Regex {
- fn check_crate(&mut self, _: &LateContext<'a, 'tcx>, _: &'tcx Crate<'_>) {
- self.spans.clear();
- }
-
- fn check_block(&mut self, cx: &LateContext<'a, 'tcx>, block: &'tcx Block<'_>) {
- if_chain! {
- if self.last.is_none();
- if let Some(ref expr) = block.expr;
- if match_type(cx, cx.tables.expr_ty(expr), &paths::REGEX);
- if let Some(span) = is_expn_of(expr.span, "regex");
- then {
- if !self.spans.contains(&span) {
- span_lint(cx,
- REGEX_MACRO,
- span,
- "`regex!(_)` found. \
- Please use `Regex::new(_)`, which is faster for now.");
- self.spans.insert(span);
- }
- self.last = Some(block.hir_id);
- }
- }
- }
-
- fn check_block_post(&mut self, _: &LateContext<'a, 'tcx>, block: &'tcx Block<'_>) {
- if self.last.map_or(false, |id| block.hir_id == id) {
- self.last = None;
- }
- }