summaryrefslogtreecommitdiffstats
path: root/compiler/rustc_ast/src/token.rs
diff options
context:
space:
mode:
Diffstat (limited to 'compiler/rustc_ast/src/token.rs')
-rw-r--r--compiler/rustc_ast/src/token.rs20
1 files changed, 12 insertions, 8 deletions
diff --git a/compiler/rustc_ast/src/token.rs b/compiler/rustc_ast/src/token.rs
index c0cc4e79a..f947ae4d0 100644
--- a/compiler/rustc_ast/src/token.rs
+++ b/compiler/rustc_ast/src/token.rs
@@ -114,7 +114,7 @@ impl Lit {
if let NtExpr(expr) | NtLiteral(expr) = &**nt
&& let ast::ExprKind::Lit(token_lit) = expr.kind =>
{
- Some(token_lit.clone())
+ Some(token_lit)
}
_ => None,
}
@@ -125,27 +125,27 @@ impl fmt::Display for Lit {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let Lit { kind, symbol, suffix } = *self;
match kind {
- Byte => write!(f, "b'{}'", symbol)?,
- Char => write!(f, "'{}'", symbol)?,
- Str => write!(f, "\"{}\"", symbol)?,
+ Byte => write!(f, "b'{symbol}'")?,
+ Char => write!(f, "'{symbol}'")?,
+ Str => write!(f, "\"{symbol}\"")?,
StrRaw(n) => write!(
f,
"r{delim}\"{string}\"{delim}",
delim = "#".repeat(n as usize),
string = symbol
)?,
- ByteStr => write!(f, "b\"{}\"", symbol)?,
+ ByteStr => write!(f, "b\"{symbol}\"")?,
ByteStrRaw(n) => write!(
f,
"br{delim}\"{string}\"{delim}",
delim = "#".repeat(n as usize),
string = symbol
)?,
- Integer | Float | Bool | Err => write!(f, "{}", symbol)?,
+ Integer | Float | Bool | Err => write!(f, "{symbol}")?,
}
if let Some(suffix) = suffix {
- write!(f, "{}", suffix)?;
+ write!(f, "{suffix}")?;
}
Ok(())
@@ -379,6 +379,10 @@ impl Token {
}
}
+ pub fn is_range_separator(&self) -> bool {
+ [DotDot, DotDotDot, DotDotEq].contains(&self.kind)
+ }
+
pub fn is_op(&self) -> bool {
match self.kind {
Eq | Lt | Le | EqEq | Ne | Ge | Gt | AndAnd | OrOr | Not | Tilde | BinOp(_)
@@ -752,7 +756,7 @@ impl Token {
_ => return None,
},
SingleQuote => match joint.kind {
- Ident(name, false) => Lifetime(Symbol::intern(&format!("'{}", name))),
+ Ident(name, false) => Lifetime(Symbol::intern(&format!("'{name}"))),
_ => return None,
},