]> git.lizzy.rs Git - rust.git/blobdiff - clippy_lints/src/shadow.rs
Auto merge of #3985 - phansch:move_some_cast_tests, r=flip1995
[rust.git] / clippy_lints / src / shadow.rs
index 40e76c2c089be56a6e2df5dde3ffd5279b38140c..e43b591a9cdc83e8211f0e3ddf7e563dede16733 100644 (file)
@@ -4,91 +4,80 @@
 use rustc::hir::*;
 use rustc::lint::{in_external_macro, LateContext, LateLintPass, LintArray, LintContext, LintPass};
 use rustc::ty;
-use rustc::{declare_tool_lint, lint_array};
+use rustc::{declare_lint_pass, declare_tool_lint};
 use syntax::source_map::Span;
 
-/// **What it does:** Checks for bindings that shadow other bindings already in
-/// scope, while just changing reference level or mutability.
-///
-/// **Why is this bad?** Not much, in fact it's a very common pattern in Rust
-/// code. Still, some may opt to avoid it in their code base, they can set this
-/// lint to `Warn`.
-///
-/// **Known problems:** This lint, as the other shadowing related lints,
-/// currently only catches very simple patterns.
-///
-/// **Example:**
-/// ```rust
-/// let x = &x;
-/// ```
 declare_clippy_lint! {
+    /// **What it does:** Checks for bindings that shadow other bindings already in
+    /// scope, while just changing reference level or mutability.
+    ///
+    /// **Why is this bad?** Not much, in fact it's a very common pattern in Rust
+    /// code. Still, some may opt to avoid it in their code base, they can set this
+    /// lint to `Warn`.
+    ///
+    /// **Known problems:** This lint, as the other shadowing related lints,
+    /// currently only catches very simple patterns.
+    ///
+    /// **Example:**
+    /// ```rust
+    /// let x = &x;
+    /// ```
     pub SHADOW_SAME,
     restriction,
-    "rebinding a name to itself, e.g. `let mut x = &mut x`"
+    "rebinding a name to itself, e.g., `let mut x = &mut x`"
 }
 
-/// **What it does:** Checks for bindings that shadow other bindings already in
-/// scope, while reusing the original value.
-///
-/// **Why is this bad?** Not too much, in fact it's a common pattern in Rust
-/// code. Still, some argue that name shadowing like this hurts readability,
-/// because a value may be bound to different things depending on position in
-/// the code.
-///
-/// **Known problems:** This lint, as the other shadowing related lints,
-/// currently only catches very simple patterns.
-///
-/// **Example:**
-/// ```rust
-/// let x = x + 1;
-/// ```
-/// use different variable name:
-/// ```rust
-/// let y = x + 1;
-/// ```
 declare_clippy_lint! {
+    /// **What it does:** Checks for bindings that shadow other bindings already in
+    /// scope, while reusing the original value.
+    ///
+    /// **Why is this bad?** Not too much, in fact it's a common pattern in Rust
+    /// code. Still, some argue that name shadowing like this hurts readability,
+    /// because a value may be bound to different things depending on position in
+    /// the code.
+    ///
+    /// **Known problems:** This lint, as the other shadowing related lints,
+    /// currently only catches very simple patterns.
+    ///
+    /// **Example:**
+    /// ```rust
+    /// let x = x + 1;
+    /// ```
+    /// use different variable name:
+    /// ```rust
+    /// let y = x + 1;
+    /// ```
     pub SHADOW_REUSE,
     restriction,
-    "rebinding a name to an expression that re-uses the original value, e.g. `let x = x + 1`"
+    "rebinding a name to an expression that re-uses the original value, e.g., `let x = x + 1`"
 }
 
-/// **What it does:** Checks for bindings that shadow other bindings already in
-/// scope, either without a initialization or with one that does not even use
-/// the original value.
-///
-/// **Why is this bad?** Name shadowing can hurt readability, especially in
-/// large code bases, because it is easy to lose track of the active binding at
-/// any place in the code. This can be alleviated by either giving more specific
-/// names to bindings or introducing more scopes to contain the bindings.
-///
-/// **Known problems:** This lint, as the other shadowing related lints,
-/// currently only catches very simple patterns.
-///
-/// **Example:**
-/// ```rust
-/// let x = y;
-/// let x = z; // shadows the earlier binding
-/// ```
 declare_clippy_lint! {
+    /// **What it does:** Checks for bindings that shadow other bindings already in
+    /// scope, either without a initialization or with one that does not even use
+    /// the original value.
+    ///
+    /// **Why is this bad?** Name shadowing can hurt readability, especially in
+    /// large code bases, because it is easy to lose track of the active binding at
+    /// any place in the code. This can be alleviated by either giving more specific
+    /// names to bindings or introducing more scopes to contain the bindings.
+    ///
+    /// **Known problems:** This lint, as the other shadowing related lints,
+    /// currently only catches very simple patterns.
+    ///
+    /// **Example:**
+    /// ```rust
+    /// let x = y;
+    /// let x = z; // shadows the earlier binding
+    /// ```
     pub SHADOW_UNRELATED,
     pedantic,
     "rebinding a name without even using the original value"
 }
 
-#[derive(Copy, Clone)]
-pub struct Pass;
+declare_lint_pass!(Shadow => [SHADOW_SAME, SHADOW_REUSE, SHADOW_UNRELATED]);
 
-impl LintPass for Pass {
-    fn get_lints(&self) -> LintArray {
-        lint_array!(SHADOW_SAME, SHADOW_REUSE, SHADOW_UNRELATED)
-    }
-
-    fn name(&self) -> &'static str {
-        "Shadow"
-    }
-}
-
-impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
+impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Shadow {
     fn check_fn(
         &mut self,
         cx: &LateContext<'a, 'tcx>,