arabidopsis / typescript-definitions

Apache License 2.0
69 stars 19 forks source link

error: proc-macro derive produced unparseable tokens #4

Open masonk opened 4 years ago

masonk commented 4 years ago

This is a cool project. Thanks for releasing it! I am getting an error in typescript.rs:40.

I can trigger this with a very simple main.rs:

use serde::{Deserialize, Serialize};
use typescript_definitions::{TypeScriptify, TypeScriptifyTrait};

fn main() {
    #[derive(Debug, Serialize, Deserialize, TypeScriptify)]
    struct Foo {
        num: i64,
    }

    println!("{}", Foo::type_script_ify());
}
error: proc-macro derive produced unparseable tokens
  --> /home/mason/.cargo/registry/src/github.com-1ecc6299db9ec823/typescript-definitions-derive-0.1.10/src/typescript.rs:40:10
   |
$ rustup show
Default host: x86_64-unknown-linux-gnu
rustup home:  /home/mason/.rustup

nightly-x86_64-unknown-linux-gnu (default)
rustc 1.41.0-nightly (412f43ac5 2019-11-24)
onelson commented 4 years ago

Seems to be related to pest-parser/pest#427 (it is not related to this, not in the least).

onelson commented 4 years ago

Looking closer, it was suggested the issue reported to pest was caused by ambigious module names (which is not the case here as far as I can tell). Just to rule it out, I fussed with the use statements and the path in the derive attribute itself to no avail. I'm not exactly sure what the issue is.

onelson commented 4 years ago

I still don't have any real solutions, but what I see in master right now.

I can get the crate to build...

diff --git a/typescript-definitions-derive/src/attrs.rs b/typescript-definitions-derive/src/attrs.rs
index 83a6867..43b3546 100644
--- a/typescript-definitions-derive/src/attrs.rs
+++ b/typescript-definitions-derive/src/attrs.rs
@@ -12,7 +12,6 @@ use quote::quote;
 use proc_macro2::TokenStream;
 use syn::{Attribute, Ident, Lit, Meta, /* MetaList,*/ MetaNameValue, NestedMeta};

-#[derive(Debug)]
 pub struct Attrs {
     pub comments: Vec<String>,
     pub guard: bool,

The removal of the derived Debug trait is needed since apparently syn::Type does not implement Debug.

CAD97 commented 4 years ago

Short-term fix: rename the union rule.

I'm looking into what changed and will report a bug to upstream rust for this changed behavior.

onelson commented 4 years ago

Thanks @CAD97. I'll keep my toolchain pinned for now and track the upstream bug on rust for progress. Probably doesn't make much sense to patch around this immediately if holding the toolchain back is enough for now.

onelson commented 4 years ago

Looks like the "unparsable tokens" issue should be fixed as of 2 days ago since rust-lang/rust#66943 has been merged through. We should be able to track nightly freely once more.