Skip to content

Conversation

@nbdd0121
Copy link
Member

@nbdd0121 nbdd0121 commented Dec 5, 2025

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

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.
@rustbot
Copy link
Collaborator

rustbot commented Dec 5, 2025

Some changes occurred in src/tools/clippy

cc @rust-lang/clippy

Some changes occurred in match checking

cc @Nadrieril

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-clippy Relevant to the Clippy team. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Dec 5, 2025
@Nadrieril
Copy link
Member

cc @dianne

Copy link
Contributor

@dianne dianne left a 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).

View changes since this review

Comment on lines +1770 to +1782
/// 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))
}
Copy link
Contributor

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.

Comment on lines 1283 to +1284
let bound = if self.check_inline_const(0) {
self.parse_const_block(self.token.span, true)
self.parse_pat_const_block(self.token.span)
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-clippy Relevant to the Clippy team. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants