]> git.lizzy.rs Git - rust.git/blobdiff - clippy_lints/src/escape.rs
Auto merge of #3680 - g-bartoszek:needless-bool-else-if-brackets, r=oli-obk
[rust.git] / clippy_lints / src / escape.rs
index 11bdf2244b10bec9a15a0015321fd12331a8bffa..a7b47fd1e5463f32ddcc00cb3d98a9e53c1064e2 100644 (file)
@@ -1,25 +1,15 @@
-// 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.
-
-
-use crate::rustc::hir::*;
-use crate::rustc::hir::intravisit as visit;
-use crate::rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
-use crate::rustc::{declare_tool_lint, lint_array};
-use crate::rustc::middle::expr_use_visitor::*;
-use crate::rustc::middle::mem_categorization::{cmt_, Categorization};
-use crate::rustc::ty::{self, Ty};
-use crate::rustc::ty::layout::LayoutOf;
-use crate::rustc::util::nodemap::NodeSet;
-use crate::syntax::ast::NodeId;
-use crate::syntax::source_map::Span;
 use crate::utils::span_lint;
+use rustc::hir::intravisit as visit;
+use rustc::hir::*;
+use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
+use rustc::middle::expr_use_visitor::*;
+use rustc::middle::mem_categorization::{cmt_, Categorization};
+use rustc::ty::layout::LayoutOf;
+use rustc::ty::{self, Ty};
+use rustc::util::nodemap::NodeSet;
+use rustc::{declare_tool_lint, lint_array};
+use syntax::ast::NodeId;
+use syntax::source_map::Span;
 
 pub struct Pass {
     pub too_large_for_stack: u64,
@@ -65,7 +55,6 @@ fn get_lints(&self) -> LintArray {
 }
 
 impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
-
     fn check_fn(
         &mut self,
         cx: &LateContext<'a, 'tcx>,
@@ -76,8 +65,8 @@ fn check_fn(
         node_id: NodeId,
     ) {
         // If the method is an impl for a trait, don't warn
-        let parent_id = cx.tcx.hir.get_parent(node_id);
-        let parent_node = cx.tcx.hir.find(parent_id);
+        let parent_id = cx.tcx.hir().get_parent(node_id);
+        let parent_node = cx.tcx.hir().find(parent_id);
 
         if let Some(Node::Item(item)) = parent_node {
             if let ItemKind::Impl(_, _, _, _, Some(..), _, _) = item.node {
@@ -91,7 +80,7 @@ fn check_fn(
             too_large_for_stack: self.too_large_for_stack,
         };
 
-        let fn_def_id = cx.tcx.hir.local_def_id(node_id);
+        let fn_def_id = cx.tcx.hir().local_def_id(node_id);
         let region_scope_tree = &cx.tcx.region_scope_tree(fn_def_id);
         ExprUseVisitor::new(&mut v, cx.tcx, cx.param_env, region_scope_tree, cx.tables, None).consume_body(body);
 
@@ -99,7 +88,7 @@ fn check_fn(
             span_lint(
                 cx,
                 BOXED_LOCAL,
-                cx.tcx.hir.span(node),
+                cx.tcx.hir().span(node),
                 "local variable doesn't need to be boxed here",
             );
         }
@@ -117,7 +106,7 @@ fn consume(&mut self, _: NodeId, _: Span, cmt: &cmt_<'tcx>, mode: ConsumeMode) {
     }
     fn matched_pat(&mut self, _: &Pat, _: &cmt_<'tcx>, _: MatchMode) {}
     fn consume_pat(&mut self, consume_pat: &Pat, cmt: &cmt_<'tcx>, _: ConsumeMode) {
-        let map = &self.cx.tcx.hir;
+        let map = &self.cx.tcx.hir();
         if map.is_argument(consume_pat.id) {
             // Skip closure arguments
             if let Some(Node::Expr(..)) = map.find(map.get_parent_node(consume_pat.id)) {
@@ -131,18 +120,16 @@ fn consume_pat(&mut self, consume_pat: &Pat, cmt: &cmt_<'tcx>, _: ConsumeMode) {
         if let Categorization::Rvalue(..) = cmt.cat {
             let id = map.hir_to_node_id(cmt.hir_id);
             if let Some(Node::Stmt(st)) = map.find(map.get_parent_node(id)) {
-                if let StmtKind::Decl(ref decl, _) = st.node {
-                    if let DeclKind::Local(ref loc) = decl.node {
-                        if let Some(ref ex) = loc.init {
-                            if let ExprKind::Box(..) = ex.node {
-                                if is_non_trait_box(cmt.ty) && !self.is_large_box(cmt.ty) {
-                                    // let x = box (...)
-                                    self.set.insert(consume_pat.id);
-                                }
-                                // TODO Box::new
-                                // TODO vec![]
-                                // TODO "foo".to_owned() and friends
+                if let StmtKind::Local(ref loc) = st.node {
+                    if let Some(ref ex) = loc.init {
+                        if let ExprKind::Box(..) = ex.node {
+                            if is_non_trait_box(cmt.ty) && !self.is_large_box(cmt.ty) {
+                                // let x = box (...)
+                                self.set.insert(consume_pat.id);
                             }
+                            // TODO Box::new
+                            // TODO vec![]
+                            // TODO "foo".to_owned() and friends
                         }
                     }
                 }
@@ -157,7 +144,15 @@ fn consume_pat(&mut self, consume_pat: &Pat, cmt: &cmt_<'tcx>, _: ConsumeMode) {
             }
         }
     }
-    fn borrow(&mut self, _: NodeId, _: Span, cmt: &cmt_<'tcx>, _: ty::Region<'_>, _: ty::BorrowKind, loan_cause: LoanCause) {
+    fn borrow(
+        &mut self,
+        _: NodeId,
+        _: Span,
+        cmt: &cmt_<'tcx>,
+        _: ty::Region<'_>,
+        _: ty::BorrowKind,
+        loan_cause: LoanCause,
+    ) {
         if let Categorization::Local(lid) = cmt.cat {
             match loan_cause {
                 // x.foo()