]> git.lizzy.rs Git - rust.git/blobdiff - clippy_lints/src/non_expressive_names.rs
Merge branch 'master' into fix-3739
[rust.git] / clippy_lints / src / non_expressive_names.rs
index f39cae46de03e5212f009ff3f84df4fdb69b4f29..7bdeec0a56f0ee0fc53951b92267d12fa9ab9023 100644 (file)
@@ -7,57 +7,57 @@
 use syntax::symbol::LocalInternedString;
 use syntax::visit::{walk_block, walk_expr, walk_pat, Visitor};
 
-/// **What it does:** Checks for names that are very similar and thus confusing.
-///
-/// **Why is this bad?** It's hard to distinguish between names that differ only
-/// by a single character.
-///
-/// **Known problems:** None?
-///
-/// **Example:**
-/// ```rust
-/// let checked_exp = something;
-/// let checked_expr = something_else;
-/// ```
 declare_clippy_lint! {
+    /// **What it does:** Checks for names that are very similar and thus confusing.
+    ///
+    /// **Why is this bad?** It's hard to distinguish between names that differ only
+    /// by a single character.
+    ///
+    /// **Known problems:** None?
+    ///
+    /// **Example:**
+    /// ```ignore
+    /// let checked_exp = something;
+    /// let checked_expr = something_else;
+    /// ```
     pub SIMILAR_NAMES,
     pedantic,
     "similarly named items and bindings"
 }
 
-/// **What it does:** Checks for too many variables whose name consists of a
-/// single character.
-///
-/// **Why is this bad?** It's hard to memorize what a variable means without a
-/// descriptive name.
-///
-/// **Known problems:** None?
-///
-/// **Example:**
-/// ```rust
-/// let (a, b, c, d, e, f, g) = (...);
-/// ```
 declare_clippy_lint! {
+    /// **What it does:** Checks for too many variables whose name consists of a
+    /// single character.
+    ///
+    /// **Why is this bad?** It's hard to memorize what a variable means without a
+    /// descriptive name.
+    ///
+    /// **Known problems:** None?
+    ///
+    /// **Example:**
+    /// ```ignore
+    /// let (a, b, c, d, e, f, g) = (...);
+    /// ```
     pub MANY_SINGLE_CHAR_NAMES,
     style,
     "too many single character bindings"
 }
 
-/// **What it does:** Checks if you have variables whose name consists of just
-/// underscores and digits.
-///
-/// **Why is this bad?** It's hard to memorize what a variable means without a
-/// descriptive name.
-///
-/// **Known problems:** None?
-///
-/// **Example:**
-/// ```rust
-/// let _1 = 1;
-/// let ___1 = 1;
-/// let __1___2 = 11;
-/// ```
 declare_clippy_lint! {
+    /// **What it does:** Checks if you have variables whose name consists of just
+    /// underscores and digits.
+    ///
+    /// **Why is this bad?** It's hard to memorize what a variable means without a
+    /// descriptive name.
+    ///
+    /// **Known problems:** None?
+    ///
+    /// **Example:**
+    /// ```rust
+    /// let _1 = 1;
+    /// let ___1 = 1;
+    /// let __1___2 = 11;
+    /// ```
     pub JUST_UNDERSCORES_AND_DIGITS,
     style,
     "unclear name"
@@ -71,6 +71,10 @@ impl LintPass for NonExpressiveNames {
     fn get_lints(&self) -> LintArray {
         lint_array!(SIMILAR_NAMES, MANY_SINGLE_CHAR_NAMES, JUST_UNDERSCORES_AND_DIGITS)
     }
+
+    fn name(&self) -> &'static str {
+        "NoneExpressiveNames"
+    }
 }
 
 struct ExistingName {
@@ -154,6 +158,7 @@ fn check_short_name(&mut self, c: char, span: Span) {
             );
         }
     }
+    #[allow(clippy::too_many_lines)]
     fn check_name(&mut self, span: Span, name: Name) {
         let interned_name = name.as_str();
         if interned_name.chars().any(char::is_uppercase) {
@@ -236,7 +241,7 @@ fn check_name(&mut self, span: Span, name: Name) {
                         // or too many chars differ (x_foo, y_boo) or (xfoo, yboo)
                         continue;
                     }
-                    split_at = interned_name.chars().next().map(|c| c.len_utf8());
+                    split_at = interned_name.chars().next().map(char::len_utf8);
                 }
             }
             span_lint_and_then(