@@ -17,17 +17,17 @@ use hir::def::CtorKind;
17
17
use hir:: def_id:: DefId ;
18
18
use hir:: { self , HirId , InlineAsm } ;
19
19
use middle:: region;
20
- use mir:: interpret:: { EvalErrorKind , Scalar , ScalarMaybeUndef , ConstValue } ;
20
+ use mir:: interpret:: { ConstValue , EvalErrorKind , Scalar , ScalarMaybeUndef } ;
21
21
use mir:: visit:: MirVisitable ;
22
22
use rustc_apfloat:: ieee:: { Double , Single } ;
23
23
use rustc_apfloat:: Float ;
24
24
use rustc_data_structures:: graph:: dominators:: { dominators, Dominators } ;
25
25
use rustc_data_structures:: graph:: { self , GraphPredecessors , GraphSuccessors } ;
26
26
use rustc_data_structures:: indexed_vec:: { Idx , IndexVec } ;
27
- use smallvec:: SmallVec ;
28
27
use rustc_data_structures:: sync:: Lrc ;
29
28
use rustc_data_structures:: sync:: ReadGuard ;
30
29
use rustc_serialize as serialize;
30
+ use smallvec:: SmallVec ;
31
31
use std:: borrow:: Cow ;
32
32
use std:: fmt:: { self , Debug , Formatter , Write } ;
33
33
use std:: ops:: { Index , IndexMut } ;
@@ -203,6 +203,35 @@ impl<'tcx> Mir<'tcx> {
203
203
ReadGuard :: map ( self . predecessors ( ) , |p| & p[ bb] )
204
204
}
205
205
206
+ #[ inline]
207
+ pub fn predecessor_locations ( & self , loc : Location ) -> impl Iterator < Item = Location > + ' _ {
208
+ let if_zero_locations = if loc. statement_index == 0 {
209
+ let predecessor_blocks = self . predecessors_for ( loc. block ) ;
210
+ let num_predecessor_blocks = predecessor_blocks. len ( ) ;
211
+ Some (
212
+ ( 0 ..num_predecessor_blocks)
213
+ . map ( move |i| predecessor_blocks[ i] )
214
+ . map ( move |bb| self . terminator_loc ( bb) ) ,
215
+ )
216
+ } else {
217
+ None
218
+ } ;
219
+
220
+ let if_not_zero_locations = if loc. statement_index == 0 {
221
+ None
222
+ } else {
223
+ Some ( Location {
224
+ block : loc. block ,
225
+ statement_index : loc. statement_index - 1 ,
226
+ } )
227
+ } ;
228
+
229
+ if_zero_locations
230
+ . into_iter ( )
231
+ . flatten ( )
232
+ . chain ( if_not_zero_locations)
233
+ }
234
+
206
235
#[ inline]
207
236
pub fn dominators ( & self ) -> Dominators < BasicBlock > {
208
237
dominators ( self )
@@ -555,13 +584,15 @@ impl_stable_hash_for!(struct self::VarBindingForm<'tcx> {
555
584
} ) ;
556
585
557
586
mod binding_form_impl {
558
- use rustc_data_structures:: stable_hasher:: { HashStable , StableHasher , StableHasherResult } ;
559
587
use ich:: StableHashingContext ;
588
+ use rustc_data_structures:: stable_hasher:: { HashStable , StableHasher , StableHasherResult } ;
560
589
561
590
impl < ' a , ' tcx > HashStable < StableHashingContext < ' a > > for super :: BindingForm < ' tcx > {
562
- fn hash_stable < W : StableHasherResult > ( & self ,
563
- hcx : & mut StableHashingContext < ' a > ,
564
- hasher : & mut StableHasher < W > ) {
591
+ fn hash_stable < W : StableHasherResult > (
592
+ & self ,
593
+ hcx : & mut StableHashingContext < ' a > ,
594
+ hasher : & mut StableHasher < W > ,
595
+ ) {
565
596
use super :: BindingForm :: * ;
566
597
:: std:: mem:: discriminant ( self ) . hash_stable ( hcx, hasher) ;
567
598
@@ -1478,16 +1509,17 @@ impl<'tcx> TerminatorKind<'tcx> {
1478
1509
. map ( |& u| {
1479
1510
let mut s = String :: new ( ) ;
1480
1511
let c = ty:: Const {
1481
- val : ConstValue :: Scalar ( Scalar :: Bits {
1512
+ val : ConstValue :: Scalar (
1513
+ Scalar :: Bits {
1482
1514
bits : u,
1483
1515
size : size. bytes ( ) as u8 ,
1484
- } . into ( ) ) ,
1516
+ } . into ( ) ,
1517
+ ) ,
1485
1518
ty : switch_ty,
1486
1519
} ;
1487
1520
fmt_const_val ( & mut s, & c) . unwrap ( ) ;
1488
1521
s. into ( )
1489
- } )
1490
- . chain ( iter:: once ( String :: from ( "otherwise" ) . into ( ) ) )
1522
+ } ) . chain ( iter:: once ( String :: from ( "otherwise" ) . into ( ) ) )
1491
1523
. collect ( )
1492
1524
}
1493
1525
Call {
@@ -2017,7 +2049,13 @@ pub enum AggregateKind<'tcx> {
2017
2049
/// active field number and is present only for union expressions
2018
2050
/// -- e.g. for a union expression `SomeUnion { c: .. }`, the
2019
2051
/// active field index would identity the field `c`
2020
- Adt ( & ' tcx AdtDef , usize , & ' tcx Substs < ' tcx > , Option < CanonicalTy < ' tcx > > , Option < usize > ) ,
2052
+ Adt (
2053
+ & ' tcx AdtDef ,
2054
+ usize ,
2055
+ & ' tcx Substs < ' tcx > ,
2056
+ Option < CanonicalTy < ' tcx > > ,
2057
+ Option < usize > ,
2058
+ ) ,
2021
2059
2022
2060
Closure ( DefId , ClosureSubsts < ' tcx > ) ,
2023
2061
Generator ( DefId , GeneratorSubsts < ' tcx > , hir:: GeneratorMovability ) ,
@@ -2267,7 +2305,7 @@ pub fn fmt_const_val(f: &mut impl Write, const_val: &ty::Const) -> fmt::Result {
2267
2305
return write ! ( f, "{:?}{}" , ( ( bits as i128 ) << shift) >> shift, i) ;
2268
2306
}
2269
2307
Char => return write ! ( f, "{:?}" , :: std:: char :: from_u32( bits as u32 ) . unwrap( ) ) ,
2270
- _ => { } ,
2308
+ _ => { }
2271
2309
}
2272
2310
}
2273
2311
// print function definitons
@@ -2283,14 +2321,12 @@ pub fn fmt_const_val(f: &mut impl Write, const_val: &ty::Const) -> fmt::Result {
2283
2321
let alloc = tcx. alloc_map . lock ( ) . get ( ptr. alloc_id ) ;
2284
2322
if let Some ( interpret:: AllocType :: Memory ( alloc) ) = alloc {
2285
2323
assert_eq ! ( len as usize as u128 , len) ;
2286
- let slice = & alloc
2287
- . bytes
2288
- [ ( ptr. offset . bytes ( ) as usize ) ..]
2289
- [ ..( len as usize ) ] ;
2324
+ let slice =
2325
+ & alloc. bytes [ ( ptr. offset . bytes ( ) as usize ) ..] [ ..( len as usize ) ] ;
2290
2326
let s = :: std:: str:: from_utf8 ( slice) . expect ( "non utf8 str from miri" ) ;
2291
2327
write ! ( f, "{:?}" , s)
2292
2328
} else {
2293
- write ! ( f, "pointer to erroneous constant {:?}, {:?}" , ptr, len)
2329
+ write ! ( f, "pointer to erroneous constant {:?}, {:?}" , ptr, len)
2294
2330
}
2295
2331
} ) ;
2296
2332
}
@@ -2821,15 +2857,13 @@ impl<'tcx> TypeFoldable<'tcx> for Rvalue<'tcx> {
2821
2857
let kind = box match * * kind {
2822
2858
AggregateKind :: Array ( ty) => AggregateKind :: Array ( ty. fold_with ( folder) ) ,
2823
2859
AggregateKind :: Tuple => AggregateKind :: Tuple ,
2824
- AggregateKind :: Adt ( def, v, substs, user_ty, n) => {
2825
- AggregateKind :: Adt (
2826
- def,
2827
- v,
2828
- substs. fold_with ( folder) ,
2829
- user_ty. fold_with ( folder) ,
2830
- n,
2831
- )
2832
- }
2860
+ AggregateKind :: Adt ( def, v, substs, user_ty, n) => AggregateKind :: Adt (
2861
+ def,
2862
+ v,
2863
+ substs. fold_with ( folder) ,
2864
+ user_ty. fold_with ( folder) ,
2865
+ n,
2866
+ ) ,
2833
2867
AggregateKind :: Closure ( id, substs) => {
2834
2868
AggregateKind :: Closure ( id, substs. fold_with ( folder) )
2835
2869
}
@@ -2860,8 +2894,9 @@ impl<'tcx> TypeFoldable<'tcx> for Rvalue<'tcx> {
2860
2894
( match * * kind {
2861
2895
AggregateKind :: Array ( ty) => ty. visit_with ( visitor) ,
2862
2896
AggregateKind :: Tuple => false ,
2863
- AggregateKind :: Adt ( _, _, substs, user_ty, _) =>
2864
- substs. visit_with ( visitor) || user_ty. visit_with ( visitor) ,
2897
+ AggregateKind :: Adt ( _, _, substs, user_ty, _) => {
2898
+ substs. visit_with ( visitor) || user_ty. visit_with ( visitor)
2899
+ }
2865
2900
AggregateKind :: Closure ( _, substs) => substs. visit_with ( visitor) ,
2866
2901
AggregateKind :: Generator ( _, substs, _) => substs. visit_with ( visitor) ,
2867
2902
} ) || fields. visit_with ( visitor)
0 commit comments