@@ -225,8 +225,15 @@ pub enum TokenKind {
225
225
/* Literals */
226
226
Literal ( Lit ) ,
227
227
228
- /* Name components */
228
+ /// Identifier token.
229
+ /// Do not forget about `NtIdent` when you want to match on identifiers.
230
+ /// It's recommended to use `Token::(ident,uninterpolate,uninterpolated_span)` to
231
+ /// treat regular and interpolated identifiers in the same way.
229
232
Ident ( ast:: Name , /* is_raw */ bool ) ,
233
+ /// Lifetime identifier token.
234
+ /// Do not forget about `NtLifetime` when you want to match on lifetime identifiers.
235
+ /// It's recommended to use `Token::(lifetime,uninterpolate,uninterpolated_span)` to
236
+ /// treat regular and interpolated lifetime identifiers in the same way.
230
237
Lifetime ( ast:: Name ) ,
231
238
232
239
Interpolated ( Lrc < Nonterminal > ) ,
@@ -328,11 +335,12 @@ impl Token {
328
335
mem:: replace ( self , Token :: dummy ( ) )
329
336
}
330
337
331
- /// For interpolated tokens returns a span of the fragment to which the interpolated
332
- /// token refers, for all other tokens this is just a regular span.
338
+ /// For interpolated tokens, returns a span of the fragment to which the interpolated
339
+ /// token refers. For all other tokens this is just a regular span.
333
340
/// It is particularly important to use this for identifiers and lifetimes
334
- /// for which spans affect name resolution. This also includes edition checks
335
- /// for edition-specific keyword identifiers.
341
+ /// for which spans affect name resolution and edition checks.
342
+ /// Note that keywords are also identifiers, so they should use this
343
+ /// if they keep spans or perform edition checks.
336
344
pub fn uninterpolated_span ( & self ) -> Span {
337
345
match & self . kind {
338
346
Interpolated ( nt) => nt. span ( ) ,
@@ -453,6 +461,7 @@ impl Token {
453
461
}
454
462
}
455
463
464
+ // A convenience function for matching on identifiers during parsing.
456
465
// Turns interpolated identifier (`$i: ident`) or lifetime (`$l: lifetime`) token
457
466
// into the regular identifier or lifetime token it refers to,
458
467
// otherwise returns the original token.
0 commit comments