diff options
| -rw-r--r-- | CHANGELOG.md | 2 | ||||
| -rw-r--r-- | clippy_lints/src/declared_lints.rs | 2 | ||||
| -rw-r--r-- | clippy_lints/src/lib.rs | 4 | ||||
| -rw-r--r-- | clippy_lints/src/single_char_idents.rs (renamed from clippy_lints/src/single_letter_idents.rs) | 12 |
4 files changed, 10 insertions, 10 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 5a03d768fee..27a5fc06b07 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5155,12 +5155,12 @@ Released 2018-09-13 [`significant_drop_tightening`]: https://rust-lang.github.io/rust-clippy/master/index.html#significant_drop_tightening [`similar_names`]: https://rust-lang.github.io/rust-clippy/master/index.html#similar_names [`single_char_add_str`]: https://rust-lang.github.io/rust-clippy/master/index.html#single_char_add_str +[`single_char_idents`]: https://rust-lang.github.io/rust-clippy/master/index.html#single_char_idents [`single_char_lifetime_names`]: https://rust-lang.github.io/rust-clippy/master/index.html#single_char_lifetime_names [`single_char_pattern`]: https://rust-lang.github.io/rust-clippy/master/index.html#single_char_pattern [`single_char_push_str`]: https://rust-lang.github.io/rust-clippy/master/index.html#single_char_push_str [`single_component_path_imports`]: https://rust-lang.github.io/rust-clippy/master/index.html#single_component_path_imports [`single_element_loop`]: https://rust-lang.github.io/rust-clippy/master/index.html#single_element_loop -[`single_letter_idents`]: https://rust-lang.github.io/rust-clippy/master/index.html#single_letter_idents [`single_match`]: https://rust-lang.github.io/rust-clippy/master/index.html#single_match [`single_match_else`]: https://rust-lang.github.io/rust-clippy/master/index.html#single_match_else [`size_of_in_element_count`]: https://rust-lang.github.io/rust-clippy/master/index.html#size_of_in_element_count diff --git a/clippy_lints/src/declared_lints.rs b/clippy_lints/src/declared_lints.rs index 03c3e153a97..1c494468226 100644 --- a/clippy_lints/src/declared_lints.rs +++ b/clippy_lints/src/declared_lints.rs @@ -565,9 +565,9 @@ pub(crate) static LINTS: &[&crate::LintInfo] = &[ crate::shadow::SHADOW_SAME_INFO, crate::shadow::SHADOW_UNRELATED_INFO, crate::significant_drop_tightening::SIGNIFICANT_DROP_TIGHTENING_INFO, + crate::single_char_idents::SINGLE_CHAR_IDENTS_INFO, crate::single_char_lifetime_names::SINGLE_CHAR_LIFETIME_NAMES_INFO, crate::single_component_path_imports::SINGLE_COMPONENT_PATH_IMPORTS_INFO, - crate::single_letter_idents::SINGLE_LETTER_IDENTS_INFO, crate::size_of_in_element_count::SIZE_OF_IN_ELEMENT_COUNT_INFO, crate::size_of_ref::SIZE_OF_REF_INFO, crate::slow_vector_initialization::SLOW_VECTOR_INITIALIZATION_INFO, diff --git a/clippy_lints/src/lib.rs b/clippy_lints/src/lib.rs index 9b8edc5d77e..463e4a429d1 100644 --- a/clippy_lints/src/lib.rs +++ b/clippy_lints/src/lib.rs @@ -284,9 +284,9 @@ mod semicolon_if_nothing_returned; mod serde_api; mod shadow; mod significant_drop_tightening; +mod single_char_idents; mod single_char_lifetime_names; mod single_component_path_imports; -mod single_letter_idents; mod size_of_in_element_count; mod size_of_ref; mod slow_vector_initialization; @@ -1036,7 +1036,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf: store.register_late_pass(|_| Box::new(needless_if::NeedlessIf)); let allowed_idents = conf.allowed_idents.clone(); store.register_early_pass(move || { - Box::new(single_letter_idents::SingleLetterIdents { + Box::new(single_char_idents::SingleCharIdents { allowed_idents: allowed_idents.clone(), }) }); diff --git a/clippy_lints/src/single_letter_idents.rs b/clippy_lints/src/single_char_idents.rs index e957b6fec68..0125b576f43 100644 --- a/clippy_lints/src/single_letter_idents.rs +++ b/clippy_lints/src/single_char_idents.rs @@ -24,29 +24,29 @@ declare_clippy_lint! { /// } /// ``` #[clippy::version = "1.72.0"] - pub SINGLE_LETTER_IDENTS, + pub SINGLE_CHAR_IDENTS, restriction, "disallows idents that can be represented as a char" } -impl_lint_pass!(SingleLetterIdents => [SINGLE_LETTER_IDENTS]); +impl_lint_pass!(SingleCharIdents => [SINGLE_CHAR_IDENTS]); #[derive(Clone)] -pub struct SingleLetterIdents { +pub struct SingleCharIdents { pub allowed_idents: FxHashSet<char>, } -impl EarlyLintPass for SingleLetterIdents { +impl EarlyLintPass for SingleCharIdents { fn check_ident(&mut self, cx: &EarlyContext<'_>, ident: Ident) { let str = ident.name.as_str(); let chars = str.chars(); - if let [char, rest @ ..] = chars.collect_vec().as_slice() + if let [char, rest @ ..] = &*chars.collect_vec() && rest.is_empty() && self.allowed_idents.get(char).is_none() && !in_external_macro(cx.sess(), ident.span) // Ignore proc macros. Let's implement `WithSearchPat` for early lints someday :) && snippet(cx, ident.span, str) == str { - span_lint(cx, SINGLE_LETTER_IDENTS, ident.span, "this ident comprises of a single letter"); + span_lint(cx, SINGLE_CHAR_IDENTS, ident.span, "this ident comprises of a single char"); } } } |
