about summary refs log tree commit diff
path: root/src/libsyntax/parse
diff options
context:
space:
mode:
authorCrazycolorz5 <Crazycolorz5@gmail.com>2018-05-25 16:40:16 -0400
committerCrazycolorz5 <Crazycolorz5@gmail.com>2018-06-04 22:25:00 -0400
commit682033c4e47cf0cca5b4b96b07123da8807254f6 (patch)
treece414ce38f8136937eb28d2057f06871921f25da /src/libsyntax/parse
parentc610be92e2925ab8e789efc835c88247e46c6cbf (diff)
downloadrust-682033c4e47cf0cca5b4b96b07123da8807254f6.tar.gz
rust-682033c4e47cf0cca5b4b96b07123da8807254f6.zip
Implemented eat_plus and used it in parsing parse_ty_param_bounds_common.
Diffstat (limited to 'src/libsyntax/parse')
-rw-r--r--src/libsyntax/parse/parser.rs23
1 files changed, 22 insertions, 1 deletions
diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs
index 28f93328e95..a4e2b96c5f9 100644
--- a/src/libsyntax/parse/parser.rs
+++ b/src/libsyntax/parse/parser.rs
@@ -880,6 +880,27 @@ impl<'a> Parser<'a> {
             false
         }
     }
+    
+    /// Expect and consume a `+`. if `+=` is seen, replace it with a `=`
+    /// and continue. If a `+` is not seen, return false.
+    ///
+    /// This is using when token splitting += into +. 
+    /// See issue 47856 for an example of when this may occur.
+    fn eat_plus(&mut self) -> bool {
+        self.expected_tokens.push(TokenType::Token(token::BinOp(token::Plus)));
+        match self.token {
+            token::BinOp(token::Plus) => {
+                self.bump();
+                true
+            }
+            token::BinOpEq(token::Plus) => {
+                let span = self.span.with_lo(self.span.lo() + BytePos(1));
+                self.bump_with(token::Eq, span);
+                true
+            }
+            _ => false,
+        }
+    }
 
     /// Expect and consume an `&`. If `&&` is seen, replace it with a single
     /// `&` and continue. If an `&` is not seen, signal an error.
@@ -4801,7 +4822,7 @@ impl<'a> Parser<'a> {
                 break
             }
 
-            if !allow_plus || !self.eat(&token::BinOp(token::Plus)) {
+            if !allow_plus || !self.eat_plus() {
                 break
             }
         }