From 4b073a1f4a61e69ed08ad116f5d545d4c553d235 Mon Sep 17 00:00:00 2001 From: Mazdak Farrokhzad Date: Sun, 8 Dec 2019 11:28:57 +0100 Subject: [PATCH] extract parse_generic_lt_bound --- src/librustc_parse/parser/ty.rs | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/src/librustc_parse/parser/ty.rs b/src/librustc_parse/parser/ty.rs index a5ce46e9700..905bc204b51 100644 --- a/src/librustc_parse/parser/ty.rs +++ b/src/librustc_parse/parser/ty.rs @@ -427,10 +427,8 @@ fn can_begin_bound(&mut self) -> bool { } /// Parses a bound according to the grammar: - /// /// ``` /// BOUND = TY_BOUND | LT_BOUND - /// LT_BOUND = LIFETIME (e.g., `'a`) /// ``` fn parse_generic_bound( &mut self, @@ -443,14 +441,7 @@ fn parse_generic_bound( let is_negative = self.eat(&token::Not); let question = if self.eat(&token::Question) { Some(self.prev_span) } else { None }; if self.token.is_lifetime() { - self.error_opt_out_lifetime(question); - let bound = GenericBound::Outlives(self.expect_lifetime()); - if has_parens { - // FIXME(Centril): Consider not erroring here and accepting `('lt)` instead, - // possibly introducing `GenericBound::Paren(P)`? - self.recover_paren_lifetime(lo, inner_lo)?; - } - Ok(Ok(bound)) + Ok(Ok(self.parse_generic_lt_bound(lo, inner_lo, has_parens, question)?)) } else { let (poly_span, bound) = self.parse_generic_ty_bound(lo, has_parens, question)?; if is_negative { @@ -461,6 +452,27 @@ fn parse_generic_bound( } } + /// Parses a lifetime ("outlives") bound, e.g. `'a`, according to: + /// ``` + /// LT_BOUND = LIFETIME + /// ``` + fn parse_generic_lt_bound( + &mut self, + lo: Span, + inner_lo: Span, + has_parens: bool, + question: Option, + ) -> PResult<'a, GenericBound> { + self.error_opt_out_lifetime(question); + let bound = GenericBound::Outlives(self.expect_lifetime()); + if has_parens { + // FIXME(Centril): Consider not erroring here and accepting `('lt)` instead, + // possibly introducing `GenericBound::Paren(P)`? + self.recover_paren_lifetime(lo, inner_lo)?; + } + Ok(bound) + } + fn error_opt_out_lifetime(&self, question: Option) { if let Some(span) = question { self.struct_span_err(span, "`?` may only modify trait bounds, not lifetime bounds") -- 2.44.0