Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Syn data structures do not implement std::fmt::debug #583

Closed
dutchmartin opened this issue Feb 24, 2019 · 2 comments
Closed

Syn data structures do not implement std::fmt::debug #583

dutchmartin opened this issue Feb 24, 2019 · 2 comments

Comments

@dutchmartin
Copy link

While trying to build a new procedural macro, I wanted to see what data I was working with, so I tried to use the debug macro and the print line macro, but this does not compile (rust 1.32) since the Debug trait is not implemented.
For reference, see the code below:

extern crate proc_macro;

use proc_macro::TokenStream;
use quote::quote;
use syn::{parse_macro_input, DeriveInput};


#[proc_macro_derive(do_stuff)]
pub fn do_stuff(input: TokenStream) -> TokenStream {
// Parse the input tokens into a syntax tree
    let input = parse_macro_input!(input as DeriveInput);

    let name = &input.ident;
    // this line below does not compile.
    dbg!(input);

    let expanded = quote! {
        impl #name {
            pub fn do_some_stuff()  {
                println!("macro fn executed");
            }
        }
        };

    TokenStream::from(expanded)
}

Looking at the declaration of the struct, it should have been added since the ast_struct macro Adds the debug derive. So I am clueless what causes this.

TLDR: syn::derive::DeriveInput cannot be formatted using {:?} because it doesn't implement `std::fmt::Debug``
@Dushistov
Copy link

Look at README, optional features sections, you should enable "extra-traits" feature.

@dtolnay
Copy link
Owner

dtolnay commented Feb 24, 2019

The "extra-traits" cfg exposes the Debug impl. The feature is off by default because having all those impls increases compile time quite substantially, so you would normally only want it during debugging.

From your second link:

#[cfg_attr(feature = "extra-traits", derive(Debug, Eq, PartialEq, Hash))]

the derive(Debug) only applies if "extra-traits" is enabled.

@dtolnay dtolnay closed this as completed Feb 24, 2019
onelson added a commit to onelson/typescript-definitions that referenced this issue Dec 2, 2019
Build fails since syn::Type only adds an impl for Debug when
"extra-traits" feature is enabled. This exposes a feature on
typescript-definitions-derive to control whether or not syn's feature is
active, and adds a cfg_attr to the derive on `Attrs`.

- <dtolnay/syn#583 (comment)>
attente pushed a commit to arilotter/typescript-definitions that referenced this issue Mar 6, 2020
Build fails since syn::Type only adds an impl for Debug when
"extra-traits" feature is enabled. This exposes a feature on
typescript-definitions-derive to control whether or not syn's feature is
active, and adds a cfg_attr to the derive on `Attrs`.

- <dtolnay/syn#583 (comment)>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants