From f87bb97e0e94c9fb5548cdb4c597f23a58dbd25d Mon Sep 17 00:00:00 2001 From: Arthur Zucker Date: Wed, 12 Jun 2024 11:53:32 +0200 Subject: [PATCH] update --- tokenizers/display_derive/src/lib.rs | 25 ++++++++++++----------- tokenizers/display_derive/src/vendored.rs | 4 ---- 2 files changed, 13 insertions(+), 16 deletions(-) diff --git a/tokenizers/display_derive/src/lib.rs b/tokenizers/display_derive/src/lib.rs index 4850588b1..20aaceb08 100644 --- a/tokenizers/display_derive/src/lib.rs +++ b/tokenizers/display_derive/src/lib.rs @@ -8,29 +8,30 @@ use vendored::FmtAttribute; #[proc_macro_derive(Display)] pub fn display_derive(input: TokenStream) -> TokenStream { - // Parse the input tokens into a syntax tree - let input = parse_macro_input!(input as DeriveInput); - return ; + // Parse the parsed_input tokens into a syntax tree + let parsed_input = parse_macro_input!(input as DeriveInput); let attr_name = "display"; - let attrs = FmtAttribute::parse_attrs(&input.attrs, &attr_name)? - .unwrap_or_default(); + let attrs = syn::parse::(input).unwrap(); let trait_ident = format_ident!("display"); - let ident = &input.ident; + let ident = &parsed_input.ident; - let ctx = (&attrs, ident, &trait_ident, &attr_name); - let body = match &input.data { + let ctx = (&attrs, ident, &trait_ident, &trait_ident); + let body = match &parsed_input.data { syn::Data::Struct(s) => expand_struct(s, ctx), syn::Data::Enum(e) => expand_enum(e, ctx), - syn::Data::Union(u) => return Err(syn::Error::new(u, format!("Union is not supported"))), - }?; + syn::Data::Union(u) => { + let error = syn::Error::new_spanned(u.union_token, "Unions are not supported"); + return proc_macro::TokenStream::from(error.into_compile_error()); + } + }; - Ok(quote! { + quote! { impl std::fmt::Display for #ident{ fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { #body } } - }) + }.into() } /// Type alias for an expansion context: diff --git a/tokenizers/display_derive/src/vendored.rs b/tokenizers/display_derive/src/vendored.rs index 9799cbf81..a1cc967f8 100644 --- a/tokenizers/display_derive/src/vendored.rs +++ b/tokenizers/display_derive/src/vendored.rs @@ -15,7 +15,6 @@ use syn::{ /// ``` /// /// [`fmt`]: std::fmt -#[derive(Debug)] pub struct FmtAttribute { /// Interpolation [`syn::LitStr`]. /// @@ -33,7 +32,6 @@ pub struct FmtAttribute { impl Parse for FmtAttribute { fn parse(input: ParseStream<'_>) -> syn::Result { - Self::check_legacy_fmt(input)?; Ok(Self { lit: input.parse()?, @@ -46,7 +44,6 @@ impl Parse for FmtAttribute { } } -impl attr::ParseMultiple for FmtAttribute {} impl ToTokens for FmtAttribute { fn to_tokens(&self, tokens: &mut TokenStream) { @@ -122,7 +119,6 @@ impl FmtAttribute { /// in a [`FmtAttribute`]. /// /// [1]: https://doc.rust-lang.org/stable/std/fmt/index.html#named-parameters -#[derive(Debug)] struct FmtArgument { /// `identifier =` [`Ident`]. ///