@@ -15,8 +15,9 @@ use middle::ty::{self, AdtDef, ClosureSubsts, FnOutput, Region, Ty};
15
15
use rustc_back:: slice;
16
16
use rustc_data_structures:: tuple_slice:: TupleSlice ;
17
17
use rustc_front:: hir:: InlineAsm ;
18
- use syntax:: ast:: Name ;
18
+ use syntax:: ast:: { self , Name } ;
19
19
use syntax:: codemap:: Span ;
20
+ use std:: ascii;
20
21
use std:: borrow:: { Cow , IntoCow } ;
21
22
use std:: fmt:: { self , Debug , Formatter , Write } ;
22
23
use std:: { iter, u32} ;
@@ -547,13 +548,11 @@ pub enum ProjectionElem<'tcx, V> {
547
548
548
549
/// Alias for projections as they appear in lvalues, where the base is an lvalue
549
550
/// and the index is an operand.
550
- pub type LvalueProjection < ' tcx > =
551
- Projection < ' tcx , Lvalue < ' tcx > , Operand < ' tcx > > ;
551
+ pub type LvalueProjection < ' tcx > = Projection < ' tcx , Lvalue < ' tcx > , Operand < ' tcx > > ;
552
552
553
553
/// Alias for projections as they appear in lvalues, where the base is an lvalue
554
554
/// and the index is an operand.
555
- pub type LvalueElem < ' tcx > =
556
- ProjectionElem < ' tcx , Operand < ' tcx > > ;
555
+ pub type LvalueElem < ' tcx > = ProjectionElem < ' tcx , Operand < ' tcx > > ;
557
556
558
557
/// Index into the list of fields found in a `VariantDef`
559
558
#[ derive( Copy , Clone , Debug , PartialEq , Eq , Hash , RustcEncodable , RustcDecodable ) ]
@@ -597,11 +596,11 @@ impl<'tcx> Debug for Lvalue<'tcx> {
597
596
598
597
match * self {
599
598
Var ( id) =>
600
- write ! ( fmt, "var{:?}" , id) ,
599
+ write ! ( fmt, "var{:?}" , id) ,
601
600
Arg ( id) =>
602
- write ! ( fmt, "arg{:?}" , id) ,
601
+ write ! ( fmt, "arg{:?}" , id) ,
603
602
Temp ( id) =>
604
- write ! ( fmt, "tmp{:?}" , id) ,
603
+ write ! ( fmt, "tmp{:?}" , id) ,
605
604
Static ( def_id) =>
606
605
write ! ( fmt, "{}" , ty:: tls:: with( |tcx| tcx. item_path_str( def_id) ) ) ,
607
606
ReturnPointer =>
@@ -897,26 +896,41 @@ impl<'tcx> Debug for Literal<'tcx> {
897
896
use self :: Literal :: * ;
898
897
match * self {
899
898
Item { def_id, .. } =>
900
- write ! ( fmt, "{}" , ty:: tls:: with( |tcx| tcx. item_path_str( def_id) ) ) ,
901
- Value { ref value } => fmt_const_val ( fmt, value) ,
899
+ write ! ( fmt, "{}" , item_path_str( def_id) ) ,
900
+ Value { ref value } => {
901
+ try!( write ! ( fmt, "const " ) ) ;
902
+ fmt_const_val ( fmt, value)
903
+ }
902
904
}
903
905
}
904
906
}
905
907
906
908
/// Write a `ConstVal` in a way closer to the original source code than the `Debug` output.
907
- pub fn fmt_const_val < W : Write > ( fmt : & mut W , const_val : & ConstVal ) -> fmt:: Result {
909
+ fn fmt_const_val < W : Write > ( fmt : & mut W , const_val : & ConstVal ) -> fmt:: Result {
908
910
use middle:: const_eval:: ConstVal :: * ;
909
911
match * const_val {
910
912
Float ( f) => write ! ( fmt, "{:?}" , f) ,
911
913
Int ( n) => write ! ( fmt, "{:?}" , n) ,
912
914
Uint ( n) => write ! ( fmt, "{:?}" , n) ,
913
- Str ( ref s) => write ! ( fmt, "Str({:?})" , s) ,
914
- ByteStr ( ref bytes) => write ! ( fmt, "ByteStr{:?}" , bytes) ,
915
+ Str ( ref s) => write ! ( fmt, "{:?}" , s) ,
916
+ ByteStr ( ref bytes) => {
917
+ let escaped: String = bytes
918
+ . iter ( )
919
+ . flat_map ( |& ch| ascii:: escape_default ( ch) . map ( |c| c as char ) )
920
+ . collect ( ) ;
921
+ write ! ( fmt, "b\" {}\" " , escaped)
922
+ }
915
923
Bool ( b) => write ! ( fmt, "{:?}" , b) ,
916
- Struct ( id) => write ! ( fmt, "Struct({:?})" , id) ,
917
- Tuple ( id) => write ! ( fmt, "Tuple({:?})" , id) ,
918
- Function ( def_id) => write ! ( fmt, "Function({:?})" , def_id) ,
919
- Array ( id, n) => write ! ( fmt, "Array({:?}, {:?})" , id, n) ,
920
- Repeat ( id, n) => write ! ( fmt, "Repeat({:?}, {:?})" , id, n) ,
924
+ Function ( def_id) => write ! ( fmt, "{}" , item_path_str( def_id) ) ,
925
+ Struct ( node_id) | Tuple ( node_id) | Array ( node_id, _) | Repeat ( node_id, _) =>
926
+ write ! ( fmt, "{}" , node_to_string( node_id) ) ,
921
927
}
922
928
}
929
+
930
+ fn node_to_string ( node_id : ast:: NodeId ) -> String {
931
+ ty:: tls:: with ( |tcx| tcx. map . node_to_user_string ( node_id) )
932
+ }
933
+
934
+ fn item_path_str ( def_id : DefId ) -> String {
935
+ ty:: tls:: with ( |tcx| tcx. item_path_str ( def_id) )
936
+ }
0 commit comments