提交 dcaeb6aa 编写于 作者: B bors

auto merge of #20901 : dgrunwald/rust/update-token-can-begin-expr, r=sanxiyn

 * add `Token::AndAnd` (double borrow)
 * add `Token::DotDot` (range notation)
 * remove `Token::Pound` and `Token::At`

This 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.
......@@ -2139,6 +2139,7 @@ pub fn parse_bottom_expr(&mut self) -> P<Expr> {
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();
......@@ -2776,6 +2777,7 @@ pub fn parse_prefix_expr(&mut self) -> P<Expr> {
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 => {
......@@ -5536,13 +5538,6 @@ fn parse_item_enum(&mut self) -> ItemInfo {
(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> {
......@@ -5715,8 +5710,7 @@ fn parse_item_or_view_item(&mut self,
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) =
......
......@@ -183,14 +183,14 @@ pub fn can_begin_expr(&self) -> bool {
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,
......
......@@ -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 {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册