diff options
| author | bors <bors@rust-lang.org> | 2022-12-25 14:42:49 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2022-12-25 14:42:49 +0000 |
| commit | 300aa907a682dfa492f4eb394d27f5331fba0a64 (patch) | |
| tree | 670d3bbba1e7444b03d41fea73252874354b5bcb | |
| parent | d9ee0f468f8d07e92da94fe991db91e95822d721 (diff) | |
| parent | 4af9e6a1c203b6459aea23aed05924fcf2e12c58 (diff) | |
| download | rust-300aa907a682dfa492f4eb394d27f5331fba0a64.tar.gz rust-300aa907a682dfa492f4eb394d27f5331fba0a64.zip | |
Auto merge of #105701 - RedDocMD:bug-105634, r=cjgillot
Allow .. to be parsed as let initializer .. and ..= are valid expressions, however when used in a let statement it is not parsed. Fixes #105634
| -rw-r--r-- | compiler/rustc_ast/src/token.rs | 4 | ||||
| -rw-r--r-- | compiler/rustc_parse/src/parser/expr.rs | 10 | ||||
| -rw-r--r-- | src/test/ui/parser/issue-105634.rs | 8 |
3 files changed, 19 insertions, 3 deletions
diff --git a/compiler/rustc_ast/src/token.rs b/compiler/rustc_ast/src/token.rs index 7b8c0d79a17..5b6cf30fa96 100644 --- a/compiler/rustc_ast/src/token.rs +++ b/compiler/rustc_ast/src/token.rs @@ -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(_) diff --git a/compiler/rustc_parse/src/parser/expr.rs b/compiler/rustc_parse/src/parser/expr.rs index c0ed450b985..6a115088eca 100644 --- a/compiler/rustc_parse/src/parser/expr.rs +++ b/compiler/rustc_parse/src/parser/expr.rs @@ -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)? @@ -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 ); @@ -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 { diff --git a/src/test/ui/parser/issue-105634.rs b/src/test/ui/parser/issue-105634.rs new file mode 100644 index 00000000000..579aa6e5bfb --- /dev/null +++ b/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; +} |
