summaryrefslogtreecommitdiffstats
path: root/compiler/rustc_ast/src/token.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-07 05:48:48 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-07 05:48:48 +0000
commitef24de24a82fe681581cc130f342363c47c0969a (patch)
tree0d494f7e1a38b95c92426f58fe6eaa877303a86c /compiler/rustc_ast/src/token.rs
parentReleasing progress-linux version 1.74.1+dfsg1-1~progress7.99u1. (diff)
downloadrustc-ef24de24a82fe681581cc130f342363c47c0969a.tar.xz
rustc-ef24de24a82fe681581cc130f342363c47c0969a.zip
Merging upstream version 1.75.0+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'compiler/rustc_ast/src/token.rs')
-rw-r--r--compiler/rustc_ast/src/token.rs46
1 files changed, 38 insertions, 8 deletions
diff --git a/compiler/rustc_ast/src/token.rs b/compiler/rustc_ast/src/token.rs
index 300b1486f..914c97a14 100644
--- a/compiler/rustc_ast/src/token.rs
+++ b/compiler/rustc_ast/src/token.rs
@@ -107,13 +107,11 @@ impl Lit {
/// Keep this in sync with `Token::can_begin_literal_or_bool` excluding unary negation.
pub fn from_token(token: &Token) -> Option<Lit> {
match token.uninterpolate().kind {
- Ident(name, false) if name.is_bool_lit() => {
- Some(Lit::new(Bool, name, None))
- }
+ Ident(name, false) if name.is_bool_lit() => Some(Lit::new(Bool, name, None)),
Literal(token_lit) => Some(token_lit),
Interpolated(ref nt)
if let NtExpr(expr) | NtLiteral(expr) = &**nt
- && let ast::ExprKind::Lit(token_lit) = expr.kind =>
+ && let ast::ExprKind::Lit(token_lit) = expr.kind =>
{
Some(token_lit)
}
@@ -199,6 +197,7 @@ pub fn ident_can_begin_expr(name: Symbol, span: Span, is_raw: bool) -> bool {
kw::Continue,
kw::False,
kw::For,
+ kw::Gen,
kw::If,
kw::Let,
kw::Loop,
@@ -229,35 +228,61 @@ fn ident_can_begin_type(name: Symbol, span: Span, is_raw: bool) -> bool {
#[derive(PartialEq, Encodable, Decodable, Debug, HashStable_Generic)]
pub enum TokenKind {
/* Expression-operator symbols. */
+ /// `=`
Eq,
+ /// `<`
Lt,
+ /// `<=`
Le,
+ /// `==`
EqEq,
+ /// `!=`
Ne,
+ /// `>`
Ge,
+ /// `>=`
Gt,
+ /// `&&`
AndAnd,
+ /// `||`
OrOr,
+ /// `!`
Not,
+ /// `~`
Tilde,
BinOp(BinOpToken),
BinOpEq(BinOpToken),
/* Structural symbols */
+ /// `@`
At,
+ /// `.`
Dot,
+ /// `..`
DotDot,
+ /// `...`
DotDotDot,
+ /// `..=`
DotDotEq,
+ /// `,`
Comma,
+ /// `;`
Semi,
+ /// `:`
Colon,
+ /// `::`
ModSep,
+ /// `->`
RArrow,
+ /// `<-`
LArrow,
+ /// `=>`
FatArrow,
+ /// `#`
Pound,
+ /// `$`
Dollar,
+ /// `?`
Question,
/// Used by proc macros for representing lifetimes, not generated by lexer right now.
SingleQuote,
@@ -296,6 +321,7 @@ pub enum TokenKind {
/// similarly to symbols in string literal tokens.
DocComment(CommentKind, ast::AttrStyle, Symbol),
+ /// End Of File
Eof,
}
@@ -404,7 +430,7 @@ impl Token {
[DotDot, DotDotDot, DotDotEq].contains(&self.kind)
}
- pub fn is_op(&self) -> bool {
+ pub fn is_punct(&self) -> bool {
match self.kind {
Eq | Lt | Le | EqEq | Ne | Ge | Gt | AndAnd | OrOr | Not | Tilde | BinOp(_)
| BinOpEq(_) | At | Dot | DotDot | DotDotDot | DotDotEq | Comma | Semi | Colon
@@ -446,7 +472,7 @@ impl Token {
}
}
- /// Returns `true` if the token can appear at the start of an pattern.
+ /// Returns `true` if the token can appear at the start of a pattern.
///
/// Shamelessly borrowed from `can_begin_expr`, only used for diagnostics right now.
pub fn can_begin_pattern(&self) -> bool {
@@ -628,7 +654,9 @@ impl Token {
/// Returns `true` if the token is an interpolated path.
fn is_path(&self) -> bool {
- if let Interpolated(nt) = &self.kind && let NtPath(..) = **nt {
+ if let Interpolated(nt) = &self.kind
+ && let NtPath(..) = **nt
+ {
return true;
}
@@ -650,7 +678,9 @@ impl Token {
/// Is the token an interpolated block (`$b:block`)?
pub fn is_whole_block(&self) -> bool {
- if let Interpolated(nt) = &self.kind && let NtBlock(..) = **nt {
+ if let Interpolated(nt) = &self.kind
+ && let NtBlock(..) = **nt
+ {
return true;
}