Skip to content

Commit 52cc5fc

Browse files
committed
Auto merge of #5760 - phansch:deprecate-regex-macro, r=Manishearth
Deprecate regex_macro lint Closes #2586 changelog: Deprecate regex_macro lint
2 parents 0860375 + d347d0c commit 52cc5fc

File tree

8 files changed

+26
-69
lines changed

8 files changed

+26
-69
lines changed

clippy_lints/src/deprecated_lints.rs

+9-1
Original file line numberDiff line numberDiff line change
@@ -153,5 +153,13 @@ declare_deprecated_lint! {
153153
///
154154
/// **Deprecation reason:** Associated-constants are now preferred.
155155
pub REPLACE_CONSTS,
156-
"associated-constants `MIN`/`MAX` of integers are prefer to `{min,max}_value()` and module constants"
156+
"associated-constants `MIN`/`MAX` of integers are prefered to `{min,max}_value()` and module constants"
157+
}
158+
159+
declare_deprecated_lint! {
160+
/// **What it does:** Nothing. This lint has been deprecated.
161+
///
162+
/// **Deprecation reason:** The regex! macro does not exist anymore.
163+
pub REGEX_MACRO,
164+
"the regex! macro has been removed from the regex crate in 2018"
157165
}

clippy_lints/src/lib.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,11 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
460460
);
461461
store.register_removed(
462462
"clippy::replace_consts",
463-
"associated-constants `MIN`/`MAX` of integers are prefer to `{min,max}_value()` and module constants",
463+
"associated-constants `MIN`/`MAX` of integers are prefered to `{min,max}_value()` and module constants",
464+
);
465+
store.register_removed(
466+
"clippy::regex_macro",
467+
"the regex! macro has been removed from the regex crate in 2018",
464468
);
465469
// end deprecated lints, do not remove this comment, it’s used in `update_lints`
466470

@@ -755,7 +759,6 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
755759
&reference::DEREF_ADDROF,
756760
&reference::REF_IN_DEREF,
757761
&regex::INVALID_REGEX,
758-
&regex::REGEX_MACRO,
759762
&regex::TRIVIAL_REGEX,
760763
&returns::NEEDLESS_RETURN,
761764
&returns::UNUSED_UNIT,
@@ -1380,7 +1383,6 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
13801383
LintId::of(&reference::DEREF_ADDROF),
13811384
LintId::of(&reference::REF_IN_DEREF),
13821385
LintId::of(&regex::INVALID_REGEX),
1383-
LintId::of(&regex::REGEX_MACRO),
13841386
LintId::of(&regex::TRIVIAL_REGEX),
13851387
LintId::of(&returns::NEEDLESS_RETURN),
13861388
LintId::of(&returns::UNUSED_UNIT),
@@ -1517,7 +1519,6 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
15171519
LintId::of(&redundant_field_names::REDUNDANT_FIELD_NAMES),
15181520
LintId::of(&redundant_pattern_matching::REDUNDANT_PATTERN_MATCHING),
15191521
LintId::of(&redundant_static_lifetimes::REDUNDANT_STATIC_LIFETIMES),
1520-
LintId::of(&regex::REGEX_MACRO),
15211522
LintId::of(&regex::TRIVIAL_REGEX),
15221523
LintId::of(&returns::NEEDLESS_RETURN),
15231524
LintId::of(&returns::UNUSED_UNIT),

clippy_lints/src/regex.rs

+3-54
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
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};
33
use if_chain::if_chain;
44
use rustc_ast::ast::{LitKind, StrStyle};
55
use rustc_data_structures::fx::FxHashSet;
6-
use rustc_hir::{Block, BorrowKind, Crate, Expr, ExprKind, HirId};
6+
use rustc_hir::{BorrowKind, Expr, ExprKind, HirId};
77
use rustc_lint::{LateContext, LateLintPass};
88
use rustc_session::{declare_tool_lint, impl_lint_pass};
99
use rustc_span::source_map::{BytePos, Span};
@@ -46,66 +46,15 @@ declare_clippy_lint! {
4646
"trivial regular expressions"
4747
}
4848

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-
6849
#[derive(Clone, Default)]
6950
pub struct Regex {
7051
spans: FxHashSet<Span>,
7152
last: Option<HirId>,
7253
}
7354

74-
impl_lint_pass!(Regex => [INVALID_REGEX, REGEX_MACRO, TRIVIAL_REGEX]);
55+
impl_lint_pass!(Regex => [INVALID_REGEX, TRIVIAL_REGEX]);
7556

7657
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-
10958
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) {
11059
if_chain! {
11160
if let ExprKind::Call(ref fun, ref args) = expr.kind;

clippy_lints/src/utils/paths.rs

-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,6 @@ pub const RANGE_TO_STD: [&str; 3] = ["std", "ops", "RangeTo"];
9898
pub const RC: [&str; 3] = ["alloc", "rc", "Rc"];
9999
pub const RC_PTR_EQ: [&str; 4] = ["alloc", "rc", "Rc", "ptr_eq"];
100100
pub const RECEIVER: [&str; 4] = ["std", "sync", "mpsc", "Receiver"];
101-
pub const REGEX: [&str; 3] = ["regex", "re_unicode", "Regex"];
102101
pub const REGEX_BUILDER_NEW: [&str; 5] = ["regex", "re_builder", "unicode", "RegexBuilder", "new"];
103102
pub const REGEX_BYTES_BUILDER_NEW: [&str; 5] = ["regex", "re_builder", "bytes", "RegexBuilder", "new"];
104103
pub const REGEX_BYTES_NEW: [&str; 4] = ["regex", "re_bytes", "Regex", "new"];

src/lintlist/mod.rs

-7
Original file line numberDiff line numberDiff line change
@@ -1865,13 +1865,6 @@ pub static ref ALL_LINTS: Vec<Lint> = vec![
18651865
deprecation: None,
18661866
module: "reference",
18671867
},
1868-
Lint {
1869-
name: "regex_macro",
1870-
group: "style",
1871-
desc: "use of `regex!(_)` instead of `Regex::new(_)`",
1872-
deprecation: None,
1873-
module: "regex",
1874-
},
18751868
Lint {
18761869
name: "rest_pat_in_fully_bound_structs",
18771870
group: "restriction",

tests/ui/deprecated.rs

+1
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@
77
#[warn(clippy::invalid_ref)]
88
#[warn(clippy::into_iter_on_array)]
99
#[warn(clippy::unused_label)]
10+
#[warn(clippy::regex_macro)]
1011

1112
fn main() {}

tests/ui/deprecated.stderr

+7-1
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,17 @@ error: lint `clippy::unused_label` has been removed: `this lint has been uplifte
5454
LL | #[warn(clippy::unused_label)]
5555
| ^^^^^^^^^^^^^^^^^^^^
5656

57+
error: lint `clippy::regex_macro` has been removed: `the regex! macro has been removed from the regex crate in 2018`
58+
--> $DIR/deprecated.rs:10:8
59+
|
60+
LL | #[warn(clippy::regex_macro)]
61+
| ^^^^^^^^^^^^^^^^^^^
62+
5763
error: lint `clippy::str_to_string` has been removed: `using `str::to_string` is common even today and specialization will likely happen soon`
5864
--> $DIR/deprecated.rs:1:8
5965
|
6066
LL | #[warn(clippy::str_to_string)]
6167
| ^^^^^^^^^^^^^^^^^^^^^
6268

63-
error: aborting due to 10 previous errors
69+
error: aborting due to 11 previous errors
6470

tests/ui/regex.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#![allow(unused)]
2-
#![warn(clippy::invalid_regex, clippy::trivial_regex, clippy::regex_macro)]
2+
#![warn(clippy::invalid_regex, clippy::trivial_regex)]
33

44
extern crate regex;
55

0 commit comments

Comments
 (0)