3
3
use std:: { ascii, fmt, str} ;
4
4
5
5
use 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 ,
7
7
} ;
8
8
use rustc_span:: { Span , Symbol , kw, sym} ;
9
9
use tracing:: debug;
@@ -87,11 +87,10 @@ impl LitKind {
87
87
// Force-inlining here is aggressive but the closure is
88
88
// called on every char in the string, so it can be hot in
89
89
// programs with many long strings containing escapes.
90
- unescape_unicode (
90
+ unescape_str (
91
91
s,
92
- Mode :: Str ,
93
92
& mut #[ inline ( always) ]
94
- |_, c | match c {
93
+ |_, res | match res {
95
94
Ok ( c) => buf. push ( c) ,
96
95
Err ( err) => {
97
96
assert ! ( !err. is_fatal( ) , "failed to unescape string literal" )
@@ -111,8 +110,8 @@ impl LitKind {
111
110
token:: ByteStr => {
112
111
let s = symbol. as_str ( ) ;
113
112
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 ) ,
116
115
Err ( err) => {
117
116
assert ! ( !err. is_fatal( ) , "failed to unescape string literal" )
118
117
}
@@ -128,11 +127,11 @@ impl LitKind {
128
127
token:: CStr => {
129
128
let s = symbol. as_str ( ) ;
130
129
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 {
132
131
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 ( ) )
134
133
}
135
- Ok ( MixedUnit :: HighByte ( b) ) => buf. push ( b) ,
134
+ Ok ( MixedUnit :: HighByte ( b) ) => buf. push ( b. get ( ) ) ,
136
135
Err ( err) => {
137
136
assert ! ( !err. is_fatal( ) , "failed to unescape C string literal" )
138
137
}
0 commit comments