Skip to content

Commit dcaeb6a

Browse files
committed
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.
2 parents 30f081e + ca8578a commit dcaeb6a

File tree

3 files changed

+8
-11
lines changed

3 files changed

+8
-11
lines changed

src/libsyntax/parse/parser.rs

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

21402140
let ex: Expr_;
21412141

2142+
// Note: when adding new syntax here, don't forget to adjust Token::can_begin_expr().
21422143
match self.token {
21432144
token::OpenDelim(token::Paren) => {
21442145
self.bump();
@@ -2776,6 +2777,7 @@ impl<'a> Parser<'a> {
27762777
let lo = self.span.lo;
27772778
let hi;
27782779

2780+
// Note: when adding new unary operators, don't forget to adjust Token::can_begin_expr()
27792781
let ex;
27802782
match self.token {
27812783
token::Not => {
@@ -5536,13 +5538,6 @@ impl<'a> Parser<'a> {
55365538
(id, ItemEnum(enum_definition, generics), None)
55375539
}
55385540

5539-
fn fn_expr_lookahead(tok: &token::Token) -> bool {
5540-
match *tok {
5541-
token::OpenDelim(token::Paren) | token::At | token::Tilde | token::BinOp(_) => true,
5542-
_ => false
5543-
}
5544-
}
5545-
55465541
/// Parses a string as an ABI spec on an extern type or module. Consumes
55475542
/// the `extern` keyword, if one is found.
55485543
fn parse_opt_abi(&mut self) -> Option<abi::Abi> {
@@ -5715,8 +5710,7 @@ impl<'a> Parser<'a> {
57155710
maybe_append(attrs, extra_attrs));
57165711
return IoviItem(item);
57175712
}
5718-
if self.token.is_keyword(keywords::Fn) &&
5719-
self.look_ahead(1, |f| !Parser::fn_expr_lookahead(f)) {
5713+
if self.token.is_keyword(keywords::Fn) {
57205714
// FUNCTION ITEM
57215715
self.bump();
57225716
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,

src/test/run-pass/range.rs

+3
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212

1313
fn foo() -> int { 42 }
1414

15+
// Test that range syntax works in return statements
16+
fn return_range_to() -> ::std::ops::RangeTo<i32> { return ..1; }
17+
1518
pub fn main() {
1619
let mut count = 0;
1720
for i in 0u..10 {

0 commit comments

Comments
 (0)