@@ -146,6 +146,7 @@ impl QuoteOffsets {
146
146
147
147
pub trait IsString : AstToken {
148
148
const RAW_PREFIX : & ' static str ;
149
+ const MODE : Mode ;
149
150
fn is_raw ( & self ) -> bool {
150
151
self . text ( ) . starts_with ( Self :: RAW_PREFIX )
151
152
}
@@ -181,7 +182,7 @@ pub trait IsString: AstToken {
181
182
let text = & self . text ( ) [ text_range_no_quotes - start] ;
182
183
let offset = text_range_no_quotes. start ( ) - start;
183
184
184
- unescape_literal ( text, Mode :: Str , & mut |range, unescaped_char| {
185
+ unescape_literal ( text, Self :: MODE , & mut |range, unescaped_char| {
185
186
let text_range =
186
187
TextRange :: new ( range. start . try_into ( ) . unwrap ( ) , range. end . try_into ( ) . unwrap ( ) ) ;
187
188
cb ( text_range + offset, unescaped_char) ;
@@ -196,6 +197,7 @@ pub trait IsString: AstToken {
196
197
197
198
impl IsString for ast:: String {
198
199
const RAW_PREFIX : & ' static str = "r" ;
200
+ const MODE : Mode = Mode :: Str ;
199
201
}
200
202
201
203
impl ast:: String {
@@ -213,7 +215,7 @@ impl ast::String {
213
215
let mut buf = String :: new ( ) ;
214
216
let mut prev_end = 0 ;
215
217
let mut has_error = false ;
216
- unescape_literal ( text, Mode :: Str , & mut |char_range, unescaped_char| match (
218
+ unescape_literal ( text, Self :: MODE , & mut |char_range, unescaped_char| match (
217
219
unescaped_char,
218
220
buf. capacity ( ) == 0 ,
219
221
) {
@@ -239,6 +241,7 @@ impl ast::String {
239
241
240
242
impl IsString for ast:: ByteString {
241
243
const RAW_PREFIX : & ' static str = "br" ;
244
+ const MODE : Mode = Mode :: ByteStr ;
242
245
}
243
246
244
247
impl ast:: ByteString {
@@ -256,7 +259,7 @@ impl ast::ByteString {
256
259
let mut buf: Vec < u8 > = Vec :: new ( ) ;
257
260
let mut prev_end = 0 ;
258
261
let mut has_error = false ;
259
- unescape_literal ( text, Mode :: ByteStr , & mut |char_range, unescaped_char| match (
262
+ unescape_literal ( text, Self :: MODE , & mut |char_range, unescaped_char| match (
260
263
unescaped_char,
261
264
buf. capacity ( ) == 0 ,
262
265
) {
@@ -282,6 +285,9 @@ impl ast::ByteString {
282
285
283
286
impl IsString for ast:: CString {
284
287
const RAW_PREFIX : & ' static str = "cr" ;
288
+ // XXX: `Mode::CStr` is not supported by `unescape_literal` of ra-ap-rustc_lexer yet.
289
+ // Here we pretend it to be a byte string.
290
+ const MODE : Mode = Mode :: ByteStr ;
285
291
}
286
292
287
293
impl ast:: CString {
@@ -299,7 +305,7 @@ impl ast::CString {
299
305
let mut buf = String :: new ( ) ;
300
306
let mut prev_end = 0 ;
301
307
let mut has_error = false ;
302
- unescape_literal ( text, Mode :: Str , & mut |char_range, unescaped_char| match (
308
+ unescape_literal ( text, Self :: MODE , & mut |char_range, unescaped_char| match (
303
309
unescaped_char,
304
310
buf. capacity ( ) == 0 ,
305
311
) {
0 commit comments