@@ -310,32 +310,17 @@ impl Token {
310
310
}
311
311
}
312
312
313
- fn ident_common ( & self , allow_raw : bool ) -> Option < ast:: Ident > {
313
+ pub fn ident ( & self ) -> Option < ( ast:: Ident , bool ) > {
314
314
match * self {
315
- Ident ( ident, is_raw) if !is_raw || allow_raw => Some ( ident) ,
315
+ Ident ( ident, is_raw) => Some ( ( ident, is_raw ) ) ,
316
316
Interpolated ( ref nt) => match nt. 0 {
317
- NtIdent ( ident, is_raw) if !is_raw || allow_raw => Some ( ident. node ) ,
317
+ NtIdent ( ident, is_raw) => Some ( ( ident. node , is_raw ) ) ,
318
318
_ => None ,
319
319
} ,
320
320
_ => None ,
321
321
}
322
322
}
323
323
324
- pub fn nonraw_ident ( & self ) -> Option < ast:: Ident > {
325
- self . ident_common ( false )
326
- }
327
-
328
- pub fn is_raw_ident ( & self ) -> bool {
329
- match * self {
330
- Ident ( _, true ) => true ,
331
- _ => false ,
332
- }
333
- }
334
-
335
- pub fn ident ( & self ) -> Option < ast:: Ident > {
336
- self . ident_common ( true )
337
- }
338
-
339
324
/// Returns `true` if the token is an identifier.
340
325
pub fn is_ident ( & self ) -> bool {
341
326
self . ident ( ) . is_some ( )
@@ -404,37 +389,37 @@ impl Token {
404
389
405
390
/// Returns `true` if the token is a given keyword, `kw`.
406
391
pub fn is_keyword ( & self , kw : keywords:: Keyword ) -> bool {
407
- self . nonraw_ident ( ) . map ( |ident| ident. name == kw. name ( ) ) . unwrap_or ( false )
392
+ self . ident ( ) . map ( |( ident, is_raw ) | ident. name == kw. name ( ) && !is_raw ) . unwrap_or ( false )
408
393
}
409
394
410
395
pub fn is_path_segment_keyword ( & self ) -> bool {
411
- match self . nonraw_ident ( ) {
412
- Some ( id ) => is_path_segment_keyword ( id) ,
413
- None => false ,
396
+ match self . ident ( ) {
397
+ Some ( ( id , false ) ) => is_path_segment_keyword ( id) ,
398
+ _ => false ,
414
399
}
415
400
}
416
401
417
402
// Returns true for reserved identifiers used internally for elided lifetimes,
418
403
// unnamed method parameters, crate root module, error recovery etc.
419
404
pub fn is_special_ident ( & self ) -> bool {
420
- match self . nonraw_ident ( ) {
421
- Some ( id ) => is_special_ident ( id) ,
405
+ match self . ident ( ) {
406
+ Some ( ( id , false ) ) => is_special_ident ( id) ,
422
407
_ => false ,
423
408
}
424
409
}
425
410
426
411
/// Returns `true` if the token is a keyword used in the language.
427
412
pub fn is_used_keyword ( & self ) -> bool {
428
- match self . nonraw_ident ( ) {
429
- Some ( id ) => is_used_keyword ( id) ,
413
+ match self . ident ( ) {
414
+ Some ( ( id , false ) ) => is_used_keyword ( id) ,
430
415
_ => false ,
431
416
}
432
417
}
433
418
434
419
/// Returns `true` if the token is a keyword reserved for possible future use.
435
420
pub fn is_unused_keyword ( & self ) -> bool {
436
- match self . nonraw_ident ( ) {
437
- Some ( id ) => is_unused_keyword ( id) ,
421
+ match self . ident ( ) {
422
+ Some ( ( id , false ) ) => is_unused_keyword ( id) ,
438
423
_ => false ,
439
424
}
440
425
}
@@ -507,8 +492,8 @@ impl Token {
507
492
508
493
/// Returns `true` if the token is either a special identifier or a keyword.
509
494
pub fn is_reserved_ident ( & self ) -> bool {
510
- match self . nonraw_ident ( ) {
511
- Some ( id ) => is_reserved_ident ( id) ,
495
+ match self . ident ( ) {
496
+ Some ( ( id , false ) ) => is_reserved_ident ( id) ,
512
497
_ => false ,
513
498
}
514
499
}
0 commit comments