Skip to content

Commit 5cc1559

Browse files
committed
token: refactor with is_non_raw_ident_where.
1 parent 2bd27fb commit 5cc1559

File tree

1 file changed

+13
-19
lines changed

1 file changed

+13
-19
lines changed

src/libsyntax/parse/token.rs

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,7 @@ impl Token {
409409
crate fn expect_lit(&self) -> Lit {
410410
match self.kind {
411411
Literal(lit) => lit,
412-
_=> panic!("`expect_lit` called on non-literal"),
412+
_ => panic!("`expect_lit` called on non-literal"),
413413
}
414414
}
415415

@@ -457,6 +457,7 @@ impl Token {
457457
pub fn is_ident(&self) -> bool {
458458
self.ident().is_some()
459459
}
460+
460461
/// Returns `true` if the token is a lifetime.
461462
crate fn is_lifetime(&self) -> bool {
462463
self.lifetime().is_some()
@@ -508,45 +509,38 @@ impl Token {
508509

509510
/// Returns `true` if the token is a given keyword, `kw`.
510511
pub fn is_keyword(&self, kw: Symbol) -> bool {
511-
self.ident().map(|(id, is_raw)| id.name == kw && !is_raw).unwrap_or(false)
512+
self.is_non_raw_ident_where(|id| id.name == kw)
512513
}
513514

514515
crate fn is_path_segment_keyword(&self) -> bool {
515-
match self.ident() {
516-
Some((id, false)) => id.is_path_segment_keyword(),
517-
_ => false,
518-
}
516+
self.is_non_raw_ident_where(ast::Ident::is_path_segment_keyword)
519517
}
520518

521519
// Returns true for reserved identifiers used internally for elided lifetimes,
522520
// unnamed method parameters, crate root module, error recovery etc.
523521
crate fn is_special_ident(&self) -> bool {
524-
match self.ident() {
525-
Some((id, false)) => id.is_special(),
526-
_ => false,
527-
}
522+
self.is_non_raw_ident_where(ast::Ident::is_special)
528523
}
529524

530525
/// Returns `true` if the token is a keyword used in the language.
531526
crate fn is_used_keyword(&self) -> bool {
532-
match self.ident() {
533-
Some((id, false)) => id.is_used_keyword(),
534-
_ => false,
535-
}
527+
self.is_non_raw_ident_where(ast::Ident::is_used_keyword)
536528
}
537529

538530
/// Returns `true` if the token is a keyword reserved for possible future use.
539531
crate fn is_unused_keyword(&self) -> bool {
540-
match self.ident() {
541-
Some((id, false)) => id.is_unused_keyword(),
542-
_ => false,
543-
}
532+
self.is_non_raw_ident_where(ast::Ident::is_unused_keyword)
544533
}
545534

546535
/// Returns `true` if the token is either a special identifier or a keyword.
547536
pub fn is_reserved_ident(&self) -> bool {
537+
self.is_non_raw_ident_where(ast::Ident::is_reserved)
538+
}
539+
540+
/// Returns `true` if the token is a non-raw identifier for which `pred` holds.
541+
fn is_non_raw_ident_where(&self, pred: impl FnOnce(ast::Ident) -> bool) -> bool {
548542
match self.ident() {
549-
Some((id, false)) => id.is_reserved(),
543+
Some((id, false)) => pred(id),
550544
_ => false,
551545
}
552546
}

0 commit comments

Comments
 (0)