Skip to content

Commit bb10afd

Browse files
committed
Move eating const back into parse_const_block
1 parent e4a9b8b commit bb10afd

File tree

3 files changed

+7
-8
lines changed

3 files changed

+7
-8
lines changed

compiler/rustc_parse/src/parser/expr.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1472,8 +1472,8 @@ impl<'a> Parser<'a> {
14721472
err
14731473
},
14741474
)
1475-
} else if this.eat_keyword(kw::Const) {
1476-
this.parse_const_block(lo.to(this.prev_token.span), false)
1475+
} else if this.check_keyword(kw::Const) {
1476+
this.parse_const_block(lo.to(this.token.span), false)
14771477
} else if this.may_recover() && this.is_do_catch_block() {
14781478
this.recover_do_catch()
14791479
} else if this.is_try_block() {

compiler/rustc_parse/src/parser/mod.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1302,11 +1302,12 @@ impl<'a> Parser<'a> {
13021302
}
13031303
}
13041304

1305-
/// Parses inline const expressions. The `const` keyword was already eaten.
1305+
/// Parses inline const expressions.
13061306
fn parse_const_block(&mut self, span: Span, pat: bool) -> PResult<'a, P<Expr>> {
13071307
if pat {
13081308
self.psess.gated_spans.gate(sym::inline_const_pat, span);
13091309
}
1310+
self.expect_keyword(kw::Const)?;
13101311
let (attrs, blk) = self.parse_inner_attrs_and_block()?;
13111312
let anon_const = AnonConst {
13121313
id: DUMMY_NODE_ID,

compiler/rustc_parse/src/parser/pat.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -730,9 +730,9 @@ impl<'a> Parser<'a> {
730730
self.parse_pat_ident(BindingMode(ByRef::Yes(mutbl), Mutability::Not), syntax_loc)?
731731
} else if self.eat_keyword(kw::Box) {
732732
self.parse_pat_box()?
733-
} else if self.eat_keyword(kw::Const) {
733+
} else if self.check_keyword(kw::Const) {
734734
// Parse `const { pat }`
735-
let const_expr = self.parse_const_block(lo.to(self.prev_token.span), true)?;
735+
let const_expr = self.parse_const_block(lo.to(self.token.span), true)?;
736736

737737
if let Some(re) = self.parse_range_end() {
738738
self.parse_pat_range_begin_with(const_expr, re)?
@@ -1220,9 +1220,7 @@ impl<'a> Parser<'a> {
12201220
.then_some(self.prev_token.span);
12211221

12221222
let bound = if self.check_inline_const(0) {
1223-
let _eaten = self.eat_keyword(kw::Const);
1224-
debug_assert!(_eaten);
1225-
self.parse_const_block(self.prev_token.span, true)
1223+
self.parse_const_block(self.token.span, true)
12261224
} else if self.check_path() {
12271225
let lo = self.token.span;
12281226
let (qself, path) = if self.eat_lt() {

0 commit comments

Comments
 (0)