Skip to content

Commit

Permalink
Auto merge of #105701 - RedDocMD:bug-105634, r=cjgillot
Browse files Browse the repository at this point in the history
Allow .. to be parsed as let initializer

.. and ..= are valid expressions, however when used in a let statement
it is not parsed.
Fixes #105634
  • Loading branch information
bors committed Dec 25, 2022
2 parents d9ee0f4 + 4af9e6a commit 300aa90
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
4 changes: 4 additions & 0 deletions compiler/rustc_ast/src/token.rs
Expand Up @@ -379,6 +379,10 @@ impl Token {
}
}

pub fn is_range_separator(&self) -> bool {
[DotDot, DotDotDot, DotDotEq].contains(&self.kind)
}

pub fn is_op(&self) -> bool {
match self.kind {
Eq | Lt | Le | EqEq | Ne | Ge | Gt | AndAnd | OrOr | Not | Tilde | BinOp(_)
Expand Down
10 changes: 7 additions & 3 deletions compiler/rustc_parse/src/parser/expr.rs
Expand Up @@ -182,7 +182,7 @@ impl<'a> Parser<'a> {
LhsExpr::AttributesParsed(attrs) => Some(attrs),
_ => None,
};
if [token::DotDot, token::DotDotDot, token::DotDotEq].contains(&self.token.kind) {
if self.token.is_range_separator() {
return self.parse_prefix_range_expr(attrs);
} else {
self.parse_prefix_expr(attrs)?
Expand Down Expand Up @@ -514,7 +514,7 @@ impl<'a> Parser<'a> {
}

debug_assert!(
[token::DotDot, token::DotDotDot, token::DotDotEq].contains(&self.token.kind),
self.token.is_range_separator(),
"parse_prefix_range_expr: token {:?} is not DotDot/DotDotEq",
self.token
);
Expand Down Expand Up @@ -899,7 +899,11 @@ impl<'a> Parser<'a> {
let has_lifetime = self.token.is_lifetime() && self.look_ahead(1, |t| t != &token::Colon);
let lifetime = has_lifetime.then(|| self.expect_lifetime()); // For recovery, see below.
let (borrow_kind, mutbl) = self.parse_borrow_modifiers(lo);
let expr = self.parse_prefix_expr(None);
let expr = if self.token.is_range_separator() {
self.parse_prefix_range_expr(None)
} else {
self.parse_prefix_expr(None)
};
let (hi, expr) = self.interpolated_or_expr_span(expr)?;
let span = lo.to(hi);
if let Some(lt) = lifetime {
Expand Down
8 changes: 8 additions & 0 deletions src/test/ui/parser/issue-105634.rs
@@ -0,0 +1,8 @@
// check-pass

fn main() {
let _a = ..;
let _b = ..=10;
let _c = &..;
let _d = &..=10;
}

0 comments on commit 300aa90

Please sign in to comment.