diff options
| author | Mazdak Farrokhzad <twingoow@gmail.com> | 2019-12-08 11:28:57 +0100 |
|---|---|---|
| committer | Mazdak Farrokhzad <twingoow@gmail.com> | 2019-12-21 19:20:41 +0100 |
| commit | 4b073a1f4a61e69ed08ad116f5d545d4c553d235 (patch) | |
| tree | 04892b3c4fc91c2b63694f4d7a1cefd021624860 | |
| parent | 50e00c73ee7efee610fa1dfca85155f3ce81b91e (diff) | |
extract parse_generic_lt_bound
| -rw-r--r-- | src/librustc_parse/parser/ty.rs | 32 |
1 files 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 @@ impl<'a> Parser<'a> { } /// 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 @@ impl<'a> Parser<'a> { 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<GenericBound>)`? - 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 @@ impl<'a> Parser<'a> { } } + /// 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<Span>, + ) -> 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<GenericBound>)`? + self.recover_paren_lifetime(lo, inner_lo)?; + } + Ok(bound) + } + fn error_opt_out_lifetime(&self, question: Option<Span>) { if let Some(span) = question { self.struct_span_err(span, "`?` may only modify trait bounds, not lifetime bounds") |
