about summary refs log tree commit diff
path: root/src/librustc_parse/parser
diff options
context:
space:
mode:
authorMazdak Farrokhzad <twingoow@gmail.com>2019-12-08 10:04:31 +0100
committerMazdak Farrokhzad <twingoow@gmail.com>2019-12-21 19:20:41 +0100
commitfd89104966d6ea6a1bbc14d697b9197f06614d12 (patch)
tree8afdd9545eb0395a725bf9a3f819f234664d20b8 /src/librustc_parse/parser
parente61cb44f2f55a79562d1c714b42620c81c962d5d (diff)
downloadrust-fd89104966d6ea6a1bbc14d697b9197f06614d12.tar.gz
rust-fd89104966d6ea6a1bbc14d697b9197f06614d12.zip
extract can_begin_bound
Diffstat (limited to 'src/librustc_parse/parser')
-rw-r--r--src/librustc_parse/parser/ty.rs25
1 files changed, 12 insertions, 13 deletions
diff --git a/src/librustc_parse/parser/ty.rs b/src/librustc_parse/parser/ty.rs
index b58c16c78e6..ca8dd62cc6a 100644
--- a/src/librustc_parse/parser/ty.rs
+++ b/src/librustc_parse/parser/ty.rs
@@ -367,19 +367,7 @@ impl<'a> Parser<'a> {
         let mut negative_bounds = Vec::new();
         let mut last_plus_span = None;
         let mut was_negative = false;
-        loop {
-            // This needs to be synchronized with `TokenKind::can_begin_bound`.
-            let is_bound_start = self.check_path()
-                || self.check_lifetime()
-                || self.check(&token::Not) // Used for error reporting only.
-                || self.check(&token::Question)
-                || self.check_keyword(kw::For)
-                || self.check(&token::OpenDelim(token::Paren));
-
-            if !is_bound_start {
-                break;
-            }
-
+        while self.can_begin_bound() {
             let lo = self.token.span;
             let has_parens = self.eat(&token::OpenDelim(token::Paren));
             let inner_lo = self.token.span;
@@ -456,6 +444,17 @@ impl<'a> Parser<'a> {
         return Ok(bounds);
     }
 
+    /// Can the current token begin a bound?
+    fn can_begin_bound(&mut self) -> bool {
+        // This needs to be synchronized with `TokenKind::can_begin_bound`.
+        self.check_path()
+        || self.check_lifetime()
+        || self.check(&token::Not) // Used for error reporting only.
+        || self.check(&token::Question)
+        || self.check_keyword(kw::For)
+        || self.check(&token::OpenDelim(token::Paren))
+    }
+
     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")