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

serde_derive fail involving conditional compilation #577

Closed
alexbool opened this issue Oct 8, 2016 · 4 comments
Closed

serde_derive fail involving conditional compilation #577

alexbool opened this issue Oct 8, 2016 · 4 comments
Assignees
Labels

Comments

@alexbool
Copy link

alexbool commented Oct 8, 2016

Cargo.toml:

[package]
name = "serde-fail"
version = "0.1.0"
authors = ["Alexander Bulaev <alexbool@yandex-team.ru>"]

[dependencies]
serde = { version = "*", optional = true }
serde_derive = { version = "*", optional = true }

[features]
serialize = ["serde", "serde_derive"]

src/lib.rs:

#![cfg_attr(feature = "serialize", feature(rustc_macro))]

#[cfg(feature = "serialize")]
extern crate serde;
#[cfg_attr(feature = "serialize", macro_use)]
#[cfg(feature = "serialize")]
extern crate serde_derive;

#[derive(Copy, Clone)]
#[cfg_attr(feature = "serialize", derive(Serialize, Deserialize))]
pub struct MyStruct {
    value: i64,
}
alexbool@alexbool-osx ~/D/I/serde-fail> cargo build --features "serialize"
   Compiling serde-fail v0.1.0 (file:///Users/alexbool/Documents/IdeaProjects/serde-fail)
error: internal implementation detail (see issue #29642)
  --> src/lib.rs:11:1
   |
11 | pub struct MyStruct {
   | ^
   |
   = help: add #![feature(rustc_attrs)] to the crate attributes to enable

error: aborting due to previous error

error: Could not compile `serde-fail`.

To learn more, run the command again with --verbose.

Meta:

alexbool@alexbool-osx ~/D/I/serde-fail> rustc -vV
rustc 1.14.0-nightly (3210fd5c2 2016-10-05)
binary: rustc
commit-hash: 3210fd5c20ffc6da420eb00e60bdc8704577fd3b
commit-date: 2016-10-05
host: x86_64-apple-darwin
release: 1.14.0-nightly
@dtolnay
Copy link
Member

dtolnay commented Oct 8, 2016

Thanks for the detailed report! This is a problem with the current Macros 1.1 implementation in Rust. I commented in the tracking issue so we will see whether it is something they can fix.

For now the workaround is to always put derives that include custom derives above any other attributes:

#[cfg_attr(feature = "serialize", derive(Serialize, Deserialize))]
#[derive(Copy, Clone)]
pub struct MyStruct {
    value: i64,
}

@alexbool
Copy link
Author

alexbool commented Oct 9, 2016

Thanks! The workaround works :)

@dtolnay
Copy link
Member

dtolnay commented Oct 10, 2016

This will be fixed by rust-lang/rust#37067.

sophiajt pushed a commit to sophiajt/rust that referenced this issue Oct 11, 2016
…excrichton

macros: expand `#[derive]`s after other attribute macros and improve intra-`#[derive]` ordering

Fixes serde-rs/serde#577.
cc rust-lang#35900
r? @alexcrichton
alexcrichton added a commit to alexcrichton/rust that referenced this issue Oct 12, 2016
…excrichton

macros: expand `#[derive]`s after other attribute macros and improve intra-`#[derive]` ordering

Fixes serde-rs/serde#577.
cc rust-lang#35900
r? @alexcrichton
@dtolnay
Copy link
Member

dtolnay commented Oct 19, 2016

This has been fixed as of rustc 1.14.0-nightly (e0111758e 2016-10-17).

@dtolnay dtolnay closed this as completed Oct 19, 2016
@dtolnay dtolnay self-assigned this Apr 9, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

2 participants