Skip to content

Commit c1b8b3c

Browse files
committed
get rid of keyword idents, replace with names
should prevent future bugs
1 parent 06b6434 commit c1b8b3c

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

src/libsyntax/parse/parser.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -542,7 +542,7 @@ impl<'a> Parser<'a> {
542542
// true. Otherwise, return false.
543543
pub fn eat_keyword(&mut self, kw: keywords::Keyword) -> bool {
544544
match self.token {
545-
token::IDENT(sid, false) if kw.to_ident().name == sid.name => {
545+
token::IDENT(sid, false) if kw.to_name() == sid.name => {
546546
self.bump();
547547
true
548548
}
@@ -555,7 +555,7 @@ impl<'a> Parser<'a> {
555555
// otherwise, eat it.
556556
pub fn expect_keyword(&mut self, kw: keywords::Keyword) {
557557
if !self.eat_keyword(kw) {
558-
let id_interned_str = token::get_ident(kw.to_ident());
558+
let id_interned_str = token::get_name(kw.to_name());
559559
let token_str = self.this_token_to_string();
560560
self.fatal(format!("expected `{}`, found `{}`",
561561
id_interned_str, token_str).as_slice())

src/libsyntax/parse/token.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -413,26 +413,26 @@ macro_rules! declare_special_idents_and_keywords {(
413413
* the language and may not appear as identifiers.
414414
*/
415415
pub mod keywords {
416-
use ast::Ident;
416+
use ast::Name;
417417

418418
pub enum Keyword {
419419
$( $sk_variant, )*
420420
$( $rk_variant, )*
421421
}
422422

423423
impl Keyword {
424-
pub fn to_ident(&self) -> Ident {
424+
pub fn to_name(&self) -> Name {
425425
match *self {
426-
$( $sk_variant => Ident { name: $sk_name, ctxt: 0 }, )*
427-
$( $rk_variant => Ident { name: $rk_name, ctxt: 0 }, )*
426+
$( $sk_variant => $sk_name, )*
427+
$( $rk_variant => $rk_name, )*
428428
}
429429
}
430430
}
431431
}
432432

433433
fn mk_fresh_ident_interner() -> IdentInterner {
434434
// The indices here must correspond to the numbers in
435-
// special_idents, in Keyword to_ident(), and in static
435+
// special_idents, in Keyword to_name(), and in static
436436
// constants below.
437437
let mut init_vec = Vec::new();
438438
$(init_vec.push($si_str);)*
@@ -710,7 +710,7 @@ pub fn fresh_mark() -> Mrk {
710710

711711
pub fn is_keyword(kw: keywords::Keyword, tok: &Token) -> bool {
712712
match *tok {
713-
token::IDENT(sid, false) => { kw.to_ident().name == sid.name }
713+
token::IDENT(sid, false) => { kw.to_name() == sid.name }
714714
_ => { false }
715715
}
716716
}

0 commit comments

Comments
 (0)