Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
ArthurZucker committed Jun 12, 2024
1 parent 5c930e9 commit f87bb97
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 16 deletions.
25 changes: 13 additions & 12 deletions tokenizers/display_derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<FmtAttribute>(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! {

Check failure on line 28 in tokenizers/display_derive/src/lib.rs

View workflow job for this annotation

GitHub Actions / Check it builds for Windows 32-bit (3.8)

the trait bound `Result<(Vec<WherePredicate>, proc_macro::TokenStream), syn::Error>: ToTokens` is not satisfied

Check failure on line 28 in tokenizers/display_derive/src/lib.rs

View workflow job for this annotation

GitHub Actions / Check it builds for Windows 32-bit (3.10)

the trait bound `Result<(Vec<WherePredicate>, proc_macro::TokenStream), syn::Error>: ToTokens` is not satisfied

Check failure on line 28 in tokenizers/display_derive/src/lib.rs

View workflow job for this annotation

GitHub Actions / Check it builds for Windows 32-bit (3.7)

the trait bound `Result<(Vec<WherePredicate>, proc_macro::TokenStream), syn::Error>: ToTokens` is not satisfied

Check failure on line 28 in tokenizers/display_derive/src/lib.rs

View workflow job for this annotation

GitHub Actions / Check it builds for Windows 32-bit (3.9)

the trait bound `Result<(Vec<WherePredicate>, proc_macro::TokenStream), syn::Error>: ToTokens` is not satisfied
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:
Expand Down
4 changes: 0 additions & 4 deletions tokenizers/display_derive/src/vendored.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ use syn::{
/// ```
///
/// [`fmt`]: std::fmt
#[derive(Debug)]
pub struct FmtAttribute {
/// Interpolation [`syn::LitStr`].
///
Expand All @@ -33,7 +32,6 @@ pub struct FmtAttribute {

impl Parse for FmtAttribute {
fn parse(input: ParseStream<'_>) -> syn::Result<Self> {
Self::check_legacy_fmt(input)?;

Ok(Self {
lit: input.parse()?,
Expand All @@ -46,7 +44,6 @@ impl Parse for FmtAttribute {
}
}

impl attr::ParseMultiple for FmtAttribute {}

impl ToTokens for FmtAttribute {
fn to_tokens(&self, tokens: &mut TokenStream) {
Expand Down Expand Up @@ -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`].
///
Expand Down

0 comments on commit f87bb97

Please sign in to comment.