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

0.3.0 doesn't support macro invocation in default values #4

Closed
cbiffle opened this issue Feb 18, 2019 · 6 comments
Closed

0.3.0 doesn't support macro invocation in default values #4

cbiffle opened this issue Feb 18, 2019 · 6 comments

Comments

@cbiffle
Copy link

cbiffle commented Feb 18, 2019

I have some code using 0.2.0 that does things like this:

#[derive(SmartDefault)]
struct Test {
    #[default = "vec![0; 100]"]
    field: Vec<u32>,
}

In 0.3.0 this fails to parse with either syntax:

#[derive(SmartDefault)]
struct Test {
    #[default(vec![0; 100])]
    field: Vec<u32>,
    // unexpected token: !
}
#[derive(SmartDefault)]
struct Test2 {
    #[default = vec![0; 100]]
    field: Vec<u32>,
    // expected ']', found '!'
}

This is preventing me from upgrading my codebase from 0.2.0 -- which isn't a huge deal, since 0.2.0 works fine, but it's adding a dependency on old versions of syn/quote so I'd like to upgrade.

@idanarye
Copy link
Owner

which isn't a huge deal

It is actually - 0.2.0 uses an older version of syn that does not support Rust 2018, so you can't have Rust 2018 syntax in your struct.

To support macro invocation with the new style, I'll need the still unstable unrestricted_attribute_tokens feature. Using it with the feature gate doesn't currently work, but it does work if I change the syn features to "full" - so that's an easy fix. Still - I don't want to have this available only on nightly...

I can add the string version as a special argument. How about this?

    #[default(_txt = "vec![0; 100]")]
    field: Vec<u32>,

@cbiffle
Copy link
Author

cbiffle commented Feb 18, 2019

Good point! That syntax would cover my use case. I'd suggest code or _code for the name to make its purpose more obvious.

@cbiffle
Copy link
Author

cbiffle commented Feb 18, 2019

Fantastic! Thank you!

@idanarye
Copy link
Owner

Wait - I just pushed to commit, but I did not upload the version to crates.io yet. I'm waiting for the Travis build to finish.

@cbiffle
Copy link
Author

cbiffle commented Feb 18, 2019

Understood -- the "thank you" was for working on it so swiftly. :-)

@idanarye
Copy link
Owner

@cbiffle OK, it's uploaded. Upgrade to 0.4.0 and you are good to go.

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

2 participants