Skip to content

Commit 06b6434

Browse files
committed
preserve context in parsing of self varref
1 parent 728b269 commit 06b6434

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

src/libsyntax/parse/parser.rs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -541,12 +541,13 @@ impl<'a> Parser<'a> {
541541
// if the next token is the given keyword, eat it and return
542542
// true. Otherwise, return false.
543543
pub fn eat_keyword(&mut self, kw: keywords::Keyword) -> bool {
544-
let is_kw = match self.token {
545-
token::IDENT(sid, false) => kw.to_ident().name == sid.name,
544+
match self.token {
545+
token::IDENT(sid, false) if kw.to_ident().name == sid.name => {
546+
self.bump();
547+
true
548+
}
546549
_ => false
547-
};
548-
if is_kw { self.bump() }
549-
is_kw
550+
}
550551
}
551552

552553
// if the given word is not a keyword, signal an error.
@@ -1917,7 +1918,7 @@ impl<'a> Parser<'a> {
19171918
return self.mk_expr(blk.span.lo, blk.span.hi,
19181919
ExprBlock(blk));
19191920
},
1920-
_ if token::is_bar(&self.token) => {
1921+
token::BINOP(token::OR) | token::OROR => {
19211922
return self.parse_lambda_expr();
19221923
},
19231924
_ if self.eat_keyword(keywords::Proc) => {
@@ -1933,8 +1934,9 @@ impl<'a> Parser<'a> {
19331934
});
19341935
return self.mk_expr(lo, body.span.hi, ExprProc(decl, fakeblock));
19351936
},
1936-
_ if self.eat_keyword(keywords::Self) => {
1937-
let path = ast_util::ident_to_path(mk_sp(lo, hi), special_idents::self_);
1937+
token::IDENT(id @ ast::Ident{name:token::SELF_KEYWORD_NAME,ctxt:_},false) => {
1938+
self.bump();
1939+
let path = ast_util::ident_to_path(mk_sp(lo, hi), id);
19381940
ex = ExprPath(path);
19391941
hi = self.last_span.hi;
19401942
}
@@ -1982,7 +1984,7 @@ impl<'a> Parser<'a> {
19821984
},
19831985
token::LBRACKET => {
19841986
self.bump();
1985-
1987+
19861988
if self.token == token::RBRACKET {
19871989
// Empty vector.
19881990
self.bump();

0 commit comments

Comments
 (0)