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
}
}
+ /// 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 {
})
}
+ /// 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()