]> git.lizzy.rs Git - rust.git/commitdiff
Allow --test to be used on proc-macro crates
authorJosh Driver <keeperofdakeys@gmail.com>
Mon, 21 Nov 2016 13:32:58 +0000 (00:02 +1030)
committerJosh Driver <keeperofdakeys@gmail.com>
Thu, 1 Dec 2016 13:42:20 +0000 (00:12 +1030)
src/libsyntax_ext/proc_macro_registrar.rs
src/test/compile-fail-fulldeps/proc-macro/error-on-test.rs [deleted file]
src/test/run-pass-fulldeps/proc-macro/derive-test.rs [new file with mode: 0644]

index bbdbda701ae8eba464d48f88f7a9f6b9e33e8d16..6256440bc815e3a4dcde317bb8f2dd635eef1ed2 100644 (file)
@@ -75,6 +75,10 @@ pub fn modify(sess: &ParseSess,
         handler.err("cannot mix `proc-macro` crate type with others");
     }
 
+    if is_test_crate {
+        return krate;
+    }
+
     krate.module.items.push(mk_registrar(&mut cx, &collect.derives));
 
     if krate.exported_macros.len() > 0 {
@@ -141,8 +145,6 @@ fn visit_item(&mut self, item: &ast::Item) {
         }
 
         if self.is_test_crate {
-            self.handler.span_err(attr.span(),
-                                  "`--test` cannot be used with proc-macro crates");
             return;
         }
 
diff --git a/src/test/compile-fail-fulldeps/proc-macro/error-on-test.rs b/src/test/compile-fail-fulldeps/proc-macro/error-on-test.rs
deleted file mode 100644 (file)
index 4751679..0000000
+++ /dev/null
@@ -1,22 +0,0 @@
-// 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, proc_macro_lib)]
-
-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()
-}
diff --git a/src/test/run-pass-fulldeps/proc-macro/derive-test.rs b/src/test/run-pass-fulldeps/proc-macro/derive-test.rs
new file mode 100644 (file)
index 0000000..2f44515
--- /dev/null
@@ -0,0 +1,30 @@
+// 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.
+
+// no-prefer-dynamic
+// compile-flags: --test
+
+#![crate_type = "proc-macro"]
+#![feature(proc_macro)]
+#![feature(proc_macro, proc_macro_lib)]
+
+extern crate proc_macro;
+
+use proc_macro::TokenStream;
+
+#[proc_macro_derive(Foo)]
+pub fn derive_foo(_input: TokenStream) -> TokenStream {
+    "".parse().unwrap()
+}
+
+#[test]
+pub fn test_derive() {
+    assert!(true);
+}