11//! Code related to parsing literals.
22
3- use crate :: ast:: { self , LitKind , MetaItemLit } ;
3+ use crate :: ast:: { self , LitKind , MetaItemLit , StrStyle } ;
44use crate :: token:: { self , Token } ;
55use rustc_lexer:: unescape:: { byte_from_char, unescape_byte, unescape_char, unescape_literal, Mode } ;
66use rustc_span:: symbol:: { kw, sym, Symbol } ;
77use rustc_span:: Span ;
88use std:: ascii;
9+ use std:: str;
910
1011#[ derive( Debug ) ]
1112pub enum LitError {
@@ -115,9 +116,9 @@ impl LitKind {
115116 }
116117 } ) ;
117118 error?;
118- LitKind :: ByteStr ( buf. into ( ) )
119+ LitKind :: ByteStr ( buf. into ( ) , StrStyle :: Cooked )
119120 }
120- token:: ByteStrRaw ( _ ) => {
121+ token:: ByteStrRaw ( n ) => {
121122 let s = symbol. as_str ( ) ;
122123 let bytes = if s. contains ( '\r' ) {
123124 let mut buf = Vec :: with_capacity ( s. len ( ) ) ;
@@ -136,7 +137,7 @@ impl LitKind {
136137 symbol. to_string ( ) . into_bytes ( )
137138 } ;
138139
139- LitKind :: ByteStr ( bytes. into ( ) )
140+ LitKind :: ByteStr ( bytes. into ( ) , StrStyle :: Raw ( n ) )
140141 }
141142 token:: Err => LitKind :: Err ,
142143 } )
@@ -155,10 +156,15 @@ impl LitKind {
155156 ( token:: Str , symbol, None )
156157 }
157158 LitKind :: Str ( symbol, ast:: StrStyle :: Raw ( n) ) => ( token:: StrRaw ( n) , symbol, None ) ,
158- LitKind :: ByteStr ( ref bytes) => {
159+ LitKind :: ByteStr ( ref bytes, ast :: StrStyle :: Cooked ) => {
159160 let string = bytes. escape_ascii ( ) . to_string ( ) ;
160161 ( token:: ByteStr , Symbol :: intern ( & string) , None )
161162 }
163+ LitKind :: ByteStr ( ref bytes, ast:: StrStyle :: Raw ( n) ) => {
164+ // Unwrap because raw byte string literals can only contain ASCII.
165+ let string = str:: from_utf8 ( bytes) . unwrap ( ) ;
166+ ( token:: ByteStrRaw ( n) , Symbol :: intern ( & string) , None )
167+ }
162168 LitKind :: Byte ( byte) => {
163169 let string: String = ascii:: escape_default ( byte) . map ( Into :: < char > :: into) . collect ( ) ;
164170 ( token:: Byte , Symbol :: intern ( & string) , None )
0 commit comments