]> git.lizzy.rs Git - rust.git/blobdiff - clippy_lints/src/escape.rs
Auto merge of #3946 - rchaser53:issue-3920, r=flip1995
[rust.git] / clippy_lints / src / escape.rs
index c84552d60c1c2ed145acc03bb727c9ede73abe08..59ca2563cda6eb4a247aeb4789e9195f25b7aad5 100644 (file)
@@ -1,4 +1,3 @@
-use crate::utils::span_lint;
 use rustc::hir::intravisit as visit;
 use rustc::hir::*;
 use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
@@ -10,6 +9,8 @@
 use rustc::{declare_tool_lint, lint_array};
 use syntax::source_map::Span;
 
+use crate::utils::span_lint;
+
 pub struct Pass {
     pub too_large_for_stack: u64,
 }
@@ -67,7 +68,7 @@ fn check_fn(
         _: Span,
         hir_id: HirId,
     ) {
-        // If the method is an impl for a trait, don't warn
+        // If the method is an impl for a trait, don't warn.
         let parent_id = cx.tcx.hir().get_parent_item(hir_id);
         let parent_node = cx.tcx.hir().find_by_hir_id(parent_id);
 
@@ -101,7 +102,7 @@ fn check_fn(
 impl<'a, 'tcx> Delegate<'tcx> for EscapeDelegate<'a, 'tcx> {
     fn consume(&mut self, _: HirId, _: Span, cmt: &cmt_<'tcx>, mode: ConsumeMode) {
         if let Categorization::Local(lid) = cmt.cat {
-            if let Move(DirectRefMove) = mode {
+            if let Move(DirectRefMove) | Move(CaptureMove) = mode {
                 // moved out or in. clearly can't be localized
                 self.set.remove(&lid);
             }
@@ -121,8 +122,7 @@ fn consume_pat(&mut self, consume_pat: &Pat, cmt: &cmt_<'tcx>, _: ConsumeMode) {
             return;
         }
         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 Some(Node::Stmt(st)) = map.find_by_hir_id(map.get_parent_node_by_hir_id(cmt.hir_id)) {
                 if let StmtKind::Local(ref loc) = st.node {
                     if let Some(ref ex) = loc.init {
                         if let ExprKind::Box(..) = ex.node {
@@ -158,20 +158,20 @@ fn borrow(
     ) {
         if let Categorization::Local(lid) = cmt.cat {
             match loan_cause {
-                // x.foo()
-                // Used without autodereffing (i.e. x.clone())
+                // `x.foo()`
+                // Used without autoderef-ing (i.e., `x.clone()`).
                 LoanCause::AutoRef |
 
-                // &x
-                // foo(&x) where no extra autoreffing is happening
+                // `&x`
+                // `foo(&x)` where no extra autoref-ing is happening.
                 LoanCause::AddrOf |
 
-                // `match x` can move
+                // `match x` can move.
                 LoanCause::MatchDiscriminant => {
                     self.set.remove(&lid);
                 }
 
-                // do nothing for matches, etc. These can't escape
+                // Do nothing for matches, etc. These can't escape.
                 _ => {}
             }
         }
@@ -182,8 +182,7 @@ fn mutate(&mut self, _: HirId, _: Span, _: &cmt_<'tcx>, _: MutateMode) {}
 
 impl<'a, 'tcx> EscapeDelegate<'a, 'tcx> {
     fn is_large_box(&self, ty: Ty<'tcx>) -> bool {
-        // Large types need to be boxed to avoid stack
-        // overflows.
+        // Large types need to be boxed to avoid stack overflows.
         if ty.is_box() {
             self.cx.layout_of(ty.boxed_ty()).ok().map_or(0, |l| l.size.bytes()) > self.too_large_for_stack
         } else {