about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorFelix S. Klock II <pnkfelix@pnkfx.org>2016-05-20 13:18:03 +0200
committerFelix S. Klock II <pnkfelix@pnkfx.org>2016-05-20 13:18:03 +0200
commitaaad8a209a239fdd9bb9d018768ecce66d83d1f5 (patch)
treeffb460cf289df8a61b19ba0bfd912e2a354bb85f /src
parent582f060a17d4b4a4e007db25548d01670bbdc496 (diff)
downloadrust-aaad8a209a239fdd9bb9d018768ecce66d83d1f5.tar.gz
rust-aaad8a209a239fdd9bb9d018768ecce66d83d1f5.zip
`mir::dataflow::sanity_check`: Factor out `fn is_rustc_peek` helper routine.
Diffstat (limited to 'src')
-rw-r--r--src/librustc_borrowck/borrowck/mir/dataflow/sanity_check.rs56
1 files changed, 28 insertions, 28 deletions
diff --git a/src/librustc_borrowck/borrowck/mir/dataflow/sanity_check.rs b/src/librustc_borrowck/borrowck/mir/dataflow/sanity_check.rs
index b45b7922912..7c8a9a4aeb0 100644
--- a/src/librustc_borrowck/borrowck/mir/dataflow/sanity_check.rs
+++ b/src/librustc_borrowck/borrowck/mir/dataflow/sanity_check.rs
@@ -10,6 +10,7 @@
 
 use syntax::abi::{Abi};
 use syntax::ast;
+use syntax::codemap::Span;
 
 use rustc::ty::{self, TyCtxt};
 use rustc::mir::repr::{self, Mir};
@@ -58,34 +59,9 @@ pub fn sanity_check_via_rustc_peek<'a, 'tcx, O>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
                                     ref terminator,
                                     is_cleanup: _ } = bb_data;
 
-        let (args, span) = if let Some(repr::Terminator { ref kind, span, .. }) = *terminator {
-            if let repr::TerminatorKind::Call { func: ref oper, ref args, .. } = *kind
-            {
-                if let repr::Operand::Constant(ref func) = *oper
-                {
-                    if let ty::TyFnDef(def_id, _, &ty::BareFnTy { abi, .. }) = func.ty.sty
-                    {
-                        let name = tcx.item_name(def_id);
-                        if abi == Abi::RustIntrinsic || abi == Abi::PlatformIntrinsic {
-                            if name.as_str() == "rustc_peek" {
-                                (args, span)
-                            } else {
-                                continue;
-                            }
-                        } else {
-                            continue;
-                        }
-                    } else {
-                        continue;
-                    }
-                } else {
-                    continue;
-                }
-            } else {
-                continue;
-            }
-        } else {
-            continue;
+        let (args, span) = match is_rustc_peek(tcx, terminator) {
+            Some(args_and_span) => args_and_span,
+            None => continue,
         };
         assert!(args.len() == 1);
         let peek_arg_lval = match args[0] {
@@ -162,4 +138,28 @@ pub fn sanity_check_via_rustc_peek<'a, 'tcx, O>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
                                           rustc_peek expects input of \
                                           form `&expr`"));
     }
+
+}
+
+fn is_rustc_peek<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
+                           terminator: &'a Option<repr::Terminator<'tcx>>)
+                           -> Option<(&'a [repr::Operand<'tcx>], Span)> {
+    if let Some(repr::Terminator { ref kind, span, .. }) = *terminator {
+        if let repr::TerminatorKind::Call { func: ref oper, ref args, .. } = *kind
+        {
+            if let repr::Operand::Constant(ref func) = *oper
+            {
+                if let ty::TyFnDef(def_id, _, &ty::BareFnTy { abi, .. }) = func.ty.sty
+                {
+                    let name = tcx.item_name(def_id);
+                    if abi == Abi::RustIntrinsic || abi == Abi::PlatformIntrinsic {
+                        if name.as_str() == "rustc_peek" {
+                            return Some((args, span));
+                        }
+                    }
+                }
+            }
+        }
+    }
+    return None;
 }