Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Move eating const back into parse_const_block
  • Loading branch information
GrigorenkoPV committed Jun 19, 2025
commit 2d862accf619a9e4f1737ed215f2667bbfdeb409
4 changes: 2 additions & 2 deletions compiler/rustc_parse/src/parser/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1495,8 +1495,8 @@ impl<'a> Parser<'a> {
err
},
)
} else if this.eat_keyword(exp!(Const)) {
this.parse_const_block(lo.to(this.prev_token.span), false)
} else if this.check_keyword(exp!(Const)) {
this.parse_const_block(lo.to(this.token.span), false)
} else if this.may_recover() && this.is_do_catch_block() {
this.recover_do_catch()
} else if this.is_try_block() {
Expand Down
3 changes: 2 additions & 1 deletion compiler/rustc_parse/src/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1281,8 +1281,9 @@ impl<'a> Parser<'a> {
}
}

/// Parses inline const expressions. The `const` keyword was already eaten.
/// Parses inline const expressions.
fn parse_const_block(&mut self, span: Span, pat: bool) -> PResult<'a, P<Expr>> {
self.expect_keyword(exp!(Const))?;
let (attrs, blk) = self.parse_inner_attrs_and_block(None)?;
let anon_const = AnonConst {
id: DUMMY_NODE_ID,
Expand Down
8 changes: 3 additions & 5 deletions compiler/rustc_parse/src/parser/pat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -779,9 +779,9 @@ impl<'a> Parser<'a> {
self.parse_pat_ident(BindingMode(ByRef::Yes(mutbl), Mutability::Not), syntax_loc)?
} else if self.eat_keyword(exp!(Box)) {
self.parse_pat_box()?
} else if self.eat_keyword(exp!(Const)) {
} else if self.check_keyword(exp!(Const)) {
// Parse `const { pat }`
let const_expr = self.parse_const_block(lo.to(self.prev_token.span), true)?;
let const_expr = self.parse_const_block(lo.to(self.token.span), true)?;

if let Some(re) = self.parse_range_end() {
self.parse_pat_range_begin_with(const_expr, re)?
Expand Down Expand Up @@ -1268,9 +1268,7 @@ impl<'a> Parser<'a> {
.then_some(self.prev_token.span);

let bound = if self.check_inline_const(0) {
let _eaten = self.eat_keyword(exp!(Const));
debug_assert!(_eaten);
self.parse_const_block(self.prev_token.span, true)
self.parse_const_block(self.token.span, true)
} else if self.check_path() {
let lo = self.token.span;
let (qself, path) = if self.eat_lt() {
Expand Down
Loading