1212
1313use graphviz:: IntoCow ;
1414use middle:: const_val:: ConstVal ;
15+ use middle:: region:: CodeExtent ;
1516use rustc_const_math:: { ConstUsize , ConstInt , ConstMathErr } ;
1617use rustc_data_structures:: indexed_vec:: { IndexVec , Idx } ;
1718use rustc_data_structures:: control_flow_graph:: dominators:: { Dominators , dominators} ;
@@ -804,6 +805,10 @@ pub enum StatementKind<'tcx> {
804805 inputs : Vec < Operand < ' tcx > >
805806 } ,
806807
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+
807812 /// No-op. Useful for deleting instructions without affecting statement indices.
808813 Nop ,
809814}
@@ -813,6 +818,8 @@ impl<'tcx> Debug for Statement<'tcx> {
813818 use self :: StatementKind :: * ;
814819 match self . kind {
815820 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) ) ,
816823 StorageLive ( ref lv) => write ! ( fmt, "StorageLive({:?})" , lv) ,
817824 StorageDead ( ref lv) => write ! ( fmt, "StorageDead({:?})" , lv) ,
818825 SetDiscriminant { lvalue : ref lv, variant_index : index} => {
@@ -1176,12 +1183,22 @@ impl<'tcx> Debug for Rvalue<'tcx> {
11761183 UnaryOp ( ref op, ref a) => write ! ( fmt, "{:?}({:?})" , op, a) ,
11771184 Discriminant ( ref lval) => write ! ( fmt, "discriminant({:?})" , lval) ,
11781185 NullaryOp ( ref op, ref t) => write ! ( fmt, "{:?}({:?})" , op, t) ,
1179- Ref ( _ , borrow_kind, ref lv) => {
1186+ Ref ( region , borrow_kind, ref lv) => {
11801187 let kind_str = match borrow_kind {
11811188 BorrowKind :: Shared => "" ,
11821189 BorrowKind :: Mut | BorrowKind :: Unique => "mut " ,
11831190 } ;
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)
11851202 }
11861203
11871204 Aggregate ( ref kind, ref lvs) => {
@@ -1224,7 +1241,11 @@ impl<'tcx> Debug for Rvalue<'tcx> {
12241241
12251242 AggregateKind :: Closure ( def_id, _) => ty:: tls:: with ( |tcx| {
12261243 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+ } ;
12281249 let mut struct_fmt = fmt. debug_struct ( & name) ;
12291250
12301251 tcx. with_freevars ( node_id, |freevars| {
@@ -1458,6 +1479,13 @@ impl<'tcx> TypeFoldable<'tcx> for Statement<'tcx> {
14581479 outputs : outputs. fold_with ( folder) ,
14591480 inputs : inputs. fold_with ( folder)
14601481 } ,
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+
14611489 Nop => Nop ,
14621490 } ;
14631491 Statement {
@@ -1476,6 +1504,13 @@ impl<'tcx> TypeFoldable<'tcx> for Statement<'tcx> {
14761504 StorageDead ( ref lvalue) => lvalue. visit_with ( visitor) ,
14771505 InlineAsm { ref outputs, ref inputs, .. } =>
14781506 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+
14791514 Nop => false ,
14801515 }
14811516 }
0 commit comments