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

macro imports don't work when there are _two_ imported attributes #52525

Closed
Manishearth opened this issue Jul 19, 2018 · 4 comments · Fixed by #52539
Closed

macro imports don't work when there are _two_ imported attributes #52525

Manishearth opened this issue Jul 19, 2018 · 4 comments · Fixed by #52539
Labels
A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) A-macros-1.2 Area: Declarative macros 1.2 C-bug Category: This is a bug.

Comments

@Manishearth
Copy link
Member

// crate must be on rust 2018
// OR add an `extern crate serde_derive`

use serde_derive::Deserialize;

#[derive(Deserialize)]
#[serde(rename_all = "kebab-case")]
#[serde(deny_unknown_fields)]
enum Foo {
    A(u8)
}

This is the code you are supposed to use according to the macro_use_extern_crate lint.

It fails to compile, with

   Compiling t v0.1.0 (file:///home/manishearth/sand/bar/t)                                                              
error: cannot find attribute macro `serde` in this scope=========>      ] 9/10: t                                        
  --> src/main.rs:11:3
   |
11 | #[serde(deny_unknown_fields)]
   |   ^^^^^

It compiles fine if you use just one of the two attributes. Swapping attribute order makes it complain about the last non-derive attribute.

This seems broken?

cc @dtolnay @alexcrichton

@Manishearth Manishearth added A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) C-bug Category: This is a bug. labels Jul 19, 2018
@dtolnay
Copy link
Member

dtolnay commented Jul 19, 2018

Confirmed, this behavior is broken. Possibly related to #52226. @petrochenkov

@dtolnay
Copy link
Member

dtolnay commented Jul 19, 2018

As a workaround specific to serde_derive, we allow multiple elements within one #[serde(...)] attribute.

#[derive(Deserialize)]
#[serde(rename_all = "kebab-case", deny_unknown_fields)]
enum Foo {
    A(u8)
}

@Manishearth
Copy link
Member Author

Manishearth commented Jul 19, 2018 via email

@alexcrichton alexcrichton added the A-macros-1.2 Area: Declarative macros 1.2 label Jul 19, 2018
alexcrichton added a commit to alexcrichton/rust that referenced this issue Jul 19, 2018
This commit fixes an issue where multiple custom attributes could not be fed
into a custom derive in some situations with the `use_extern_macros` feature
enabled. The problem was that the macro expander didn't consider that it was
making progress when we were deducing that attributes should be lumped in with
custom derive invocations.

The fix applied here was to track in the expander if our attribute is changing
(getting stashed away elsewhere and replaced with a new invocation). If it is
swapped then it's considered progress, otherwise behavior should remain the
same.

Closes rust-lang#52525
@alexcrichton
Copy link
Member

This should be fixed in #52539

kennytm added a commit to kennytm/rust that referenced this issue Jul 20, 2018
rustc: Fix two custom attributes with custom derive

This commit fixes an issue where multiple custom attributes could not be fed
into a custom derive in some situations with the `use_extern_macros` feature
enabled. The problem was that the macro expander didn't consider that it was
making progress when we were deducing that attributes should be lumped in with
custom derive invocations.

The fix applied here was to track in the expander if our attribute is changing
(getting stashed away elsewhere and replaced with a new invocation). If it is
swapped then it's considered progress, otherwise behavior should remain the
same.

Closes rust-lang#52525
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) A-macros-1.2 Area: Declarative macros 1.2 C-bug Category: This is a bug.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants