Skip to content
This repository has been archived by the owner on May 6, 2020. It is now read-only.

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

Open
dtolnay opened this issue Jun 25, 2016 · 3 comments
Open

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

dtolnay opened this issue Jun 25, 2016 · 3 comments
Assignees
Labels

Comments

@dtolnay
Copy link
Contributor

dtolnay commented Jun 25, 2016

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
Copy link
Contributor Author

dtolnay commented Jun 25, 2016

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
Copy link
Contributor Author

dtolnay commented Jun 25, 2016

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
Copy link
Contributor Author

dtolnay commented Sep 5, 2016

This will no longer be necessary with Macros 1.1.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Development

No branches or pull requests

1 participant