Skip to content

Commit 0052157

Browse files
committed
Extract const boundness parsing out into a method
1 parent 1b8ab72 commit 0052157

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

+16-12
Original file line numberDiff line numberDiff line change
@@ -1036,18 +1036,7 @@ impl<'a> Parser<'a> {
10361036
/// See `parse_generic_ty_bound` for the complete grammar of trait bound modifiers.
10371037
fn parse_trait_bound_modifiers(&mut self) -> PResult<'a, TraitBoundModifiers> {
10381038
let modifier_lo = self.token.span;
1039-
let constness = if self.eat(exp!(Tilde)) {
1040-
let tilde = self.prev_token.span;
1041-
self.expect_keyword(exp!(Const))?;
1042-
let span = tilde.to(self.prev_token.span);
1043-
self.psess.gated_spans.gate(sym::const_trait_impl, span);
1044-
BoundConstness::Maybe(span)
1045-
} else if self.eat_keyword(exp!(Const)) {
1046-
self.psess.gated_spans.gate(sym::const_trait_impl, self.prev_token.span);
1047-
BoundConstness::Always(self.prev_token.span)
1048-
} else {
1049-
BoundConstness::Never
1050-
};
1039+
let constness = self.parse_bound_constness()?;
10511040

10521041
let asyncness = if self.token_uninterpolated_span().at_least_rust_2018()
10531042
&& self.eat_keyword(exp!(Async))
@@ -1109,6 +1098,21 @@ impl<'a> Parser<'a> {
11091098
Ok(TraitBoundModifiers { constness, asyncness, polarity })
11101099
}
11111100

1101+
fn parse_bound_constness(&mut self) -> PResult<'a, BoundConstness> {
1102+
Ok(if self.eat(exp!(Tilde)) {
1103+
let tilde = self.prev_token.span;
1104+
self.expect_keyword(exp!(Const))?;
1105+
let span = tilde.to(self.prev_token.span);
1106+
self.psess.gated_spans.gate(sym::const_trait_impl, span);
1107+
BoundConstness::Maybe(span)
1108+
} else if self.eat_keyword(exp!(Const)) {
1109+
self.psess.gated_spans.gate(sym::const_trait_impl, self.prev_token.span);
1110+
BoundConstness::Always(self.prev_token.span)
1111+
} else {
1112+
BoundConstness::Never
1113+
})
1114+
}
1115+
11121116
/// Parses a type bound according to:
11131117
/// ```ebnf
11141118
/// TY_BOUND = TY_BOUND_NOPAREN | (TY_BOUND_NOPAREN)

0 commit comments

Comments
 (0)