Skip to content

Commit aaad8a2

Browse files
committed
mir::dataflow::sanity_check: Factor out fn is_rustc_peek helper routine.
1 parent 582f060 commit aaad8a2

File tree

1 file changed

+28
-28
lines changed

1 file changed

+28
-28
lines changed

src/librustc_borrowck/borrowck/mir/dataflow/sanity_check.rs

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
use syntax::abi::{Abi};
1212
use syntax::ast;
13+
use syntax::codemap::Span;
1314

1415
use rustc::ty::{self, TyCtxt};
1516
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>,
5859
ref terminator,
5960
is_cleanup: _ } = bb_data;
6061

61-
let (args, span) = if let Some(repr::Terminator { ref kind, span, .. }) = *terminator {
62-
if let repr::TerminatorKind::Call { func: ref oper, ref args, .. } = *kind
63-
{
64-
if let repr::Operand::Constant(ref func) = *oper
65-
{
66-
if let ty::TyFnDef(def_id, _, &ty::BareFnTy { abi, .. }) = func.ty.sty
67-
{
68-
let name = tcx.item_name(def_id);
69-
if abi == Abi::RustIntrinsic || abi == Abi::PlatformIntrinsic {
70-
if name.as_str() == "rustc_peek" {
71-
(args, span)
72-
} else {
73-
continue;
74-
}
75-
} else {
76-
continue;
77-
}
78-
} else {
79-
continue;
80-
}
81-
} else {
82-
continue;
83-
}
84-
} else {
85-
continue;
86-
}
87-
} else {
88-
continue;
62+
let (args, span) = match is_rustc_peek(tcx, terminator) {
63+
Some(args_and_span) => args_and_span,
64+
None => continue,
8965
};
9066
assert!(args.len() == 1);
9167
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>,
162138
rustc_peek expects input of \
163139
form `&expr`"));
164140
}
141+
142+
}
143+
144+
fn is_rustc_peek<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
145+
terminator: &'a Option<repr::Terminator<'tcx>>)
146+
-> Option<(&'a [repr::Operand<'tcx>], Span)> {
147+
if let Some(repr::Terminator { ref kind, span, .. }) = *terminator {
148+
if let repr::TerminatorKind::Call { func: ref oper, ref args, .. } = *kind
149+
{
150+
if let repr::Operand::Constant(ref func) = *oper
151+
{
152+
if let ty::TyFnDef(def_id, _, &ty::BareFnTy { abi, .. }) = func.ty.sty
153+
{
154+
let name = tcx.item_name(def_id);
155+
if abi == Abi::RustIntrinsic || abi == Abi::PlatformIntrinsic {
156+
if name.as_str() == "rustc_peek" {
157+
return Some((args, span));
158+
}
159+
}
160+
}
161+
}
162+
}
163+
}
164+
return None;
165165
}

0 commit comments

Comments
 (0)