Skip to content

Commit 4bbd7e4

Browse files
committed
Auto merge of #6696 - dtolnay-contrib:regex, r=Manishearth
Downgrade trivial_regex to nursery See #6690. I think there is still value in a trivial_regex lint, but only if clippy can tell that the regex is only ever constructed and applied to a single input. ```rust let regex = Regex::new("trivial_regex")?; println!("{}", regex.is_match(s)); // `regex` never used again ``` --- changelog: remove `trivial_regex` from default set of enabled lints
2 parents de35c29 + fd35517 commit 4bbd7e4

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

clippy_lints/src/lib.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1628,7 +1628,6 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
16281628
LintId::of(&reference::DEREF_ADDROF),
16291629
LintId::of(&reference::REF_IN_DEREF),
16301630
LintId::of(&regex::INVALID_REGEX),
1631-
LintId::of(&regex::TRIVIAL_REGEX),
16321631
LintId::of(&repeat_once::REPEAT_ONCE),
16331632
LintId::of(&returns::LET_AND_RETURN),
16341633
LintId::of(&returns::NEEDLESS_RETURN),
@@ -1791,7 +1790,6 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
17911790
LintId::of(&ranges::MANUAL_RANGE_CONTAINS),
17921791
LintId::of(&redundant_field_names::REDUNDANT_FIELD_NAMES),
17931792
LintId::of(&redundant_static_lifetimes::REDUNDANT_STATIC_LIFETIMES),
1794-
LintId::of(&regex::TRIVIAL_REGEX),
17951793
LintId::of(&returns::LET_AND_RETURN),
17961794
LintId::of(&returns::NEEDLESS_RETURN),
17971795
LintId::of(&single_component_path_imports::SINGLE_COMPONENT_PATH_IMPORTS),
@@ -2021,6 +2019,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
20212019
LintId::of(&needless_borrow::NEEDLESS_BORROW),
20222020
LintId::of(&path_buf_push_overwrite::PATH_BUF_PUSH_OVERWRITE),
20232021
LintId::of(&redundant_pub_crate::REDUNDANT_PUB_CRATE),
2022+
LintId::of(&regex::TRIVIAL_REGEX),
20242023
LintId::of(&strings::STRING_LIT_AS_BYTES),
20252024
LintId::of(&transmute::USELESS_TRANSMUTE),
20262025
LintId::of(&use_self::USE_SELF),

clippy_lints/src/regex.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,16 @@ declare_clippy_lint! {
3535
/// `str::starts_with`, `str::ends_with` or `std::contains` or other `str`
3636
/// methods.
3737
///
38-
/// **Known problems:** None.
38+
/// **Known problems:** If the same regex is going to be applied to multiple
39+
/// inputs, the precomputations done by `Regex` construction can give
40+
/// significantly better performance than any of the `str`-based methods.
3941
///
4042
/// **Example:**
4143
/// ```ignore
4244
/// Regex::new("^foobar")
4345
/// ```
4446
pub TRIVIAL_REGEX,
45-
style,
47+
nursery,
4648
"trivial regular expressions"
4749
}
4850

0 commit comments

Comments
 (0)