]> git.proxmox.com Git - rustc.git/blobdiff - src/libsyntax/parse/token.rs
New upstream version 1.23.0+dfsg1
[rustc.git] / src / libsyntax / parse / token.rs
index 4888654fac9d0ed09c9454ee6f23b92731757b40..f83343bf9afa51fe1785c2a0163699e3cc157467 100644 (file)
@@ -222,8 +222,8 @@ impl Token {
             BinOp(Or) | OrOr                  | // closure
             BinOp(And)                        | // reference
             AndAnd                            | // double reference
+            // DotDotDot is no longer supported, but we need some way to display the error
             DotDot | DotDotDot | DotDotEq     | // range notation
-                // SNAP remove DotDotDot
             Lt | BinOp(Shl)                   | // associated path
             ModSep                            | // global path
             Pound                             => true, // expression attributes
@@ -258,6 +258,12 @@ impl Token {
         }
     }
 
+    /// Returns `true` if the token can appear at the start of a generic bound.
+    pub fn can_begin_bound(&self) -> bool {
+        self.is_path_start() || self.is_lifetime() || self.is_keyword(keywords::For) ||
+        self == &Question || self == &OpenDelim(Paren)
+    }
+
     /// Returns `true` if the token is any literal
     pub fn is_lit(&self) -> bool {
         match *self {
@@ -427,6 +433,16 @@ impl Token {
         })
     }
 
+    /// Returns tokens that are likely to be typed accidentally instead of the current token.
+    /// Enables better error recovery when the wrong token is found.
+    pub fn similar_tokens(&self) -> Option<Vec<Token>> {
+        match *self {
+            Comma => Some(vec![Dot, Lt]),
+            Semi => Some(vec![Colon]),
+            _ => None
+        }
+    }
+
     /// Returns `true` if the token is either a special identifier or a keyword.
     pub fn is_reserved_ident(&self) -> bool {
         self.is_special_ident() || self.is_used_keyword() || self.is_unused_keyword()