serde-deprecated / syntex

No longer maintained
113 stars 34 forks source link

Derived items need to copy cfg attributes from the original item #81

Open dtolnay opened 8 years ago

dtolnay commented 8 years ago

Currently Syntex expands this:

#[cfg(condition)]
#[derive(Trait)]
#[other_attributes]
struct Struct;

... into this:

impl Trait for Struct { /* ... */ }
#[cfg(condition)]
#[other_attributes]
struct Struct;

It would be better to expand to this:

#[cfg(condition)]
impl Trait for Struct { /* ... */ }
#[cfg(condition)]
#[other_attributes]
struct Struct;

Open question whether we want to copy other attributes as well.

dtolnay commented 8 years ago

The workaround is:

#[cfg(condition)]
#[cfg_attr(condition, derive(Trait))]
#[other_attributes]
struct Struct;

which will work on Syntex >=0.36 and rustc >=1.11.

dtolnay commented 8 years ago

A different workaround that works on older Syntex and older rustc:

#[cfg(condition)]
mod workaround {
    #[derive(Trait)]
    #[other_attributes]
    pub struct Struct;
}
#[cfg(condition)]
use self::workaround::Struct;
dtolnay commented 8 years ago

This will no longer be necessary with Macros 1.1.