diff options
Diffstat (limited to 'compiler')
| -rw-r--r-- | compiler/rustc_parse/src/parser/ty.rs | 28 |
1 files changed, 16 insertions, 12 deletions
diff --git a/compiler/rustc_parse/src/parser/ty.rs b/compiler/rustc_parse/src/parser/ty.rs index 620a34044d1..aa51b550426 100644 --- a/compiler/rustc_parse/src/parser/ty.rs +++ b/compiler/rustc_parse/src/parser/ty.rs @@ -995,18 +995,7 @@ impl<'a> Parser<'a> { /// See `parse_generic_ty_bound` for the complete grammar of trait bound modifiers. fn parse_trait_bound_modifiers(&mut self) -> PResult<'a, TraitBoundModifiers> { let modifier_lo = self.token.span; - let constness = if self.eat(exp!(Tilde)) { - let tilde = self.prev_token.span; - self.expect_keyword(exp!(Const))?; - let span = tilde.to(self.prev_token.span); - self.psess.gated_spans.gate(sym::const_trait_impl, span); - BoundConstness::Maybe(span) - } else if self.eat_keyword(exp!(Const)) { - self.psess.gated_spans.gate(sym::const_trait_impl, self.prev_token.span); - BoundConstness::Always(self.prev_token.span) - } else { - BoundConstness::Never - }; + let constness = self.parse_bound_constness()?; let asyncness = if self.token_uninterpolated_span().at_least_rust_2018() && self.eat_keyword(exp!(Async)) @@ -1068,6 +1057,21 @@ impl<'a> Parser<'a> { Ok(TraitBoundModifiers { constness, asyncness, polarity }) } + fn parse_bound_constness(&mut self) -> PResult<'a, BoundConstness> { + Ok(if self.eat(exp!(Tilde)) { + let tilde = self.prev_token.span; + self.expect_keyword(exp!(Const))?; + let span = tilde.to(self.prev_token.span); + self.psess.gated_spans.gate(sym::const_trait_impl, span); + BoundConstness::Maybe(span) + } else if self.eat_keyword(exp!(Const)) { + self.psess.gated_spans.gate(sym::const_trait_impl, self.prev_token.span); + BoundConstness::Always(self.prev_token.span) + } else { + BoundConstness::Never + }) + } + /// Parses a type bound according to: /// ```ebnf /// TY_BOUND = TY_BOUND_NOPAREN | (TY_BOUND_NOPAREN) |
