@@ -18,7 +18,7 @@ use rustc_front::hir::InlineAsm;
18
18
use syntax:: ast:: Name ;
19
19
use syntax:: codemap:: Span ;
20
20
use std:: borrow:: { Cow , IntoCow } ;
21
- use std:: fmt:: { Debug , Formatter , Error , Write } ;
21
+ use std:: fmt:: { self , Debug , Formatter , Write } ;
22
22
use std:: { iter, u32} ;
23
23
24
24
/// Lowered representation of a single function.
@@ -183,8 +183,8 @@ impl BasicBlock {
183
183
}
184
184
185
185
impl Debug for BasicBlock {
186
- fn fmt ( & self , fmt : & mut Formatter ) -> Result < ( ) , Error > {
187
- write ! ( fmt, "BB({}) " , self . 0 )
186
+ fn fmt ( & self , fmt : & mut Formatter ) -> fmt :: Result {
187
+ write ! ( fmt, "bb{} " , self . 0 )
188
188
}
189
189
}
190
190
@@ -317,7 +317,7 @@ impl<'tcx> BasicBlockData<'tcx> {
317
317
}
318
318
319
319
impl < ' tcx > Debug for Terminator < ' tcx > {
320
- fn fmt ( & self , fmt : & mut Formatter ) -> Result < ( ) , Error > {
320
+ fn fmt ( & self , fmt : & mut Formatter ) -> fmt :: Result {
321
321
try!( self . fmt_head ( fmt) ) ;
322
322
let successors = self . successors ( ) ;
323
323
let labels = self . fmt_successor_labels ( ) ;
@@ -347,7 +347,7 @@ impl<'tcx> Terminator<'tcx> {
347
347
/// Write the "head" part of the terminator; that is, its name and the data it uses to pick the
348
348
/// successor basic block, if any. The only information not inlcuded is the list of possible
349
349
/// successors, which may be rendered differently between the text and the graphviz format.
350
- pub fn fmt_head < W : Write > ( & self , fmt : & mut W ) -> Result < ( ) , Error > {
350
+ pub fn fmt_head < W : Write > ( & self , fmt : & mut W ) -> fmt :: Result {
351
351
use self :: Terminator :: * ;
352
352
match * self {
353
353
Goto { .. } => write ! ( fmt, "goto" ) ,
@@ -421,7 +421,7 @@ pub enum DropKind {
421
421
}
422
422
423
423
impl < ' tcx > Debug for Statement < ' tcx > {
424
- fn fmt ( & self , fmt : & mut Formatter ) -> Result < ( ) , Error > {
424
+ fn fmt ( & self , fmt : & mut Formatter ) -> fmt :: Result {
425
425
use self :: StatementKind :: * ;
426
426
match self . kind {
427
427
Assign ( ref lv, ref rv) => write ! ( fmt, "{:?} = {:?}" , lv, rv) ,
@@ -541,7 +541,7 @@ impl<'tcx> Lvalue<'tcx> {
541
541
}
542
542
543
543
impl < ' tcx > Debug for Lvalue < ' tcx > {
544
- fn fmt ( & self , fmt : & mut Formatter ) -> Result < ( ) , Error > {
544
+ fn fmt ( & self , fmt : & mut Formatter ) -> fmt :: Result {
545
545
use self :: Lvalue :: * ;
546
546
547
547
match * self {
@@ -551,24 +551,24 @@ impl<'tcx> Debug for Lvalue<'tcx> {
551
551
write ! ( fmt, "arg{:?}" , id) ,
552
552
Temp ( id) =>
553
553
write ! ( fmt, "tmp{:?}" , id) ,
554
- Static ( id ) =>
555
- write ! ( fmt, "Static({:?}) ", id ) ,
554
+ Static ( def_id ) =>
555
+ write ! ( fmt, "{} ", ty :: tls :: with ( |tcx| tcx . item_path_str ( def_id ) ) ) ,
556
556
ReturnPointer =>
557
- write ! ( fmt, "ReturnPointer ") ,
557
+ write ! ( fmt, "return ") ,
558
558
Projection ( ref data) =>
559
559
match data. elem {
560
560
ProjectionElem :: Downcast ( ref adt_def, index) =>
561
- write ! ( fmt, "({:?} as {})" , data. base, adt_def. variants[ index] . name) ,
561
+ write ! ( fmt, "({:?} as {})" , data. base, adt_def. variants[ index] . name) ,
562
562
ProjectionElem :: Deref =>
563
- write ! ( fmt, "(*{:?})" , data. base) ,
563
+ write ! ( fmt, "(*{:?})" , data. base) ,
564
564
ProjectionElem :: Field ( field) =>
565
- write ! ( fmt, "{:?}.{:?}" , data. base, field. index( ) ) ,
565
+ write ! ( fmt, "{:?}.{:?}" , data. base, field. index( ) ) ,
566
566
ProjectionElem :: Index ( ref index) =>
567
- write ! ( fmt, "{:?}[{:?}]" , data. base, index) ,
567
+ write ! ( fmt, "{:?}[{:?}]" , data. base, index) ,
568
568
ProjectionElem :: ConstantIndex { offset, min_length, from_end : false } =>
569
- write ! ( fmt, "{:?}[{:?} of {:?}]" , data. base, offset, min_length) ,
569
+ write ! ( fmt, "{:?}[{:?} of {:?}]" , data. base, offset, min_length) ,
570
570
ProjectionElem :: ConstantIndex { offset, min_length, from_end : true } =>
571
- write ! ( fmt, "{:?}[-{:?} of {:?}]" , data. base, offset, min_length) ,
571
+ write ! ( fmt, "{:?}[-{:?} of {:?}]" , data. base, offset, min_length) ,
572
572
} ,
573
573
}
574
574
}
@@ -588,7 +588,7 @@ pub enum Operand<'tcx> {
588
588
}
589
589
590
590
impl < ' tcx > Debug for Operand < ' tcx > {
591
- fn fmt ( & self , fmt : & mut Formatter ) -> Result < ( ) , Error > {
591
+ fn fmt ( & self , fmt : & mut Formatter ) -> fmt :: Result {
592
592
use self :: Operand :: * ;
593
593
match * self {
594
594
Constant ( ref a) => write ! ( fmt, "{:?}" , a) ,
@@ -715,22 +715,87 @@ pub enum UnOp {
715
715
}
716
716
717
717
impl < ' tcx > Debug for Rvalue < ' tcx > {
718
- fn fmt ( & self , fmt : & mut Formatter ) -> Result < ( ) , Error > {
718
+ fn fmt ( & self , fmt : & mut Formatter ) -> fmt :: Result {
719
719
use self :: Rvalue :: * ;
720
720
721
721
match * self {
722
722
Use ( ref lvalue) => write ! ( fmt, "{:?}" , lvalue) ,
723
723
Repeat ( ref a, ref b) => write ! ( fmt, "[{:?}; {:?}]" , a, b) ,
724
- Ref ( ref a, bk, ref b) => write ! ( fmt, "&{:?} {:?} {:?}" , a, bk, b) ,
725
724
Len ( ref a) => write ! ( fmt, "Len({:?})" , a) ,
726
725
Cast ( ref kind, ref lv, ref ty) => write ! ( fmt, "{:?} as {:?} ({:?})" , lv, ty, kind) ,
727
726
BinaryOp ( ref op, ref a, ref b) => write ! ( fmt, "{:?}({:?}, {:?})" , op, a, b) ,
728
727
UnaryOp ( ref op, ref a) => write ! ( fmt, "{:?}({:?})" , op, a) ,
729
728
Box ( ref t) => write ! ( fmt, "Box({:?})" , t) ,
730
- Aggregate ( ref kind, ref lvs) => write ! ( fmt, "Aggregate<{:?}>{:?}" , kind, lvs) ,
731
729
InlineAsm ( ref asm) => write ! ( fmt, "InlineAsm({:?})" , asm) ,
732
730
Slice { ref input, from_start, from_end } =>
733
731
write ! ( fmt, "{:?}[{:?}..-{:?}]" , input, from_start, from_end) ,
732
+
733
+ Ref ( _, borrow_kind, ref lv) => {
734
+ let kind_str = match borrow_kind {
735
+ BorrowKind :: Shared => "" ,
736
+ BorrowKind :: Mut | BorrowKind :: Unique => "mut " ,
737
+ } ;
738
+ write ! ( fmt, "&{}{:?}" , kind_str, lv)
739
+ }
740
+
741
+ Aggregate ( ref kind, ref lvs) => {
742
+ use self :: AggregateKind :: * ;
743
+
744
+ fn fmt_tuple ( fmt : & mut Formatter , name : & str , lvs : & [ Operand ] ) -> fmt:: Result {
745
+ let mut tuple_fmt = fmt. debug_tuple ( name) ;
746
+ for lv in lvs {
747
+ tuple_fmt. field ( lv) ;
748
+ }
749
+ tuple_fmt. finish ( )
750
+ }
751
+
752
+ match * kind {
753
+ Vec => write ! ( fmt, "{:?}" , lvs) ,
754
+
755
+ Tuple => {
756
+ if lvs. len ( ) == 1 {
757
+ write ! ( fmt, "({:?},)" , lvs[ 0 ] )
758
+ } else {
759
+ fmt_tuple ( fmt, "" , lvs)
760
+ }
761
+ }
762
+
763
+ Adt ( adt_def, variant, _) => {
764
+ let variant_def = & adt_def. variants [ variant] ;
765
+ let name = ty:: tls:: with ( |tcx| tcx. item_path_str ( variant_def. did ) ) ;
766
+
767
+ match variant_def. kind ( ) {
768
+ ty:: VariantKind :: Unit => write ! ( fmt, "{}" , name) ,
769
+ ty:: VariantKind :: Tuple => fmt_tuple ( fmt, & name, lvs) ,
770
+ ty:: VariantKind :: Struct => {
771
+ let mut struct_fmt = fmt. debug_struct ( & name) ;
772
+ for ( field, lv) in variant_def. fields . iter ( ) . zip ( lvs) {
773
+ struct_fmt. field ( & field. name . as_str ( ) , lv) ;
774
+ }
775
+ struct_fmt. finish ( )
776
+ }
777
+ }
778
+ }
779
+
780
+ Closure ( def_id, _) => ty:: tls:: with ( |tcx| {
781
+ if let Some ( node_id) = tcx. map . as_local_node_id ( def_id) {
782
+ let name = format ! ( "[closure@{:?}]" , tcx. map. span( node_id) ) ;
783
+ let mut struct_fmt = fmt. debug_struct ( & name) ;
784
+
785
+ tcx. with_freevars ( node_id, |freevars| {
786
+ for ( freevar, lv) in freevars. iter ( ) . zip ( lvs) {
787
+ let var_name = tcx. local_var_name_str ( freevar. def . var_id ( ) ) ;
788
+ struct_fmt. field ( & var_name, lv) ;
789
+ }
790
+ } ) ;
791
+
792
+ struct_fmt. finish ( )
793
+ } else {
794
+ write ! ( fmt, "[closure]" )
795
+ }
796
+ } ) ,
797
+ }
798
+ }
734
799
}
735
800
}
736
801
}
@@ -771,13 +836,13 @@ pub enum Literal<'tcx> {
771
836
}
772
837
773
838
impl < ' tcx > Debug for Constant < ' tcx > {
774
- fn fmt ( & self , fmt : & mut Formatter ) -> Result < ( ) , Error > {
839
+ fn fmt ( & self , fmt : & mut Formatter ) -> fmt :: Result {
775
840
write ! ( fmt, "{:?}" , self . literal)
776
841
}
777
842
}
778
843
779
844
impl < ' tcx > Debug for Literal < ' tcx > {
780
- fn fmt ( & self , fmt : & mut Formatter ) -> Result < ( ) , Error > {
845
+ fn fmt ( & self , fmt : & mut Formatter ) -> fmt :: Result {
781
846
use self :: Literal :: * ;
782
847
match * self {
783
848
Item { def_id, .. } =>
@@ -788,7 +853,7 @@ impl<'tcx> Debug for Literal<'tcx> {
788
853
}
789
854
790
855
/// Write a `ConstVal` in a way closer to the original source code than the `Debug` output.
791
- pub fn fmt_const_val < W : Write > ( fmt : & mut W , const_val : & ConstVal ) -> Result < ( ) , Error > {
856
+ pub fn fmt_const_val < W : Write > ( fmt : & mut W , const_val : & ConstVal ) -> fmt :: Result {
792
857
use middle:: const_eval:: ConstVal :: * ;
793
858
match * const_val {
794
859
Float ( f) => write ! ( fmt, "{:?}" , f) ,
0 commit comments