mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-26 16:54:01 +00:00
rename the lint
This commit is contained in:
parent
52cfc997af
commit
e2ecb132a5
@ -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
|
||||
|
@ -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,
|
||||
|
@ -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(),
|
||||
})
|
||||
});
|
||||
|
@ -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");
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user