-
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
base: main
Are you sure you want to change the base?
Conversation
This makes it obvious that inline const pat is removed (and the parsing is only preserved for better error message).
This feature has been removed but some lowering remains. Let's remove them.
|
Some changes occurred in src/tools/clippy cc @rust-lang/clippy Some changes occurred in match checking cc @Nadrieril |
|
cc @dianne |
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.
I'd prefer to land this via #149667. Otherwise, this looks good to me, apart from a couple nits. Since this fixes #148138, we'd probably also want a regression test for that and/or for the query cycle in #148138 (comment).
| /// 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)) | ||
| } |
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 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 arbitrary expressions aren't allowed in patterns error so this does fix #148138, but we'd be checking for const blocks in patterns at two separate stages of compilation.
| let bound = if self.check_inline_const(0) { | ||
| self.parse_const_block(self.token.span, true) | ||
| self.parse_pat_const_block(self.token.span) |
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.
Follow up to #138492 to remove the lowering of inline const that still remains.
Only visible change is that when reporting the error, the "const" keyword is covered in span too, which I think is better.
r? @lcnr