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

#![feature(proc_macro)] breaks some custom derive attributes #52219

Closed
alexcrichton opened this Issue Jul 10, 2018 · 4 comments

Comments

Projects
None yet
3 participants
@alexcrichton
Copy link
Member

alexcrichton commented Jul 10, 2018

Originally reported as rust-lang-nursery/rustfix#126 this is reduced to:

// foo.rs
#![crate_type = "proc-macro"]

extern crate proc_macro;

use proc_macro::TokenStream;

#[proc_macro_derive(Foo)]
pub fn foo(a: TokenStream) -> TokenStream {
    "".parse().unwrap()
}

#[proc_macro_derive(Bar, attributes(custom))]
pub fn bar(a: TokenStream) -> TokenStream {
    "".parse().unwrap()
}
// bar.rs
#![cfg_attr(broken, feature(proc_macro))]
#![crate_type = "lib"]

#[macro_use]
extern crate foo;

#[derive(Foo, Bar, Debug)]
#[custom = "test"]
pub enum A{
    B,
    C,
}

compiles with:

$ rustc +nightly foo.rs
$ rustc +nightly bar.rs -L .
$ rustc +nightly bar.rs -L . --cfg broken
error: cannot find attribute macro `custom` in this scope
 --> bar.rs:8:3
  |
8 | #[custom = "test"]
  |   ^^^^^^

error: aborting due to previous error
@alexcrichton

This comment has been minimized.

Copy link
Member Author

alexcrichton commented Jul 10, 2018

cc @petrochenkov, I'm not really sure what this classifies under, it seems like maybe #50911 although #![feature(use_extern_macros)] doesn't break it, only #![feature(proc_macro)] does. After #52081 though it may be broken by use_extern_macros (I'm not 100% sure where this is happening)

@petrochenkov

This comment has been minimized.

Copy link
Contributor

petrochenkov commented Jul 10, 2018

I'm not really sure what this classifies under, it seems like maybe #50911 although #![feature(use_extern_macros)] doesn't break it

This falls under "attribute resolution is mess" and "some things are gated by proc_macro while they should be gated by macro modularization (use_extern_macros)".

@cramertj

This comment has been minimized.

Copy link
Member

cramertj commented Jul 10, 2018

I hit this error last week when trying to update a crate that used failure's derive macros. I found that useing the macro would give me the attribute error, but #[macro_use]ing the crate worked.

alexcrichton added a commit to alexcrichton/rust that referenced this issue Jul 10, 2018

rustc: Search all derives for inert attributes
This commit fixes an apparent mistake in librustc_resolve where when the
`proc_macro` feature is enabled (or `rust_2018_preview`) the resolution of
custom attributes for custom derive was tweaked. Previously when an attribute
failed to resolve it was attempted to locate if there is a custom derive also in
scope which declares the attribute, but only the first custom derive directive
was search.

Instead this commit fixes the loop to search all custom derive invocations
looking for any which register the attribute in question.

Closes rust-lang#52219
@alexcrichton

This comment has been minimized.

Copy link
Member Author

alexcrichton commented Jul 10, 2018

@cramertj I think that may be a separate bug, can you file a different issue?

I believe I've fixed this issue in #52230

alexcrichton added a commit to alexcrichton/rust that referenced this issue Jul 10, 2018

rustc: Search all derives for inert attributes
This commit fixes an apparent mistake in librustc_resolve where when the
`proc_macro` feature is enabled (or `rust_2018_preview`) the resolution of
custom attributes for custom derive was tweaked. Previously when an attribute
failed to resolve it was attempted to locate if there is a custom derive also in
scope which declares the attribute, but only the first custom derive directive
was search.

Instead this commit fixes the loop to search all custom derive invocations
looking for any which register the attribute in question.

Closes rust-lang#52219

alexcrichton added a commit to alexcrichton/rust that referenced this issue Jul 10, 2018

rustc: Search all derives for inert attributes
This commit fixes an apparent mistake in librustc_resolve where when the
`proc_macro` feature is enabled (or `rust_2018_preview`) the resolution of
custom attributes for custom derive was tweaked. Previously when an attribute
failed to resolve it was attempted to locate if there is a custom derive also in
scope which declares the attribute, but only the first custom derive directive
was search.

Instead this commit fixes the loop to search all custom derive invocations
looking for any which register the attribute in question.

Closes rust-lang#52219

bors added a commit that referenced this issue Jul 12, 2018

Auto merge of #52230 - alexcrichton:attr-and-derive, r=petrochenkov
rustc: Search all derives for inert attributes

This commit fixes an apparent mistake in librustc_resolve where when the
`proc_macro` feature is enabled (or `rust_2018_preview`) the resolution of
custom attributes for custom derive was tweaked. Previously when an attribute
failed to resolve it was attempted to locate if there is a custom derive also in
scope which declares the attribute, but only the first custom derive directive
was search.

Instead this commit fixes the loop to search all custom derive invocations
looking for any which register the attribute in question.

Closes #52219

@bors bors closed this in #52230 Jul 12, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.