diff options
| author | Nicholas Nethercote <n.nethercote@gmail.com> | 2024-06-13 13:52:20 +1000 |
|---|---|---|
| committer | Nicholas Nethercote <n.nethercote@gmail.com> | 2024-06-20 04:50:40 +1000 |
| commit | c6f78270b66b2ffc78742006445df76105b7d558 (patch) | |
| tree | 724238e1977144f0c98be6629b94cd794f14390a /compiler/rustc_ast/src/token.rs | |
| parent | 7d9a92ba31122950f2c7f6a71ad6dee49b3e95e4 (diff) | |
| download | rust-c6f78270b66b2ffc78742006445df76105b7d558.tar.gz rust-c6f78270b66b2ffc78742006445df76105b7d558.zip | |
Introduce `can_begin_string_literal`.
We currently use `can_begin_literal_maybe_minus` in a couple of places where only string literals are allowed. This commit introduces a more specific function, which makes things clearer. It doesn't change behaviour because the two functions affected (`is_unsafe_foreign_mod` and `check_keyword_case`) are always followed by a call to `parse_abi`, which checks again for a string literal.
Diffstat (limited to 'compiler/rustc_ast/src/token.rs')
| -rw-r--r-- | compiler/rustc_ast/src/token.rs | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/compiler/rustc_ast/src/token.rs b/compiler/rustc_ast/src/token.rs index 4d513797f5f..4dc41a02cb8 100644 --- a/compiler/rustc_ast/src/token.rs +++ b/compiler/rustc_ast/src/token.rs @@ -621,6 +621,21 @@ impl Token { } } + pub fn can_begin_string_literal(&self) -> bool { + match self.uninterpolate().kind { + Literal(..) => true, + Interpolated(ref nt) => match &**nt { + NtLiteral(_) => true, + NtExpr(e) => match &e.kind { + ast::ExprKind::Lit(_) => true, + _ => false, + }, + _ => false, + }, + _ => false, + } + } + /// A convenience function for matching on identifiers during parsing. /// Turns interpolated identifier (`$i: ident`) or lifetime (`$l: lifetime`) token /// into the regular identifier or lifetime token it refers to, |
