]> git.lizzy.rs Git - rust.git/blobdiff - clippy_lints/src/utils/author.rs
Merge pull request #3735 from jsgf/setup-toolchain
[rust.git] / clippy_lints / src / utils / author.rs
index 9eb543db6d4cfd04202caa60105a7b7bec2f63f7..264a5463225df79434c34cb6089e3247b1603a19 100644 (file)
@@ -1,23 +1,14 @@
-// Copyright 2014-2018 The Rust Project Developers. See the COPYRIGHT
-// file at the top-level directory of this distribution.
-//
-// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
-// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
-// option. This file may not be copied, modified, or distributed
-// except according to those terms.
-
 //! A group of attributes that can be attached to Rust code in order
 //! to generate a clippy lint detecting said code automatically.
 
-use crate::rustc::hir;
-use crate::rustc::hir::intravisit::{NestedVisitorMap, Visitor};
-use crate::rustc::hir::{BindingAnnotation, DeclKind, Expr, ExprKind, Pat, PatKind, QPath, Stmt, StmtKind, TyKind};
-use crate::rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
-use crate::rustc::{declare_tool_lint, lint_array};
-use crate::rustc_data_structures::fx::FxHashMap;
-use crate::syntax::ast::{Attribute, LitKind, DUMMY_NODE_ID};
 use crate::utils::get_attr;
+use rustc::hir;
+use rustc::hir::intravisit::{NestedVisitorMap, Visitor};
+use rustc::hir::{BindingAnnotation, Expr, ExprKind, Pat, PatKind, QPath, Stmt, StmtKind, TyKind};
+use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
+use rustc::{declare_tool_lint, lint_array};
+use rustc_data_structures::fx::FxHashMap;
+use syntax::ast::{Attribute, LitKind, DUMMY_NODE_ID};
 
 /// **What it does:** Generates clippy code that detects the offending pattern
 ///
@@ -62,6 +53,10 @@ impl LintPass for Pass {
     fn get_lints(&self) -> LintArray {
         lint_array!(LINT_AUTHOR)
     }
+
+    fn name(&self) -> &'static str {
+        "Author"
+    }
 }
 
 fn prelude() {
@@ -199,6 +194,7 @@ struct PrintVisitor {
 }
 
 impl<'tcx> Visitor<'tcx> for PrintVisitor {
+    #[allow(clippy::too_many_lines)]
     fn visit_expr(&mut self, expr: &Expr) {
         print!("    if let ExprKind::");
         let current = format!("{}.node", self.current);
@@ -269,6 +265,7 @@ fn visit_expr(&mut self, expr: &Expr) {
                 match lit.node {
                     LitKind::Bool(val) => println!("    if let LitKind::Bool({:?}) = {}.node;", val, lit_pat),
                     LitKind::Char(c) => println!("    if let LitKind::Char({:?}) = {}.node;", c, lit_pat),
+                    LitKind::Err(val) => println!("    if let LitKind::Err({}) = {}.node;", val, lit_pat),
                     LitKind::Byte(b) => println!("    if let LitKind::Byte({}) = {}.node;", b, lit_pat),
                     // FIXME: also check int type
                     LitKind::Int(i, _) => println!("    if let LitKind::Int({}, _) = {}.node;", i, lit_pat),
@@ -510,12 +507,13 @@ fn visit_expr(&mut self, expr: &Expr) {
         }
     }
 
+    #[allow(clippy::too_many_lines)]
     fn visit_pat(&mut self, pat: &Pat) {
         print!("    if let PatKind::");
         let current = format!("{}.node", self.current);
         match pat.node {
             PatKind::Wild => println!("Wild = {};", current),
-            PatKind::Binding(anno, _, ident, ref sub) => {
+            PatKind::Binding(anno, .., ident, ref sub) => {
                 let anno_pat = match anno {
                     BindingAnnotation::Unannotated => "BindingAnnotation::Unannotated",
                     BindingAnnotation::Mutable => "BindingAnnotation::Mutable",
@@ -634,35 +632,26 @@ fn visit_stmt(&mut self, s: &Stmt) {
         print!("    if let StmtKind::");
         let current = format!("{}.node", self.current);
         match s.node {
-            // Could be an item or a local (let) binding:
-            StmtKind::Decl(ref decl, _) => {
-                let decl_pat = self.next("decl");
-                println!("Decl(ref {}, _) = {}", decl_pat, current);
-                print!("    if let DeclKind::");
-                let current = format!("{}.node", decl_pat);
-                match decl.node {
-                    // A local (let) binding:
-                    DeclKind::Local(ref local) => {
-                        let local_pat = self.next("local");
-                        println!("Local(ref {}) = {};", local_pat, current);
-                        if let Some(ref init) = local.init {
-                            let init_pat = self.next("init");
-                            println!("    if let Some(ref {}) = {}.init", init_pat, local_pat);
-                            self.current = init_pat;
-                            self.visit_expr(init);
-                        }
-                        self.current = format!("{}.pat", local_pat);
-                        self.visit_pat(&local.pat);
-                    },
-                    // An item binding:
-                    DeclKind::Item(_) => {
-                        println!("Item(item_id) = {};", current);
-                    },
+            // A local (let) binding:
+            StmtKind::Local(ref local) => {
+                let local_pat = self.next("local");
+                println!("Local(ref {}) = {};", local_pat, current);
+                if let Some(ref init) = local.init {
+                    let init_pat = self.next("init");
+                    println!("    if let Some(ref {}) = {}.init", init_pat, local_pat);
+                    self.current = init_pat;
+                    self.visit_expr(init);
                 }
+                self.current = format!("{}.pat", local_pat);
+                self.visit_pat(&local.pat);
+            },
+            // An item binding:
+            StmtKind::Item(_) => {
+                println!("Item(item_id) = {};", current);
             },
 
             // Expr without trailing semi-colon (must have unit type):
-            StmtKind::Expr(ref e, _) => {
+            StmtKind::Expr(ref e) => {
                 let e_pat = self.next("e");
                 println!("Expr(ref {}, _) = {}", e_pat, current);
                 self.current = e_pat;
@@ -670,7 +659,7 @@ fn visit_stmt(&mut self, s: &Stmt) {
             },
 
             // Expr with trailing semi-colon (may have any type):
-            StmtKind::Semi(ref e, _) => {
+            StmtKind::Semi(ref e) => {
                 let e_pat = self.next("e");
                 println!("Semi(ref {}, _) = {}", e_pat, current);
                 self.current = e_pat;