@@ -310,32 +310,17 @@ impl Token {
310310 }
311311 }
312312
313- fn ident_common ( & self , allow_raw : bool ) -> Option < ast:: Ident > {
313+ pub fn ident ( & self ) -> Option < ( ast:: Ident , bool ) > {
314314 match * self {
315- Ident ( ident, is_raw) if !is_raw || allow_raw => Some ( ident) ,
315+ Ident ( ident, is_raw) => Some ( ( ident, is_raw ) ) ,
316316 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 ) ) ,
318318 _ => None ,
319319 } ,
320320 _ => None ,
321321 }
322322 }
323323
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-
339324 /// Returns `true` if the token is an identifier.
340325 pub fn is_ident ( & self ) -> bool {
341326 self . ident ( ) . is_some ( )
@@ -404,37 +389,37 @@ impl Token {
404389
405390 /// Returns `true` if the token is a given keyword, `kw`.
406391 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 )
408393 }
409394
410395 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 ,
414399 }
415400 }
416401
417402 // Returns true for reserved identifiers used internally for elided lifetimes,
418403 // unnamed method parameters, crate root module, error recovery etc.
419404 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) ,
422407 _ => false ,
423408 }
424409 }
425410
426411 /// Returns `true` if the token is a keyword used in the language.
427412 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) ,
430415 _ => false ,
431416 }
432417 }
433418
434419 /// Returns `true` if the token is a keyword reserved for possible future use.
435420 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) ,
438423 _ => false ,
439424 }
440425 }
@@ -507,8 +492,8 @@ impl Token {
507492
508493 /// Returns `true` if the token is either a special identifier or a keyword.
509494 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) ,
512497 _ => false ,
513498 }
514499 }
0 commit comments