Skip to content

Commit 31af5b0

Browse files
committed
Move eating const back into parse_const_block
1 parent a49aece commit 31af5b0

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
@@ -1473,8 +1473,8 @@ impl<'a> Parser<'a> {
14731473
err
14741474
},
14751475
)
1476-
} else if this.eat_keyword(kw::Const) {
1477-
this.parse_const_block(lo.to(this.prev_token.span), false)
1476+
} else if this.check_keyword(kw::Const) {
1477+
this.parse_const_block(lo.to(this.token.span), false)
14781478
} else if this.may_recover() && this.is_do_catch_block() {
14791479
this.recover_do_catch()
14801480
} else if this.is_try_block() {

compiler/rustc_parse/src/parser/mod.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1314,11 +1314,12 @@ impl<'a> Parser<'a> {
13141314
}
13151315
}
13161316

1317-
/// Parses inline const expressions. The `const` keyword was already eaten.
1317+
/// Parses inline const expressions.
13181318
fn parse_const_block(&mut self, span: Span, pat: bool) -> PResult<'a, P<Expr>> {
13191319
if pat {
13201320
self.psess.gated_spans.gate(sym::inline_const_pat, span);
13211321
}
1322+
self.expect_keyword(kw::Const)?;
13221323
let (attrs, blk) = self.parse_inner_attrs_and_block()?;
13231324
let anon_const = AnonConst {
13241325
id: DUMMY_NODE_ID,

compiler/rustc_parse/src/parser/pat.rs

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

740740
if let Some(re) = self.parse_range_end() {
741741
self.parse_pat_range_begin_with(const_expr, re)?
@@ -1225,9 +1225,7 @@ impl<'a> Parser<'a> {
12251225
.then_some(self.prev_token.span);
12261226

12271227
let bound = if self.check_inline_const(0) {
1228-
let _eaten = self.eat_keyword(kw::Const);
1229-
debug_assert!(_eaten);
1230-
self.parse_const_block(self.prev_token.span, true)
1228+
self.parse_const_block(self.token.span, true)
12311229
} else if self.check_path() {
12321230
let lo = self.token.span;
12331231
let (qself, path) = if self.eat_lt() {

0 commit comments

Comments
 (0)