|
1 | 1 | use crate::consts::{constant, Constant};
|
2 |
| -use crate::utils::{is_expn_of, match_def_path, match_type, paths, span_lint, span_lint_and_help}; |
| 2 | +use crate::utils::{match_def_path, paths, span_lint, span_lint_and_help}; |
3 | 3 | use if_chain::if_chain;
|
4 | 4 | use rustc_ast::ast::{LitKind, StrStyle};
|
5 | 5 | use rustc_data_structures::fx::FxHashSet;
|
6 |
| -use rustc_hir::{Block, BorrowKind, Crate, Expr, ExprKind, HirId}; |
| 6 | +use rustc_hir::{BorrowKind, Expr, ExprKind, HirId}; |
7 | 7 | use rustc_lint::{LateContext, LateLintPass};
|
8 | 8 | use rustc_session::{declare_tool_lint, impl_lint_pass};
|
9 | 9 | use rustc_span::source_map::{BytePos, Span};
|
@@ -46,66 +46,15 @@ declare_clippy_lint! {
|
46 | 46 | "trivial regular expressions"
|
47 | 47 | }
|
48 | 48 |
|
49 |
| -declare_clippy_lint! { |
50 |
| - /// **What it does:** Checks for usage of `regex!(_)` which (as of now) is |
51 |
| - /// usually slower than `Regex::new(_)` unless called in a loop (which is a bad |
52 |
| - /// idea anyway). |
53 |
| - /// |
54 |
| - /// **Why is this bad?** Performance, at least for now. The macro version is |
55 |
| - /// likely to catch up long-term, but for now the dynamic version is faster. |
56 |
| - /// |
57 |
| - /// **Known problems:** None. |
58 |
| - /// |
59 |
| - /// **Example:** |
60 |
| - /// ```ignore |
61 |
| - /// regex!("foo|bar") |
62 |
| - /// ``` |
63 |
| - pub REGEX_MACRO, |
64 |
| - style, |
65 |
| - "use of `regex!(_)` instead of `Regex::new(_)`" |
66 |
| -} |
67 |
| - |
68 | 49 | #[derive(Clone, Default)]
|
69 | 50 | pub struct Regex {
|
70 | 51 | spans: FxHashSet<Span>,
|
71 | 52 | last: Option<HirId>,
|
72 | 53 | }
|
73 | 54 |
|
74 |
| -impl_lint_pass!(Regex => [INVALID_REGEX, REGEX_MACRO, TRIVIAL_REGEX]); |
| 55 | +impl_lint_pass!(Regex => [INVALID_REGEX, TRIVIAL_REGEX]); |
75 | 56 |
|
76 | 57 | impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Regex {
|
77 |
| - fn check_crate(&mut self, _: &LateContext<'a, 'tcx>, _: &'tcx Crate<'_>) { |
78 |
| - self.spans.clear(); |
79 |
| - } |
80 |
| - |
81 |
| - fn check_block(&mut self, cx: &LateContext<'a, 'tcx>, block: &'tcx Block<'_>) { |
82 |
| - if_chain! { |
83 |
| - if self.last.is_none(); |
84 |
| - if let Some(ref expr) = block.expr; |
85 |
| - if match_type(cx, cx.tables().expr_ty(expr), &paths::REGEX); |
86 |
| - if let Some(span) = is_expn_of(expr.span, "regex"); |
87 |
| - then { |
88 |
| - if !self.spans.contains(&span) { |
89 |
| - span_lint( |
90 |
| - cx, |
91 |
| - REGEX_MACRO, |
92 |
| - span, |
93 |
| - "`regex!(_)` found. \ |
94 |
| - Please use `Regex::new(_)`, which is faster for now." |
95 |
| - ); |
96 |
| - self.spans.insert(span); |
97 |
| - } |
98 |
| - self.last = Some(block.hir_id); |
99 |
| - } |
100 |
| - } |
101 |
| - } |
102 |
| - |
103 |
| - fn check_block_post(&mut self, _: &LateContext<'a, 'tcx>, block: &'tcx Block<'_>) { |
104 |
| - if self.last.map_or(false, |id| block.hir_id == id) { |
105 |
| - self.last = None; |
106 |
| - } |
107 |
| - } |
108 |
| - |
109 | 58 | fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) {
|
110 | 59 | if_chain! {
|
111 | 60 | if let ExprKind::Call(ref fun, ref args) = expr.kind;
|
|
0 commit comments