Remove lowering for inline const patterns and cleanup parsing#149685
Remove lowering for inline const patterns and cleanup parsing#149685nbdd0121 wants to merge 2 commits intorust-lang:mainfrom
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.
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.
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.
This might be untested, as discovered in #149667; we'll probably want a test for it.
Thanks for mentioning, I wasn't aware of that PR. I'll close this one then. If that one stalls please let me know and I'll re-open. |
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