diff options
| author | Deadbeef <ent3rm4n@gmail.com> | 2025-08-04 09:41:55 +0000 |
|---|---|---|
| committer | Deadbeef <ent3rm4n@gmail.com> | 2025-08-22 12:58:37 +0800 |
| commit | 1e5b5ba1e732d557f00a3cd79150990370c7db0a (patch) | |
| tree | 0094fcd842a287252c2c70d4acd30bdfda246ead /compiler/rustc_ast | |
| parent | 8e3710ef31a0b2cdf5a1c2f3929b7735d1e28c20 (diff) | |
| download | rust-1e5b5ba1e732d557f00a3cd79150990370c7db0a.tar.gz rust-1e5b5ba1e732d557f00a3cd79150990370c7db0a.zip | |
print raw lifetime idents with `r#`
Diffstat (limited to 'compiler/rustc_ast')
| -rw-r--r-- | compiler/rustc_ast/src/token.rs | 22 |
1 files changed, 16 insertions, 6 deletions
diff --git a/compiler/rustc_ast/src/token.rs b/compiler/rustc_ast/src/token.rs index fc816f2cb79..ea98bebd305 100644 --- a/compiler/rustc_ast/src/token.rs +++ b/compiler/rustc_ast/src/token.rs @@ -7,6 +7,7 @@ pub use NtPatKind::*; pub use TokenKind::*; use rustc_macros::{Decodable, Encodable, HashStable_Generic}; use rustc_span::edition::Edition; +use rustc_span::symbol::IdentPrintMode; use rustc_span::{DUMMY_SP, ErrorGuaranteed, Span, kw, sym}; #[allow(clippy::useless_attribute)] // FIXME: following use of `hidden_glob_reexports` incorrectly triggers `useless_attribute` lint. #[allow(hidden_glob_reexports)] @@ -344,15 +345,24 @@ pub enum IdentIsRaw { Yes, } -impl From<bool> for IdentIsRaw { - fn from(b: bool) -> Self { - if b { Self::Yes } else { Self::No } +impl IdentIsRaw { + pub fn to_print_mode_ident(self) -> IdentPrintMode { + match self { + IdentIsRaw::No => IdentPrintMode::Normal, + IdentIsRaw::Yes => IdentPrintMode::RawIdent, + } + } + pub fn to_print_mode_lifetime(self) -> IdentPrintMode { + match self { + IdentIsRaw::No => IdentPrintMode::Normal, + IdentIsRaw::Yes => IdentPrintMode::RawLifetime, + } } } -impl From<IdentIsRaw> for bool { - fn from(is_raw: IdentIsRaw) -> bool { - matches!(is_raw, IdentIsRaw::Yes) +impl From<bool> for IdentIsRaw { + fn from(b: bool) -> Self { + if b { Self::Yes } else { Self::No } } } |
