@@ -611,6 +611,7 @@ pub trait PrintState<'a> {
611
611
}
612
612
match lit. node {
613
613
ast:: LitKind :: Str ( st, style) => self . print_string ( & st. as_str ( ) , style) ,
614
+ ast:: LitKind :: ByteStr ( ref st, style) => self . print_byte_string ( st, style) ,
614
615
ast:: LitKind :: Err ( st) => {
615
616
let st = st. as_str ( ) . escape_debug ( ) . to_string ( ) ;
616
617
let mut res = String :: with_capacity ( st. len ( ) + 2 ) ;
@@ -651,14 +652,6 @@ pub trait PrintState<'a> {
651
652
ast:: LitKind :: Bool ( val) => {
652
653
if val { self . writer ( ) . word ( "true" ) } else { self . writer ( ) . word ( "false" ) }
653
654
}
654
- ast:: LitKind :: ByteStr ( ref v) => {
655
- let mut escaped: String = String :: new ( ) ;
656
- for & ch in v. iter ( ) {
657
- escaped. extend ( ascii:: escape_default ( ch)
658
- . map ( |c| c as char ) ) ;
659
- }
660
- self . writer ( ) . word ( format ! ( "b\" {}\" " , escaped) )
661
- }
662
655
}
663
656
}
664
657
@@ -677,6 +670,24 @@ pub trait PrintState<'a> {
677
670
self . writer ( ) . word ( st)
678
671
}
679
672
673
+ fn print_byte_string ( & mut self , st : & [ u8 ] , style : ast:: StrStyle ) -> io:: Result < ( ) > {
674
+ let st = match style {
675
+ ast:: StrStyle :: Cooked => {
676
+ let mut escaped = String :: with_capacity ( st. len ( ) ) ;
677
+ for & c in st {
678
+ escaped. extend ( ascii:: escape_default ( c) . map ( |c| c as char ) ) ;
679
+ }
680
+ format ! ( "b\" {}\" " , escaped)
681
+ }
682
+ ast:: StrStyle :: Raw ( n) => {
683
+ let st = String :: from_utf8 ( st. to_owned ( ) )
684
+ . expect ( "broken UTF-8 in a raw byte string literal" ) ;
685
+ format ! ( "br{delim}\" {string}\" {delim}" , delim="#" . repeat( n as usize ) , string=st)
686
+ }
687
+ } ;
688
+ self . writer ( ) . word ( st)
689
+ }
690
+
680
691
fn print_inner_attributes ( & mut self ,
681
692
attrs : & [ ast:: Attribute ] ) -> io:: Result < ( ) > {
682
693
self . print_either_attributes ( attrs, ast:: AttrStyle :: Inner , false , true )
0 commit comments