]> git.lizzy.rs Git - rust.git/blobdiff - clippy_lints/src/misc_early.rs
Fix warnings
[rust.git] / clippy_lints / src / misc_early.rs
index 8ac0c4bf0982e28dab44d894866adbad3de44bdc..96a3250d272cc3f0ac91608d7d389c91b1977374 100644 (file)
@@ -4,7 +4,7 @@
 use syntax::ast::*;
 use syntax::codemap::Span;
 use syntax::visit::FnKind;
-use utils::{constants, in_external_macro, snippet, snippet_opt, span_help_and_lint, span_lint, span_lint_and_then};
+use crate::utils::{constants, in_external_macro, snippet, snippet_opt, span_help_and_lint, span_lint, span_lint_and_then};
 
 /// **What it does:** Checks for structure field patterns bound to wildcards.
 ///
@@ -17,9 +17,9 @@
 /// ```rust
 /// let { a: _, b: ref b, c: _ } = ..
 /// ```
-declare_lint! {
+declare_clippy_lint! {
     pub UNNEEDED_FIELD_PATTERN,
-    Warn,
+    style,
     "struct fields bound to a wildcard instead of using `..`"
 }
 
@@ -34,9 +34,9 @@
 /// ```rust
 /// fn foo(a: i32, _a: i32) {}
 /// ```
-declare_lint! {
+declare_clippy_lint! {
     pub DUPLICATE_UNDERSCORE_ARGUMENT,
-    Warn,
+    style,
     "function arguments having names which only differ by an underscore"
 }
 
@@ -52,9 +52,9 @@
 /// ```rust
 /// (|| 42)()
 /// ```
-declare_lint! {
+declare_clippy_lint! {
     pub REDUNDANT_CLOSURE_CALL,
-    Warn,
+    complexity,
     "throwaway closures called in the expression they are defined"
 }
 
@@ -69,9 +69,9 @@
 /// ```rust
 /// --x;
 /// ```
-declare_lint! {
+declare_clippy_lint! {
     pub DOUBLE_NEG,
-    Warn,
+    style,
     "`--x`, which is a double negation of `x` and not a pre-decrement as in C/C++"
 }
 
@@ -86,9 +86,9 @@
 /// ```rust
 /// let y = 0x1a9BAcD;
 /// ```
-declare_lint! {
+declare_clippy_lint! {
     pub MIXED_CASE_HEX_LITERALS,
-    Warn,
+    style,
     "hex literals whose letter digits are not consistently upper- or lowercased"
 }
 
 /// ```rust
 /// let y = 123832i32;
 /// ```
-declare_lint! {
+declare_clippy_lint! {
     pub UNSEPARATED_LITERAL_SUFFIX,
-    Allow,
+    pedantic,
     "literals whose suffix is not separated by an underscore"
 }
 
 /// ```
 ///
 /// prints `83` (as `83 == 0o123` while `123 == 0o173`).
-declare_lint! {
+declare_clippy_lint! {
     pub ZERO_PREFIXED_LITERAL,
-    Warn,
+    complexity,
     "integer literals starting with `0`"
 }
 
 ///     }
 /// }
 /// ```
-declare_lint! {
+declare_clippy_lint! {
     pub BUILTIN_TYPE_SHADOW,
-    Warn,
+    style,
     "shadowing a builtin type"
 }
 
@@ -189,13 +189,13 @@ fn get_lints(&self) -> LintArray {
 impl EarlyLintPass for MiscEarly {
     fn check_generics(&mut self, cx: &EarlyContext, gen: &Generics) {
         for param in &gen.params {
-            if let GenericParam::Type(ref ty) = *param {
-                let name = ty.ident.name.as_str();
+            if let GenericParamKind::Type { .. } = param.kind {
+                let name = param.ident.name.as_str();
                 if constants::BUILTIN_TYPES.contains(&&*name) {
                     span_lint(
                         cx,
                         BUILTIN_TYPE_SHADOW,
-                        ty.span,
+                        param.ident.span,
                         &format!("This generic shadows the built-in type `{}`", name),
                     );
                 }
@@ -209,7 +209,7 @@ fn check_pat(&mut self, cx: &EarlyContext, pat: &Pat) {
             let type_name = npat.segments
                 .last()
                 .expect("A path must have at least one segment")
-                .identifier
+                .ident
                 .name;
 
             for field in pfields {
@@ -267,8 +267,8 @@ fn check_fn(&mut self, cx: &EarlyContext, _: FnKind, decl: &FnDecl, _: Span, _:
         let mut registered_names: HashMap<String, Span> = HashMap::new();
 
         for arg in &decl.inputs {
-            if let PatKind::Ident(_, sp_ident, None) = arg.pat.node {
-                let arg_name = sp_ident.node.to_string();
+            if let PatKind::Ident(_, ident, None) = arg.pat.node {
+                let arg_name = ident.name.to_string();
 
                 if arg_name.starts_with('_') {
                     if let Some(correspondence) = registered_names.get(&arg_name[1..]) {
@@ -296,7 +296,7 @@ fn check_expr(&mut self, cx: &EarlyContext, expr: &Expr) {
         }
         match expr.node {
             ExprKind::Call(ref paren, _) => if let ExprKind::Paren(ref closure) = paren.node {
-                if let ExprKind::Closure(_, _, ref decl, ref block, _) = closure.node {
+                if let ExprKind::Closure(_, _, _, ref decl, ref block, _) = closure.node {
                     span_lint_and_then(
                         cx,
                         REDUNDANT_CLOSURE_CALL,
@@ -327,14 +327,14 @@ fn check_block(&mut self, cx: &EarlyContext, block: &Block) {
             if_chain! {
                 if let StmtKind::Local(ref local) = w[0].node;
                 if let Option::Some(ref t) = local.init;
-                if let ExprKind::Closure(_, _, _, _, _) = t.node;
-                if let PatKind::Ident(_, sp_ident, _) = local.pat.node;
+                if let ExprKind::Closure(..) = t.node;
+                if let PatKind::Ident(_, ident, _) = local.pat.node;
                 if let StmtKind::Semi(ref second) = w[1].node;
                 if let ExprKind::Assign(_, ref call) = second.node;
                 if let ExprKind::Call(ref closure, _) = call.node;
                 if let ExprKind::Path(_, ref path) = closure.node;
                 then {
-                    if sp_ident.node == (&path.segments[0]).identifier {
+                    if ident == path.segments[0].ident {
                         span_lint(
                             cx,
                             REDUNDANT_CLOSURE_CALL,
@@ -349,7 +349,7 @@ fn check_block(&mut self, cx: &EarlyContext, block: &Block) {
 }
 
 impl MiscEarly {
-    fn check_lit(&self, cx: &EarlyContext, lit: &Lit) {
+    fn check_lit(self, cx: &EarlyContext, lit: &Lit) {
         if_chain! {
             if let LitKind::Int(value, ..) = lit.node;
             if let Some(src) = snippet_opt(cx, lit.span);
@@ -371,8 +371,8 @@ fn check_lit(&self, cx: &EarlyContext, lit: &Lit) {
                     let mut seen = (false, false);
                     for ch in src.chars() {
                         match ch {
-                            'a' ... 'f' => seen.0 = true,
-                            'A' ... 'F' => seen.1 = true,
+                            'a' ..= 'f' => seen.0 = true,
+                            'A' ..= 'F' => seen.1 = true,
                             'i' | 'u'   => break,   // start of suffix already
                             _ => ()
                         }