Skip to content

Commit 18f4cb1

Browse files
committed
Extract const boundness parsing out into a method
1 parent 99b18d6 commit 18f4cb1

File tree

1 file changed

+16
-12
lines changed
  • compiler/rustc_parse/src/parser

1 file changed

+16
-12
lines changed

compiler/rustc_parse/src/parser/ty.rs

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -995,18 +995,7 @@ impl<'a> Parser<'a> {
995995
/// See `parse_generic_ty_bound` for the complete grammar of trait bound modifiers.
996996
fn parse_trait_bound_modifiers(&mut self) -> PResult<'a, TraitBoundModifiers> {
997997
let modifier_lo = self.token.span;
998-
let constness = if self.eat(exp!(Tilde)) {
999-
let tilde = self.prev_token.span;
1000-
self.expect_keyword(exp!(Const))?;
1001-
let span = tilde.to(self.prev_token.span);
1002-
self.psess.gated_spans.gate(sym::const_trait_impl, span);
1003-
BoundConstness::Maybe(span)
1004-
} else if self.eat_keyword(exp!(Const)) {
1005-
self.psess.gated_spans.gate(sym::const_trait_impl, self.prev_token.span);
1006-
BoundConstness::Always(self.prev_token.span)
1007-
} else {
1008-
BoundConstness::Never
1009-
};
998+
let constness = self.parse_bound_constness()?;
1010999

10111000
let asyncness = if self.token_uninterpolated_span().at_least_rust_2018()
10121001
&& self.eat_keyword(exp!(Async))
@@ -1068,6 +1057,21 @@ impl<'a> Parser<'a> {
10681057
Ok(TraitBoundModifiers { constness, asyncness, polarity })
10691058
}
10701059

1060+
fn parse_bound_constness(&mut self) -> PResult<'a, BoundConstness> {
1061+
Ok(if self.eat(exp!(Tilde)) {
1062+
let tilde = self.prev_token.span;
1063+
self.expect_keyword(exp!(Const))?;
1064+
let span = tilde.to(self.prev_token.span);
1065+
self.psess.gated_spans.gate(sym::const_trait_impl, span);
1066+
BoundConstness::Maybe(span)
1067+
} else if self.eat_keyword(exp!(Const)) {
1068+
self.psess.gated_spans.gate(sym::const_trait_impl, self.prev_token.span);
1069+
BoundConstness::Always(self.prev_token.span)
1070+
} else {
1071+
BoundConstness::Never
1072+
})
1073+
}
1074+
10711075
/// Parses a type bound according to:
10721076
/// ```ebnf
10731077
/// TY_BOUND = TY_BOUND_NOPAREN | (TY_BOUND_NOPAREN)

0 commit comments

Comments
 (0)