diff options
| author | bors <bors@rust-lang.org> | 2021-01-30 16:49:45 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2021-01-30 16:49:45 +0000 |
| commit | 95c0459217d1661edfa794c8bb122452b92fb485 (patch) | |
| tree | edb0ff2032d97a22c45ad59ee3c9e91060ee073b | |
| parent | 4db76a6bcc51fca61de6f5a41b84ad21058835dc (diff) | |
| parent | 3874631600811d964f18784859b34302d5533358 (diff) | |
| download | rust-95c0459217d1661edfa794c8bb122452b92fb485.tar.gz rust-95c0459217d1661edfa794c8bb122452b92fb485.zip | |
Auto merge of #6654 - flip1995:no_lazy_static_regex, r=flip1995
No lazy static regex r? `@llogiq` #6500 regex is unnecessary for this lint (https://github.com/rust-lang/rust-clippy/pull/6500#discussion_r558555071) lazy_static is unnecessary. The std lazy feature should be used instead. changelog: none
| -rw-r--r-- | clippy_lints/Cargo.toml | 2 | ||||
| -rw-r--r-- | clippy_lints/src/case_sensitive_file_extension_comparisons.rs | 10 | ||||
| -rw-r--r-- | clippy_lints/src/utils/diagnostics.rs | 2 |
3 files changed, 4 insertions, 10 deletions
diff --git a/clippy_lints/Cargo.toml b/clippy_lints/Cargo.toml index 38098f8a14c..a9516560a61 100644 --- a/clippy_lints/Cargo.toml +++ b/clippy_lints/Cargo.toml @@ -34,8 +34,6 @@ rustc-semver="1.1.0" url = { version = "2.1.0", features = ["serde"] } quote = "1" syn = { version = "1", features = ["full"] } -regex = "1.4" -lazy_static = "1.4" [features] deny-warnings = [] diff --git a/clippy_lints/src/case_sensitive_file_extension_comparisons.rs b/clippy_lints/src/case_sensitive_file_extension_comparisons.rs index d5347ce6ed7..6969ac949d8 100644 --- a/clippy_lints/src/case_sensitive_file_extension_comparisons.rs +++ b/clippy_lints/src/case_sensitive_file_extension_comparisons.rs @@ -1,8 +1,6 @@ use crate::utils::paths::STRING; use crate::utils::{match_def_path, span_lint_and_help}; use if_chain::if_chain; -use lazy_static::lazy_static; -use regex::Regex; use rustc_ast::ast::LitKind; use rustc_hir::{Expr, ExprKind, PathSegment}; use rustc_lint::{LateContext, LateLintPass}; @@ -41,14 +39,14 @@ declare_clippy_lint! { declare_lint_pass!(CaseSensitiveFileExtensionComparisons => [CASE_SENSITIVE_FILE_EXTENSION_COMPARISONS]); fn check_case_sensitive_file_extension_comparison(ctx: &LateContext<'_>, expr: &Expr<'_>) -> Option<Span> { - lazy_static! { - static ref RE: Regex = Regex::new(r"^\.([a-z0-9]{1,5}|[A-Z0-9]{1,5})$").unwrap(); - } if_chain! { if let ExprKind::MethodCall(PathSegment { ident, .. }, _, [obj, extension, ..], span) = expr.kind; if ident.as_str() == "ends_with"; if let ExprKind::Lit(Spanned { node: LitKind::Str(ext_literal, ..), ..}) = extension.kind; - if RE.is_match(&ext_literal.as_str()); + if (2..=6).contains(&ext_literal.as_str().len()); + if ext_literal.as_str().starts_with('.'); + if ext_literal.as_str().chars().skip(1).all(|c| c.is_uppercase() || c.is_digit(10)) + || ext_literal.as_str().chars().skip(1).all(|c| c.is_lowercase() || c.is_digit(10)); then { let mut ty = ctx.typeck_results().expr_ty(obj); ty = match ty.kind() { diff --git a/clippy_lints/src/utils/diagnostics.rs b/clippy_lints/src/utils/diagnostics.rs index a7a6b5855b7..6caa04f651f 100644 --- a/clippy_lints/src/utils/diagnostics.rs +++ b/clippy_lints/src/utils/diagnostics.rs @@ -186,8 +186,6 @@ pub fn span_lint_hir_and_then( /// | /// = note: `-D fold-any` implied by `-D warnings` /// ``` - -#[allow(clippy::unknown_clippy_lints)] #[cfg_attr(feature = "internal-lints", allow(clippy::collapsible_span_lint_calls))] pub fn span_lint_and_sugg<'a, T: LintContext>( cx: &'a T, |
