From cc65053651b82c8317d71fdfa907efe6f6efbc19 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Sat, 4 Sep 2021 18:27:47 -0700 Subject: [PATCH] Implied bounds for the remaining std::fmt traits --- impl/src/attr.rs | 15 ++++++++++----- impl/src/fmt.rs | 7 +++++++ 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/impl/src/attr.rs b/impl/src/attr.rs index 9793586..9963fd6 100644 --- a/impl/src/attr.rs +++ b/impl/src/attr.rs @@ -31,10 +31,17 @@ pub struct Transparent<'a> { pub span: Span, } -#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd)] +#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Debug)] pub enum Trait { Debug, Display, + Octal, + LowerHex, + UpperHex, + Pointer, + Binary, + LowerExp, + UpperExp, } pub fn get(input: &[Attribute]) -> Result { @@ -200,9 +207,7 @@ impl ToTokens for Display<'_> { impl ToTokens for Trait { fn to_tokens(&self, tokens: &mut TokenStream) { - tokens.extend(match self { - Trait::Debug => quote!(std::fmt::Debug), - Trait::Display => quote!(std::fmt::Display), - }); + let trait_name = format_ident!("{}", format!("{:?}", self)); + tokens.extend(quote!(std::fmt::#trait_name)); } } diff --git a/impl/src/fmt.rs b/impl/src/fmt.rs index f214ec8..65555db 100644 --- a/impl/src/fmt.rs +++ b/impl/src/fmt.rs @@ -93,6 +93,13 @@ impl Display<'_> { }; let bound = match read[..end_spec].chars().next_back() { Some('?') => Trait::Debug, + Some('o') => Trait::Octal, + Some('x') => Trait::LowerHex, + Some('X') => Trait::UpperHex, + Some('p') => Trait::Pointer, + Some('b') => Trait::Binary, + Some('e') => Trait::LowerExp, + Some('E') => Trait::UpperExp, Some(_) => Trait::Display, None => { has_bonus_display = true;