33use std:: { ascii, fmt, str} ;
44
55use rustc_lexer:: unescape:: {
6- MixedUnit , Mode , byte_from_char , unescape_byte , unescape_char, unescape_mixed , unescape_unicode ,
6+ MixedUnit , unescape_byte , unescape_byte_str , unescape_char, unescape_cstr , unescape_str ,
77} ;
88use rustc_span:: { Span , Symbol , kw, sym} ;
99use tracing:: debug;
@@ -87,11 +87,10 @@ impl LitKind {
8787 // Force-inlining here is aggressive but the closure is
8888 // called on every char in the string, so it can be hot in
8989 // programs with many long strings containing escapes.
90- unescape_unicode (
90+ unescape_str (
9191 s,
92- Mode :: Str ,
9392 & mut #[ inline ( always) ]
94- |_, c | match c {
93+ |_, res | match res {
9594 Ok ( c) => buf. push ( c) ,
9695 Err ( err) => {
9796 assert ! ( !err. is_fatal( ) , "failed to unescape string literal" )
@@ -111,8 +110,8 @@ impl LitKind {
111110 token:: ByteStr => {
112111 let s = symbol. as_str ( ) ;
113112 let mut buf = Vec :: with_capacity ( s. len ( ) ) ;
114- unescape_unicode ( s, Mode :: ByteStr , & mut |_, c | match c {
115- Ok ( c ) => buf. push ( byte_from_char ( c ) ) ,
113+ unescape_byte_str ( s, & mut |_, res | match res {
114+ Ok ( b ) => buf. push ( b ) ,
116115 Err ( err) => {
117116 assert ! ( !err. is_fatal( ) , "failed to unescape string literal" )
118117 }
@@ -128,11 +127,11 @@ impl LitKind {
128127 token:: CStr => {
129128 let s = symbol. as_str ( ) ;
130129 let mut buf = Vec :: with_capacity ( s. len ( ) ) ;
131- unescape_mixed ( s , Mode :: CStr , & mut |_span, c| match c {
130+ unescape_cstr ( s , & mut |_span, c| match c {
132131 Ok ( MixedUnit :: Char ( c) ) => {
133- buf. extend_from_slice ( c. encode_utf8 ( & mut [ 0 ; 4 ] ) . as_bytes ( ) )
132+ buf. extend_from_slice ( c. get ( ) . encode_utf8 ( & mut [ 0 ; 4 ] ) . as_bytes ( ) )
134133 }
135- Ok ( MixedUnit :: HighByte ( b) ) => buf. push ( b) ,
134+ Ok ( MixedUnit :: HighByte ( b) ) => buf. push ( b. get ( ) ) ,
136135 Err ( err) => {
137136 assert ! ( !err. is_fatal( ) , "failed to unescape C string literal" )
138137 }
0 commit comments