@@ -12,7 +12,7 @@ use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
12
12
use rustc_data_structures:: sync:: Lrc ;
13
13
use rustc_macros:: HashStable_Generic ;
14
14
use rustc_span:: symbol:: kw;
15
- use rustc_span:: symbol:: Symbol ;
15
+ use rustc_span:: symbol:: { Ident , Symbol } ;
16
16
use rustc_span:: { self , Span , DUMMY_SP } ;
17
17
use std:: borrow:: Cow ;
18
18
use std:: { fmt, mem} ;
@@ -145,7 +145,7 @@ impl Lit {
145
145
}
146
146
}
147
147
148
- pub fn ident_can_begin_expr ( name : ast :: Name , span : Span , is_raw : bool ) -> bool {
148
+ pub fn ident_can_begin_expr ( name : Symbol , span : Span , is_raw : bool ) -> bool {
149
149
let ident_token = Token :: new ( Ident ( name, is_raw) , span) ;
150
150
151
151
!ident_token. is_reserved_ident ( )
@@ -173,7 +173,7 @@ pub fn ident_can_begin_expr(name: ast::Name, span: Span, is_raw: bool) -> bool {
173
173
. contains ( & name)
174
174
}
175
175
176
- fn ident_can_begin_type ( name : ast :: Name , span : Span , is_raw : bool ) -> bool {
176
+ fn ident_can_begin_type ( name : Symbol , span : Span , is_raw : bool ) -> bool {
177
177
let ident_token = Token :: new ( Ident ( name, is_raw) , span) ;
178
178
179
179
!ident_token. is_reserved_ident ( )
@@ -229,18 +229,18 @@ pub enum TokenKind {
229
229
/// Do not forget about `NtIdent` when you want to match on identifiers.
230
230
/// It's recommended to use `Token::(ident,uninterpolate,uninterpolated_span)` to
231
231
/// treat regular and interpolated identifiers in the same way.
232
- Ident ( ast :: Name , /* is_raw */ bool ) ,
232
+ Ident ( Symbol , /* is_raw */ bool ) ,
233
233
/// Lifetime identifier token.
234
234
/// Do not forget about `NtLifetime` when you want to match on lifetime identifiers.
235
235
/// It's recommended to use `Token::(lifetime,uninterpolate,uninterpolated_span)` to
236
236
/// treat regular and interpolated lifetime identifiers in the same way.
237
- Lifetime ( ast :: Name ) ,
237
+ Lifetime ( Symbol ) ,
238
238
239
239
Interpolated ( Lrc < Nonterminal > ) ,
240
240
241
241
// Can be expanded into several tokens.
242
242
/// A doc comment.
243
- DocComment ( ast :: Name ) ,
243
+ DocComment ( Symbol ) ,
244
244
245
245
// Junk. These carry no data because we don't really care about the data
246
246
// they *would* carry, and don't really want to allocate a new ident for
@@ -249,9 +249,9 @@ pub enum TokenKind {
249
249
Whitespace ,
250
250
/// A comment.
251
251
Comment ,
252
- Shebang ( ast :: Name ) ,
252
+ Shebang ( Symbol ) ,
253
253
/// A completely invalid token which should be skipped.
254
- Unknown ( ast :: Name ) ,
254
+ Unknown ( Symbol ) ,
255
255
256
256
Eof ,
257
257
}
@@ -325,8 +325,8 @@ impl Token {
325
325
Token :: new ( TokenKind :: Whitespace , DUMMY_SP )
326
326
}
327
327
328
- /// Recovers a `Token` from an `ast:: Ident`. This creates a raw identifier if necessary.
329
- pub fn from_ast_ident ( ident : ast :: Ident ) -> Self {
328
+ /// Recovers a `Token` from an `Ident`. This creates a raw identifier if necessary.
329
+ pub fn from_ast_ident ( ident : Ident ) -> Self {
330
330
Token :: new ( Ident ( ident. name , ident. is_raw_guess ( ) ) , ident. span )
331
331
}
332
332
@@ -488,19 +488,19 @@ impl Token {
488
488
}
489
489
490
490
/// Returns an identifier if this token is an identifier.
491
- pub fn ident ( & self ) -> Option < ( ast :: Ident , /* is_raw */ bool ) > {
491
+ pub fn ident ( & self ) -> Option < ( Ident , /* is_raw */ bool ) > {
492
492
let token = self . uninterpolate ( ) ;
493
493
match token. kind {
494
- Ident ( name, is_raw) => Some ( ( ast :: Ident :: new ( name, token. span ) , is_raw) ) ,
494
+ Ident ( name, is_raw) => Some ( ( Ident :: new ( name, token. span ) , is_raw) ) ,
495
495
_ => None ,
496
496
}
497
497
}
498
498
499
499
/// Returns a lifetime identifier if this token is a lifetime.
500
- pub fn lifetime ( & self ) -> Option < ast :: Ident > {
500
+ pub fn lifetime ( & self ) -> Option < Ident > {
501
501
let token = self . uninterpolate ( ) ;
502
502
match token. kind {
503
- Lifetime ( name) => Some ( ast :: Ident :: new ( name, token. span ) ) ,
503
+ Lifetime ( name) => Some ( Ident :: new ( name, token. span ) ) ,
504
504
_ => None ,
505
505
}
506
506
}
@@ -577,28 +577,28 @@ impl Token {
577
577
}
578
578
579
579
pub fn is_path_segment_keyword ( & self ) -> bool {
580
- self . is_non_raw_ident_where ( ast :: Ident :: is_path_segment_keyword)
580
+ self . is_non_raw_ident_where ( Ident :: is_path_segment_keyword)
581
581
}
582
582
583
583
// Returns true for reserved identifiers used internally for elided lifetimes,
584
584
// unnamed method parameters, crate root module, error recovery etc.
585
585
pub fn is_special_ident ( & self ) -> bool {
586
- self . is_non_raw_ident_where ( ast :: Ident :: is_special)
586
+ self . is_non_raw_ident_where ( Ident :: is_special)
587
587
}
588
588
589
589
/// Returns `true` if the token is a keyword used in the language.
590
590
pub fn is_used_keyword ( & self ) -> bool {
591
- self . is_non_raw_ident_where ( ast :: Ident :: is_used_keyword)
591
+ self . is_non_raw_ident_where ( Ident :: is_used_keyword)
592
592
}
593
593
594
594
/// Returns `true` if the token is a keyword reserved for possible future use.
595
595
pub fn is_unused_keyword ( & self ) -> bool {
596
- self . is_non_raw_ident_where ( ast :: Ident :: is_unused_keyword)
596
+ self . is_non_raw_ident_where ( Ident :: is_unused_keyword)
597
597
}
598
598
599
599
/// Returns `true` if the token is either a special identifier or a keyword.
600
600
pub fn is_reserved_ident ( & self ) -> bool {
601
- self . is_non_raw_ident_where ( ast :: Ident :: is_reserved)
601
+ self . is_non_raw_ident_where ( Ident :: is_reserved)
602
602
}
603
603
604
604
/// Returns `true` if the token is the identifier `true` or `false`.
@@ -607,7 +607,7 @@ impl Token {
607
607
}
608
608
609
609
/// Returns `true` if the token is a non-raw identifier for which `pred` holds.
610
- pub fn is_non_raw_ident_where ( & self , pred : impl FnOnce ( ast :: Ident ) -> bool ) -> bool {
610
+ pub fn is_non_raw_ident_where ( & self , pred : impl FnOnce ( Ident ) -> bool ) -> bool {
611
611
match self . ident ( ) {
612
612
Some ( ( id, false ) ) => pred ( id) ,
613
613
_ => false ,
@@ -746,8 +746,8 @@ pub enum Nonterminal {
746
746
NtPat ( P < ast:: Pat > ) ,
747
747
NtExpr ( P < ast:: Expr > ) ,
748
748
NtTy ( P < ast:: Ty > ) ,
749
- NtIdent ( ast :: Ident , /* is_raw */ bool ) ,
750
- NtLifetime ( ast :: Ident ) ,
749
+ NtIdent ( Ident , /* is_raw */ bool ) ,
750
+ NtLifetime ( Ident ) ,
751
751
NtLiteral ( P < ast:: Expr > ) ,
752
752
/// Stuff inside brackets for attributes
753
753
NtMeta ( P < ast:: AttrItem > ) ,
0 commit comments