-
Notifications
You must be signed in to change notification settings - Fork 14.1k
Remove lowering for inline const patterns and cleanup parsing #149685
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -786,7 +786,7 @@ impl<'a> Parser<'a> { | |
| self.parse_pat_box()? | ||
| } else if self.check_inline_const(0) { | ||
| // Parse `const pat` | ||
| let const_expr = self.parse_const_block(lo.to(self.token.span), true)?; | ||
| let const_expr = self.parse_pat_const_block(lo.to(self.token.span))?; | ||
|
|
||
| if let Some(re) = self.parse_range_end() { | ||
| self.parse_pat_range_begin_with(const_expr, re)? | ||
|
|
@@ -1281,7 +1281,7 @@ impl<'a> Parser<'a> { | |
| .then_some(self.prev_token.span); | ||
|
|
||
| let bound = if self.check_inline_const(0) { | ||
| self.parse_const_block(self.token.span, true) | ||
| self.parse_pat_const_block(self.token.span) | ||
| } else if self.check_path() { | ||
| let lo = self.token.span; | ||
| let (qself, path) = if self.eat_lt() { | ||
|
|
@@ -1767,6 +1767,20 @@ impl<'a> Parser<'a> { | |
| }) | ||
| } | ||
|
|
||
| /// Parse `const {}` in patterns - this syntax has been removed, but we still parse this | ||
| /// for now to provide a more useful error. | ||
| fn parse_pat_const_block(&mut self, span: Span) -> PResult<'a, Box<Expr>> { | ||
| let expr = self.parse_const_block(span)?; | ||
| let guar = self | ||
| .dcx() | ||
| .struct_span_err(expr.span, "const blocks cannot be used as patterns") | ||
| .with_help( | ||
| "use a named `const`-item or an `if`-guard (`x if x == const { ... }`) instead", | ||
| ) | ||
| .emit(); | ||
| Ok(self.mk_expr_err(expr.span, guar)) | ||
| } | ||
|
Comment on lines
+1770
to
+1782
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This won't catch every const block used in patterns; see #148138 (comment). Of course, the cases this doesn't catch will be caught in AST lowering after this change and result in an |
||
|
|
||
| pub(super) fn mk_pat_ident(&self, span: Span, ann: BindingMode, ident: Ident) -> Pat { | ||
| self.mk_pat(span, PatKind::Ident(ann, ident, None)) | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This might be untested, as discovered in #149667; we'll probably want a test for it.