@@ -15,8 +15,9 @@ use middle::ty::{self, AdtDef, ClosureSubsts, FnOutput, Region, Ty};
1515use rustc_back:: slice;
1616use rustc_data_structures:: tuple_slice:: TupleSlice ;
1717use rustc_front:: hir:: InlineAsm ;
18- use syntax:: ast:: Name ;
18+ use syntax:: ast:: { self , Name } ;
1919use syntax:: codemap:: Span ;
20+ use std:: ascii;
2021use std:: borrow:: { Cow , IntoCow } ;
2122use std:: fmt:: { self , Debug , Formatter , Write } ;
2223use std:: { iter, u32} ;
@@ -547,13 +548,11 @@ pub enum ProjectionElem<'tcx, V> {
547548
548549/// Alias for projections as they appear in lvalues, where the base is an lvalue
549550/// 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 > > ;
552552
553553/// Alias for projections as they appear in lvalues, where the base is an lvalue
554554/// 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 > > ;
557556
558557/// Index into the list of fields found in a `VariantDef`
559558#[ derive( Copy , Clone , Debug , PartialEq , Eq , Hash , RustcEncodable , RustcDecodable ) ]
@@ -597,11 +596,11 @@ impl<'tcx> Debug for Lvalue<'tcx> {
597596
598597 match * self {
599598 Var ( id) =>
600- write ! ( fmt, "var{:?}" , id) ,
599+ write ! ( fmt, "var{:?}" , id) ,
601600 Arg ( id) =>
602- write ! ( fmt, "arg{:?}" , id) ,
601+ write ! ( fmt, "arg{:?}" , id) ,
603602 Temp ( id) =>
604- write ! ( fmt, "tmp{:?}" , id) ,
603+ write ! ( fmt, "tmp{:?}" , id) ,
605604 Static ( def_id) =>
606605 write ! ( fmt, "{}" , ty:: tls:: with( |tcx| tcx. item_path_str( def_id) ) ) ,
607606 ReturnPointer =>
@@ -897,26 +896,41 @@ impl<'tcx> Debug for Literal<'tcx> {
897896 use self :: Literal :: * ;
898897 match * self {
899898 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+ }
902904 }
903905 }
904906}
905907
906908/// 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 {
908910 use middle:: const_eval:: ConstVal :: * ;
909911 match * const_val {
910912 Float ( f) => write ! ( fmt, "{:?}" , f) ,
911913 Int ( n) => write ! ( fmt, "{:?}" , n) ,
912914 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+ }
915923 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) ) ,
921927 }
922928}
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