-
-
Notifications
You must be signed in to change notification settings - Fork 774
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
serde_codegen does not generate code for derive in cfg_attr #148
Comments
@jmesmon I just tried this and it seems to work. Can you try again and report back? Here is the code I used: #![feature(plugin, custom_derive)]
#![plugin(serde_macros)]
#[cfg(feature = "serde")]
extern crate serde;
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
struct Foo {
a: u32,
}
#[cfg(feature = "serde")]
fn main() {
println!("with serde");
fn assert<T: serde::Serialize + serde::Deserialize>(_: T) {}
assert(Foo { a: 0 });
}
#[cfg(not(feature = "serde"))]
fn main() {
println!("without serde");
} |
@dtolnay you're using I'm still able to reproduce this with Here's a project that reproduces: https://github.com/jmesmon/serde-readme |
I suspect this is the case, but we can fix it anyway, at least for the common cases. We need to transform this: #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
struct Foo { ... } ... into this: #[cfg(feature = "serde")]
impl Serialize for Foo { ... }
#[cfg(feature = "serde")]
impl Deserialize for Foo { ... }
struct Foo { ... } |
For those not watching the Syntex repo - check out the PR at serde-deprecated/syntex#71. |
Reimplement derive to work with cfg_attr Fixes serde-rs/serde#148. The implementation expands `cfg_attr` and `derive` in-line during decorator expansion rather than as pre/post-expansion passes. I think this is a simpler and more correct design, but at the expense of being more invasive into the libsyntax code.
bad homu, this isn't implemented in serde yet. |
Actually it is. 😄 That's all it took. |
Add test for expansion inside of cfg_attr Test for #148. Requires serde-deprecated/syntex#71 + Syntex release.
I have a similar problem with: #[cfg(target_os = "macos")]
pub type NativeFontHandle = CGFont;
/// Native fonts are not used on Linux; all fonts are raw.
#[cfg(not(target_os = "macos"))]
#[derive(Clone, Serialize, Deserialize)]
pub struct NativeFontHandle; Is it the same bug? Should I file another one? |
Different bug unfortunately. I filed it as serde-deprecated/syntex#81. |
Add formatting options for Complex This adds LowerExp and UpperExp traits for Complex, taking precision into account. Fixes serde-rs#148
For example, this doesn't work:
It appears that the codegen simply doesn't know what to do about cfg_attr.
I suppose it's possible that not enough info is available when codegen occurs to actually resolve this. If so, feel free to close.
The text was updated successfully, but these errors were encountered: