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

Proc macro gives bad error about custom derives if regular macro with the same name is imported first #39326

Closed
Arnavion opened this issue Jan 26, 2017 · 3 comments

Comments

@Arnavion
Copy link

Arnavion commented Jan 26, 2017

rustc 1.16.0-nightly (7821a9b 2017-01-23)

main.rs

#[macro_use] extern crate derive_error_chain;
#[macro_use] extern crate error_chain;

#[derive(Debug, error_chain)]
pub enum ErrorKind {
    Msg(String),
}

fn main() {
}

Cargo.toml

[package]
name = "rust-test"
version = "0.1.0"
authors = ["Arnavion <[email protected]>"]

[dependencies]
derive-error-chain = "=0.8.0"
error-chain = "=0.8.1"

cargo build gives:

error: `#[derive]` for custom traits is not stable enough for use. It is deprecated and will be removed in v1.15 (see issue #29644)
 --> src\main.rs:4:17
  |
4 | #[derive(Debug, error_chain)]
  |                 ^^^^^^^^^^^
  |
  = help: add #![feature(custom_derive)] to the crate attributes to enable

error: aborting due to previous error

derive-error-chain exports a proc macro named error_chain. error-chain exports a regular macro named error_chain.

Everything's fine if the order of the extern crate statements is reversed, or error-chain's import does not have #[macro_use].

@keeperofdakeys
Copy link
Contributor

keeperofdakeys commented Jan 30, 2017

Unfortunately macro_rules, proc-macro derives, and future proc-macros share the same namespace. So I don't think there is a way to fix this besides renaming one of the macros.

@nrc ?

@Arnavion
Copy link
Author

I'm not asking for a way to make this work. I'm asking for an error message that isn't misleading :)

@keeperofdakeys
Copy link
Contributor

Ah, I'm actually working on a PR right now which should fix this, I'll be sure to keep it in mind #39391.

frewsxcv added a commit to frewsxcv/rust that referenced this issue Feb 5, 2017
…eyfried

Expand derive macros in the MacroExpander

This removes the expand_derives function, and sprinkles the functionality throughout the Invocation Collector, Expander and Resolver.

Fixes rust-lang#39326

r? @jseyfried
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants