Skip to content

'cargo test' with proc_macro_derive fails #37480

@rukai

Description

@rukai

I setup a crate using the example from http://www.ncameron.org/blog/macros-and-syntax-extensions-and-compiler-plugins-where-are-we-at/
There are no tests setup: no tests folder, no #[test] attributes.

  • cargo run succeeds
  • cargo test fails with: error: the #[proc_macro_derive]attribute is only usable with crates of theproc-macro crate type

Naturally I expected this error not to occur.

cargo.toml

name = "foobar"
version = "0.1.0"
authors = ["Rukai]

[lib]
proc-macro = true

lib.rs

#![feature(proc_macro, proc_macro_lib)]
#![crate_type = "proc-macro"]

extern crate proc_macro;

use proc_macro::TokenStream;

#[proc_macro_derive(B)]
pub fn derive(input: TokenStream) -> TokenStream {  
    let input = input.to_string();
    format!("{}\n impl B for A {{ fn b(&self) {{}} }}", input).parse().unwrap()
}

rust version

Run on the latest nightly via rustup:
rustc 1.14.0-nightly (3f4408347 2016-10-27) binary: rustc commit-hash: 3f4408347d2109803edbf53c89c8bce575de4b67 commit-date: 2016-10-27 host: x86_64-unknown-linux-gnu release: 1.14.0-nightly LLVM version: 3.9

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions