From 9eb1f7eb29d73989a41018e24e9a19e593e97749 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Tue, 25 Aug 2026 09:46:45 +0000 Subject: [PATCH] Refactor `fmt::Display` for TokenKind, LiteralKind, and NumericLiteralKind to use `fmt::Debug::fmt`. Replaces manual match statements for format display fallback implementations with delegation to `fmt::Debug::fmt`, saving boilerplate and removing typo-prone large enums mappings in `compiler/syntax/src/token_kind.rs`. Co-authored-by: Tcode-Motion <188012755+Tcode-Motion@users.noreply.github.com> --- compiler/syntax/src/token_kind.rs | 30 +++--------------------------- 1 file changed, 3 insertions(+), 27 deletions(-) diff --git a/compiler/syntax/src/token_kind.rs b/compiler/syntax/src/token_kind.rs index f4a1c54a..1092b8e8 100644 --- a/compiler/syntax/src/token_kind.rs +++ b/compiler/syntax/src/token_kind.rs @@ -21,14 +21,7 @@ pub enum LiteralKind { impl fmt::Display for LiteralKind { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - let label = match self { - LiteralKind::Int => "Int", - LiteralKind::Float => "Float", - LiteralKind::Str => "Str", - LiteralKind::Bool => "Bool", - LiteralKind::Null => "Null", - }; - write!(f, "{}", label) + fmt::Debug::fmt(self, f) } } @@ -47,13 +40,7 @@ pub enum NumericLiteralKind { impl fmt::Display for NumericLiteralKind { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - let label = match self { - NumericLiteralKind::Decimal => "Decimal", - NumericLiteralKind::Hex => "Hex", - NumericLiteralKind::Binary => "Binary", - NumericLiteralKind::Octal => "Octal", - }; - write!(f, "{}", label) + fmt::Debug::fmt(self, f) } } @@ -791,18 +778,7 @@ impl fmt::Display for TokenKind { if let Some(lexeme) = self.static_lexeme() { write!(f, "'{}'", lexeme) } else { - let label = match self { - TokenKind::Identifier => "Identifier", - TokenKind::IntLiteral => "Integer Literal", - TokenKind::FloatLiteral => "Float Literal", - TokenKind::StringLiteral => "String Literal", - TokenKind::FStringText => "f-string segment", - TokenKind::Newline => "Newline", - TokenKind::Eof => "EOF", - TokenKind::Error => "Error", - _ => "Unknown Token", - }; - write!(f, "{}", label) + fmt::Debug::fmt(self, f) } } }