Skip to content

Commit 95c0459

Browse files
committed
Auto merge of rust-lang#6654 - flip1995:no_lazy_static_regex, r=flip1995
No lazy static regex r? `@llogiq` rust-lang#6500 regex is unnecessary for this lint (rust-lang#6500 (comment)) lazy_static is unnecessary. The std lazy feature should be used instead. changelog: none
2 parents 4db76a6 + 3874631 commit 95c0459

File tree

3 files changed

+4
-10
lines changed

3 files changed

+4
-10
lines changed

clippy_lints/Cargo.toml

-2
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,6 @@ rustc-semver="1.1.0"
3434
url = { version = "2.1.0", features = ["serde"] }
3535
quote = "1"
3636
syn = { version = "1", features = ["full"] }
37-
regex = "1.4"
38-
lazy_static = "1.4"
3937

4038
[features]
4139
deny-warnings = []

clippy_lints/src/case_sensitive_file_extension_comparisons.rs

+4-6
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
use crate::utils::paths::STRING;
22
use crate::utils::{match_def_path, span_lint_and_help};
33
use if_chain::if_chain;
4-
use lazy_static::lazy_static;
5-
use regex::Regex;
64
use rustc_ast::ast::LitKind;
75
use rustc_hir::{Expr, ExprKind, PathSegment};
86
use rustc_lint::{LateContext, LateLintPass};
@@ -41,14 +39,14 @@ declare_clippy_lint! {
4139
declare_lint_pass!(CaseSensitiveFileExtensionComparisons => [CASE_SENSITIVE_FILE_EXTENSION_COMPARISONS]);
4240

4341
fn check_case_sensitive_file_extension_comparison(ctx: &LateContext<'_>, expr: &Expr<'_>) -> Option<Span> {
44-
lazy_static! {
45-
static ref RE: Regex = Regex::new(r"^\.([a-z0-9]{1,5}|[A-Z0-9]{1,5})$").unwrap();
46-
}
4742
if_chain! {
4843
if let ExprKind::MethodCall(PathSegment { ident, .. }, _, [obj, extension, ..], span) = expr.kind;
4944
if ident.as_str() == "ends_with";
5045
if let ExprKind::Lit(Spanned { node: LitKind::Str(ext_literal, ..), ..}) = extension.kind;
51-
if RE.is_match(&ext_literal.as_str());
46+
if (2..=6).contains(&ext_literal.as_str().len());
47+
if ext_literal.as_str().starts_with('.');
48+
if ext_literal.as_str().chars().skip(1).all(|c| c.is_uppercase() || c.is_digit(10))
49+
|| ext_literal.as_str().chars().skip(1).all(|c| c.is_lowercase() || c.is_digit(10));
5250
then {
5351
let mut ty = ctx.typeck_results().expr_ty(obj);
5452
ty = match ty.kind() {

clippy_lints/src/utils/diagnostics.rs

-2
Original file line numberDiff line numberDiff line change
@@ -186,8 +186,6 @@ pub fn span_lint_hir_and_then(
186186
/// |
187187
/// = note: `-D fold-any` implied by `-D warnings`
188188
/// ```
189-
190-
#[allow(clippy::unknown_clippy_lints)]
191189
#[cfg_attr(feature = "internal-lints", allow(clippy::collapsible_span_lint_calls))]
192190
pub fn span_lint_and_sugg<'a, T: LintContext>(
193191
cx: &'a T,

0 commit comments

Comments
 (0)