|
10 | 10 |
|
11 | 11 | use syntax::abi::{Abi};
|
12 | 12 | use syntax::ast;
|
| 13 | +use syntax::codemap::Span; |
13 | 14 |
|
14 | 15 | use rustc::ty::{self, TyCtxt};
|
15 | 16 | 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>,
|
58 | 59 | ref terminator,
|
59 | 60 | is_cleanup: _ } = bb_data;
|
60 | 61 |
|
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, |
89 | 65 | };
|
90 | 66 | assert!(args.len() == 1);
|
91 | 67 | 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>,
|
162 | 138 | rustc_peek expects input of \
|
163 | 139 | form `&expr`"));
|
164 | 140 | }
|
| 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; |
165 | 165 | }
|
0 commit comments