Change:
I setup a crate using the example from There are no tests setup: no tests folder, no #[test] attributes. succeeds fails with: #[procmacroderive]proc-macro Naturally I expected this error not to occur. Run on the latest nightly via rustup: rustc 1.14.0-nightly ( 2016-10-27) binary: rustc commit-hash: commit-date: 2016-10-27 host: x86_64-unknown-linux-gnu release: 1.14.0-nightly LLVM version: 3.9
You can probably work around this by using (although I haven't tested that).
Thanks for the report! I'm not sure what the best way to solve this would be. We could either tell the compiler that doesn't work for these crate types, or we could tell Cargo to not test proc-macro libraries. Both should have the end goal though of having work by default.
Would a simple fix for this be to add to ? Or should - where it currently panics - quietly bail out if this is a test crate?
I'd personally prefer for to keep doing the same feature gating it's doing today, so in that sense I don't think it should take the same bail-out route that rustdoc takes. Adding some logic to though sounds good to me.
I think it was wrong that this ticket was closed with since it states
Actually fixing this appears simpler than I expected. I'm guessing a should be enough. This will ensure all the feature gating is still done, but no expansion is performed. Did you have any further thoughts?
of it works it works for me!
this is failing again. It works correctly on nightly-2017-01-17 rustc 1.16.0-nightly ( 2017-01-17) but fails on nightly-2017-01-18 rustc 1.16.0-nightly ( 2017-01-17).
This could be related to recently enabling doc-testing of proc-macro crates in cargo This rustc change should fix that If you look at the cargo output, does the error happen when running the normal tests, or after trying to run doc-tests? Edit: I've tested this in the latest nightly from rustup, and this is definitely what is happening. Hopefully it will be fixed soon.
thanks for staying on top of this! I've approved and p=1'd it to hopefully get it in soon. sorry for the breakage!

Discussion:
let crate_types = sess.crate_types.borrow(); let num_crate_types = crate_types.len(); let is_proc_macro_crate = crate_types.contains(&config::CrateTypeProcMacro); <ins> let is_test_crate = sess.opts.test; </ins> syntax_ext::proc_macro_registrar::modify(&sess.parse_sess, &mut resolver, krate, is_proc_macro_crate, <ins> is_test_crate, </ins> num_crate_types, sess.diagnostic(), &sess.features.borrow())

in_root: bool, handler: &'a errors::Handler, is_proc_macro_crate: bool, <ins> is_test_crate: bool, </ins> } pub fn modify(sess: &ParseSess, resolver: &mut ::syntax::ext::base::Resolver, mut krate: ast::Crate, is_proc_macro_crate: bool, <ins> is_test_crate: bool, </ins> num_crate_types: usize, handler: &errors::Handler, features: &Features) -> ast::Crate {

in_root: true, handler: handler, is_proc_macro_crate: is_proc_macro_crate, <ins> is_test_crate: is_test_crate, </ins> }; visit::walk_crate(&mut collect, &krate);

attributes found"); } <ins> if self.is_test_crate { self.handler.span_err(attr.span(), "`--test` cannot be used with proc-macro crates"); return; } </ins> if !self.is_proc_macro_crate { self.handler.span_err(attr.span(), "the `#[proc_macro_derive]` attribute is 

<ins> // Copyright 2016 The Rust Project Developers. See the COPYRIGHT // file at the top-level directory of this distribution and at // http://rust-lang.org/COPYRIGHT. // // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your // option. This file may not be copied, modified, or distributed // except according to those terms. // compile-flags: --test #![crate_type = "proc-macro"] #![feature(proc_macro)] extern crate proc_macro; #[proc_macro_derive(A)] //~^ ERROR: `--test` cannot be used with proc-macro crates pub fn foo1(input: proc_macro::TokenStream) -> proc_macro::TokenStream { "".parse().unwrap() } </ins>