From f3fbd990483f43153a631604373bb9dc7e071982 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Sat, 20 Apr 2024 11:54:23 -0700 Subject: [PATCH] Implement ToTokens without reliance on {:?} --- impl/src/attr.rs | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/impl/src/attr.rs b/impl/src/attr.rs index 269c69e..395edb1 100644 --- a/impl/src/attr.rs +++ b/impl/src/attr.rs @@ -230,7 +230,18 @@ impl ToTokens for Display<'_> { impl ToTokens for Trait { fn to_tokens(&self, tokens: &mut TokenStream) { - let trait_name = format_ident!("{}", format!("{:?}", self)); - tokens.extend(quote!(::core::fmt::#trait_name)); + let trait_name = match self { + Trait::Debug => "Debug", + Trait::Display => "Display", + Trait::Octal => "Octal", + Trait::LowerHex => "LowerHex", + Trait::UpperHex => "UpperHex", + Trait::Pointer => "Pointer", + Trait::Binary => "Binary", + Trait::LowerExp => "LowerExp", + Trait::UpperExp => "UpperExp", + }; + let ident = Ident::new(trait_name, Span::call_site()); + tokens.extend(quote!(::core::fmt::#ident)); } }