12
12
13
13
use graphviz:: IntoCow ;
14
14
use middle:: const_val:: ConstVal ;
15
+ use middle:: region:: CodeExtent ;
15
16
use rustc_const_math:: { ConstUsize , ConstInt , ConstMathErr } ;
16
17
use rustc_data_structures:: indexed_vec:: { IndexVec , Idx } ;
17
18
use rustc_data_structures:: control_flow_graph:: dominators:: { Dominators , dominators} ;
@@ -804,6 +805,10 @@ pub enum StatementKind<'tcx> {
804
805
inputs : Vec < Operand < ' tcx > >
805
806
} ,
806
807
808
+ /// Mark one terminating point of an extent (i.e. static region).
809
+ /// (The starting point(s) arise implicitly from borrows.)
810
+ EndRegion ( CodeExtent ) ,
811
+
807
812
/// No-op. Useful for deleting instructions without affecting statement indices.
808
813
Nop ,
809
814
}
@@ -813,6 +818,8 @@ impl<'tcx> Debug for Statement<'tcx> {
813
818
use self :: StatementKind :: * ;
814
819
match self . kind {
815
820
Assign ( ref lv, ref rv) => write ! ( fmt, "{:?} = {:?}" , lv, rv) ,
821
+ // (reuse lifetime rendering policy from ppaux.)
822
+ EndRegion ( ref ce) => write ! ( fmt, "EndRegion({})" , ty:: ReScope ( * ce) ) ,
816
823
StorageLive ( ref lv) => write ! ( fmt, "StorageLive({:?})" , lv) ,
817
824
StorageDead ( ref lv) => write ! ( fmt, "StorageDead({:?})" , lv) ,
818
825
SetDiscriminant { lvalue : ref lv, variant_index : index} => {
@@ -1176,12 +1183,22 @@ impl<'tcx> Debug for Rvalue<'tcx> {
1176
1183
UnaryOp ( ref op, ref a) => write ! ( fmt, "{:?}({:?})" , op, a) ,
1177
1184
Discriminant ( ref lval) => write ! ( fmt, "discriminant({:?})" , lval) ,
1178
1185
NullaryOp ( ref op, ref t) => write ! ( fmt, "{:?}({:?})" , op, t) ,
1179
- Ref ( _ , borrow_kind, ref lv) => {
1186
+ Ref ( region , borrow_kind, ref lv) => {
1180
1187
let kind_str = match borrow_kind {
1181
1188
BorrowKind :: Shared => "" ,
1182
1189
BorrowKind :: Mut | BorrowKind :: Unique => "mut " ,
1183
1190
} ;
1184
- write ! ( fmt, "&{}{:?}" , kind_str, lv)
1191
+
1192
+ // When identifying regions, add trailing space if
1193
+ // necessary.
1194
+ let region = if ppaux:: identify_regions ( ) {
1195
+ let mut region = format ! ( "{}" , region) ;
1196
+ if region. len ( ) > 0 { region. push ( ' ' ) ; }
1197
+ region
1198
+ } else {
1199
+ "" . to_owned ( )
1200
+ } ;
1201
+ write ! ( fmt, "&{}{}{:?}" , region, kind_str, lv)
1185
1202
}
1186
1203
1187
1204
Aggregate ( ref kind, ref lvs) => {
@@ -1224,7 +1241,11 @@ impl<'tcx> Debug for Rvalue<'tcx> {
1224
1241
1225
1242
AggregateKind :: Closure ( def_id, _) => ty:: tls:: with ( |tcx| {
1226
1243
if let Some ( node_id) = tcx. hir . as_local_node_id ( def_id) {
1227
- let name = format ! ( "[closure@{:?}]" , tcx. hir. span( node_id) ) ;
1244
+ let name = if tcx. sess . opts . debugging_opts . span_free_formats {
1245
+ format ! ( "[closure@{:?}]" , node_id)
1246
+ } else {
1247
+ format ! ( "[closure@{:?}]" , tcx. hir. span( node_id) )
1248
+ } ;
1228
1249
let mut struct_fmt = fmt. debug_struct ( & name) ;
1229
1250
1230
1251
tcx. with_freevars ( node_id, |freevars| {
@@ -1458,6 +1479,13 @@ impl<'tcx> TypeFoldable<'tcx> for Statement<'tcx> {
1458
1479
outputs : outputs. fold_with ( folder) ,
1459
1480
inputs : inputs. fold_with ( folder)
1460
1481
} ,
1482
+
1483
+ // Note for future: If we want to expose the extents
1484
+ // during the fold, we need to either generalize EndRegion
1485
+ // to carry `[ty::Region]`, or extend the `TypeFolder`
1486
+ // trait with a `fn fold_extent`.
1487
+ EndRegion ( ref extent) => EndRegion ( extent. clone ( ) ) ,
1488
+
1461
1489
Nop => Nop ,
1462
1490
} ;
1463
1491
Statement {
@@ -1476,6 +1504,13 @@ impl<'tcx> TypeFoldable<'tcx> for Statement<'tcx> {
1476
1504
StorageDead ( ref lvalue) => lvalue. visit_with ( visitor) ,
1477
1505
InlineAsm { ref outputs, ref inputs, .. } =>
1478
1506
outputs. visit_with ( visitor) || inputs. visit_with ( visitor) ,
1507
+
1508
+ // Note for future: If we want to expose the extents
1509
+ // during the visit, we need to either generalize EndRegion
1510
+ // to carry `[ty::Region]`, or extend the `TypeVisitor`
1511
+ // trait with a `fn visit_extent`.
1512
+ EndRegion ( ref _extent) => false ,
1513
+
1479
1514
Nop => false ,
1480
1515
}
1481
1516
}
0 commit comments