Skip to content

Update Token::can_begin_expr() to make it consistent with the grammar: #20901

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 18, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 3 additions & 9 deletions src/libsyntax/parse/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2167,6 +2167,7 @@ impl<'a> Parser<'a> {

let ex: Expr_;

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

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

fn fn_expr_lookahead(tok: &token::Token) -> bool {
match *tok {
token::OpenDelim(token::Paren) | token::At | token::Tilde | token::BinOp(_) => true,
_ => false
}
}

/// Parses a string as an ABI spec on an extern type or module. Consumes
/// the `extern` keyword, if one is found.
fn parse_opt_abi(&mut self) -> Option<abi::Abi> {
Expand Down Expand Up @@ -5779,8 +5774,7 @@ impl<'a> Parser<'a> {
maybe_append(attrs, extra_attrs));
return IoviItem(item);
}
if self.token.is_keyword(keywords::Fn) &&
self.look_ahead(1, |f| !Parser::fn_expr_lookahead(f)) {
if self.token.is_keyword(keywords::Fn) {
// FUNCTION ITEM
self.bump();
let (ident, item_, extra_attrs) =
Expand Down
4 changes: 2 additions & 2 deletions src/libsyntax/parse/token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,14 +183,14 @@ impl Token {
Underscore => true,
Tilde => true,
Literal(_, _) => true,
Pound => true,
At => true,
Not => true,
BinOp(Minus) => true,
BinOp(Star) => true,
BinOp(And) => true,
BinOp(Or) => true, // in lambda syntax
OrOr => true, // in lambda syntax
AndAnd => true, // double borrow
DotDot => true, // range notation
ModSep => true,
Interpolated(NtExpr(..)) => true,
Interpolated(NtIdent(..)) => true,
Expand Down
3 changes: 3 additions & 0 deletions src/test/run-pass/range.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@

fn foo() -> int { 42 }

// Test that range syntax works in return statements
fn return_range_to() -> ::std::ops::RangeTo<i32> { return ..1; }

pub fn main() {
let mut count = 0;
for i in 0u..10 {
Expand Down