]> git.lizzy.rs Git - rust.git/commitdiff
extract parse_generic_lt_bound
authorMazdak Farrokhzad <twingoow@gmail.com>
Sun, 8 Dec 2019 10:28:57 +0000 (11:28 +0100)
committerMazdak Farrokhzad <twingoow@gmail.com>
Sat, 21 Dec 2019 18:20:41 +0000 (19:20 +0100)
src/librustc_parse/parser/ty.rs

index a5ce46e9700f9e16324ae49768bb6f41002129df..905bc204b5156ccebd94edf31c5f9983d0e0293d 100644 (file)
@@ -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<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 @@ 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<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")