Skip to content

Commit d0863ad

Browse files
committed
Update Token::can_begin_expr() to make it consistent with the grammar:
* add Token::AndAnd (double borrow) * add Token::DotDot (range notation) * remove Token::Pound and Token::At Fixes a syntax error when parsing "fn f() -> RangeTo<i32> { return ..1; }". Also, remove "fn_expr_lookahead". It's from the fn~ days and seems to no longer be necessary.
1 parent 099b411 commit d0863ad

File tree

2 files changed

+5
-11
lines changed

2 files changed

+5
-11
lines changed

src/libsyntax/parse/parser.rs

+3-9
Original file line numberDiff line numberDiff line change
@@ -2167,6 +2167,7 @@ impl<'a> Parser<'a> {
21672167

21682168
let ex: Expr_;
21692169

2170+
// Note: when adding new syntax here, don't forget to adjust Token::can_begin_expr().
21702171
match self.token {
21712172
token::OpenDelim(token::Paren) => {
21722173
self.bump();
@@ -2773,6 +2774,7 @@ impl<'a> Parser<'a> {
27732774
let lo = self.span.lo;
27742775
let hi;
27752776

2777+
// Note: when adding new unary operators, don't forget to adjust Token::can_begin_expr()
27762778
let ex;
27772779
match self.token {
27782780
token::Not => {
@@ -5590,13 +5592,6 @@ impl<'a> Parser<'a> {
55905592
(id, ItemEnum(enum_definition, generics), None)
55915593
}
55925594

5593-
fn fn_expr_lookahead(tok: &token::Token) -> bool {
5594-
match *tok {
5595-
token::OpenDelim(token::Paren) | token::At | token::Tilde | token::BinOp(_) => true,
5596-
_ => false
5597-
}
5598-
}
5599-
56005595
/// Parses a string as an ABI spec on an extern type or module. Consumes
56015596
/// the `extern` keyword, if one is found.
56025597
fn parse_opt_abi(&mut self) -> Option<abi::Abi> {
@@ -5779,8 +5774,7 @@ impl<'a> Parser<'a> {
57795774
maybe_append(attrs, extra_attrs));
57805775
return IoviItem(item);
57815776
}
5782-
if self.token.is_keyword(keywords::Fn) &&
5783-
self.look_ahead(1, |f| !Parser::fn_expr_lookahead(f)) {
5777+
if self.token.is_keyword(keywords::Fn) {
57845778
// FUNCTION ITEM
57855779
self.bump();
57865780
let (ident, item_, extra_attrs) =

src/libsyntax/parse/token.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -183,14 +183,14 @@ impl Token {
183183
Underscore => true,
184184
Tilde => true,
185185
Literal(_, _) => true,
186-
Pound => true,
187-
At => true,
188186
Not => true,
189187
BinOp(Minus) => true,
190188
BinOp(Star) => true,
191189
BinOp(And) => true,
192190
BinOp(Or) => true, // in lambda syntax
193191
OrOr => true, // in lambda syntax
192+
AndAnd => true, // double borrow
193+
DotDot => true, // range notation
194194
ModSep => true,
195195
Interpolated(NtExpr(..)) => true,
196196
Interpolated(NtIdent(..)) => true,

0 commit comments

Comments
 (0)