about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorVadim Petrochenkov <vadim.petrochenkov@gmail.com>2019-02-28 08:51:35 +0300
committerVadim Petrochenkov <vadim.petrochenkov@gmail.com>2019-03-16 23:13:15 +0300
commite2009ea5ffdacd767ea85d463fbe40d0e8b06951 (patch)
tree140429c7c67aef0b028167c02a0e0bb5afdd81d8 /src
parent2c8bbf50db0ef90a33f986ba8fc2e1fe129197ff (diff)
downloadrust-e2009ea5ffdacd767ea85d463fbe40d0e8b06951.tar.gz
rust-e2009ea5ffdacd767ea85d463fbe40d0e8b06951.zip
Add tests for malformed input in `#[proc_macro_derive]`
Diffstat (limited to 'src')
-rw-r--r--src/test/ui/proc-macro/attribute.rs94
-rw-r--r--src/test/ui/proc-macro/attribute.stderr86
-rw-r--r--src/test/ui/proc-macro/shadow-builtin.rs14
-rw-r--r--src/test/ui/proc-macro/shadow-builtin.stderr8
4 files changed, 118 insertions, 84 deletions
diff --git a/src/test/ui/proc-macro/attribute.rs b/src/test/ui/proc-macro/attribute.rs
index a0b982d75f5..f1775307fb4 100644
--- a/src/test/ui/proc-macro/attribute.rs
+++ b/src/test/ui/proc-macro/attribute.rs
@@ -4,53 +4,73 @@
 #![crate_type = "proc-macro"]
 
 extern crate proc_macro;
+use proc_macro::*;
 
 #[proc_macro_derive]
 //~^ ERROR: attribute must be of the form
-pub fn foo1(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
-    input
-}
+pub fn foo1(input: TokenStream) -> TokenStream { input }
 
-#[proc_macro_derive = "foo"]
+#[proc_macro_derive = ""]
 //~^ ERROR: attribute must be of the form
-pub fn foo2(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
-    input
-}
-
-#[proc_macro_derive(
-    a = "b"
-)]
-//~^^ ERROR: must only be one word
-pub fn foo3(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
-    input
-}
-
-#[proc_macro_derive(b, c, d)]
+pub fn foo2(input: TokenStream) -> TokenStream { input }
+
+#[proc_macro_derive(d3, a, b)]
+//~^ ERROR: attribute must have either one or two arguments
+pub fn foo3(input: TokenStream) -> TokenStream { input }
+
+#[proc_macro_derive(d4, attributes(a), b)]
 //~^ ERROR: attribute must have either one or two arguments
-pub fn foo4(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
-    input
-}
+pub fn foo4(input: TokenStream) -> TokenStream { input }
+
+#[proc_macro_derive("a")]
+//~^ ERROR: not a meta item
+pub fn foo5(input: TokenStream) -> TokenStream { input }
+
+#[proc_macro_derive(d6 = "")]
+//~^ ERROR: must only be one word
+pub fn foo6(input: TokenStream) -> TokenStream { input }
+
+#[proc_macro_derive(m::d7)]
+//FIXME ERROR: must only be one word
+pub fn foo7(input: TokenStream) -> TokenStream { input }
 
-#[proc_macro_derive(d(e))]
+#[proc_macro_derive(d8(a))]
 //~^ ERROR: must only be one word
-pub fn foo5(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
-    input
-}
+pub fn foo8(input: TokenStream) -> TokenStream { input }
 
-#[proc_macro_derive(f, attributes(g = "h"))]
+#[proc_macro_derive(self)]
+//FIXME ERROR: `self` cannot be a name of derive macro
+pub fn foo9(input: TokenStream) -> TokenStream { input }
+
+#[proc_macro_derive(PartialEq)]
+//~^ ERROR: cannot override a built-in #[derive] mode
+pub fn foo10(input: TokenStream) -> TokenStream { input }
+
+#[proc_macro_derive(d11, a)]
+//~^ ERROR: second argument must be `attributes`
+//~| ERROR: attribute must be of form: `attributes(foo, bar)`
+pub fn foo11(input: TokenStream) -> TokenStream { input }
+
+#[proc_macro_derive(d12, attributes)]
+//~^ ERROR: attribute must be of form: `attributes(foo, bar)`
+pub fn foo12(input: TokenStream) -> TokenStream { input }
+
+#[proc_macro_derive(d13, attributes("a"))]
+//~^ ERROR: not a meta item
+pub fn foo13(input: TokenStream) -> TokenStream { input }
+
+#[proc_macro_derive(d14, attributes(a = ""))]
 //~^ ERROR: must only be one word
-pub fn foo6(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
-    input
-}
+pub fn foo14(input: TokenStream) -> TokenStream { input }
+
+#[proc_macro_derive(d15, attributes(m::a))]
+//FIXME ERROR: must only be one word
+pub fn foo15(input: TokenStream) -> TokenStream { input }
 
-#[proc_macro_derive(i, attributes(j(k)))]
+#[proc_macro_derive(d16, attributes(a(b)))]
 //~^ ERROR: must only be one word
-pub fn foo7(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
-    input
-}
+pub fn foo16(input: TokenStream) -> TokenStream { input }
 
-#[proc_macro_derive(l, attributes(m), n)]
-//~^ ERROR: attribute must have either one or two arguments
-pub fn foo8(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
-    input
-}
+#[proc_macro_derive(d17, attributes(self))]
+//FIXME ERROR: `self` cannot be a name of derive helper attribute
+pub fn foo17(input: TokenStream) -> TokenStream { input }
diff --git a/src/test/ui/proc-macro/attribute.stderr b/src/test/ui/proc-macro/attribute.stderr
index 231eb1f1068..7bafb0abc4f 100644
--- a/src/test/ui/proc-macro/attribute.stderr
+++ b/src/test/ui/proc-macro/attribute.stderr
@@ -1,50 +1,86 @@
-error: must only be one word
-  --> $DIR/attribute.rs:21:5
+error: attribute must have either one or two arguments
+  --> $DIR/attribute.rs:17:1
    |
-LL |     a = "b"
-   |     ^^^^^^^
+LL | #[proc_macro_derive(d3, a, b)]
+   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 
 error: attribute must have either one or two arguments
-  --> $DIR/attribute.rs:28:1
+  --> $DIR/attribute.rs:21:1
+   |
+LL | #[proc_macro_derive(d4, attributes(a), b)]
+   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: not a meta item
+  --> $DIR/attribute.rs:25:21
    |
-LL | #[proc_macro_derive(b, c, d)]
-   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+LL | #[proc_macro_derive("a")]
+   |                     ^^^
 
 error: must only be one word
-  --> $DIR/attribute.rs:34:21
+  --> $DIR/attribute.rs:29:21
    |
-LL | #[proc_macro_derive(d(e))]
-   |                     ^^^^
+LL | #[proc_macro_derive(d6 = "")]
+   |                     ^^^^^^^
 
 error: must only be one word
-  --> $DIR/attribute.rs:40:35
+  --> $DIR/attribute.rs:37:21
+   |
+LL | #[proc_macro_derive(d8(a))]
+   |                     ^^^^^
+
+error: cannot override a built-in #[derive] mode
+  --> $DIR/attribute.rs:45:21
+   |
+LL | #[proc_macro_derive(PartialEq)]
+   |                     ^^^^^^^^^
+
+error: second argument must be `attributes`
+  --> $DIR/attribute.rs:49:26
    |
-LL | #[proc_macro_derive(f, attributes(g = "h"))]
-   |                                   ^^^^^^^
+LL | #[proc_macro_derive(d11, a)]
+   |                          ^
+
+error: attribute must be of form: `attributes(foo, bar)`
+  --> $DIR/attribute.rs:49:26
+   |
+LL | #[proc_macro_derive(d11, a)]
+   |                          ^
+
+error: attribute must be of form: `attributes(foo, bar)`
+  --> $DIR/attribute.rs:54:26
+   |
+LL | #[proc_macro_derive(d12, attributes)]
+   |                          ^^^^^^^^^^
+
+error: not a meta item
+  --> $DIR/attribute.rs:58:37
+   |
+LL | #[proc_macro_derive(d13, attributes("a"))]
+   |                                     ^^^
 
 error: must only be one word
-  --> $DIR/attribute.rs:46:35
+  --> $DIR/attribute.rs:62:37
    |
-LL | #[proc_macro_derive(i, attributes(j(k)))]
-   |                                   ^^^^
+LL | #[proc_macro_derive(d14, attributes(a = ""))]
+   |                                     ^^^^^^
 
-error: attribute must have either one or two arguments
-  --> $DIR/attribute.rs:52:1
+error: must only be one word
+  --> $DIR/attribute.rs:70:37
    |
-LL | #[proc_macro_derive(l, attributes(m), n)]
-   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+LL | #[proc_macro_derive(d16, attributes(a(b)))]
+   |                                     ^^^^
 
 error: attribute must be of the form `#[proc_macro_derive(TraitName, /*opt*/ attributes(name1, name2, ...))]`
-  --> $DIR/attribute.rs:8:1
+  --> $DIR/attribute.rs:9:1
    |
 LL | #[proc_macro_derive]
    | ^^^^^^^^^^^^^^^^^^^^
 
 error: attribute must be of the form `#[proc_macro_derive(TraitName, /*opt*/ attributes(name1, name2, ...))]`
-  --> $DIR/attribute.rs:14:1
+  --> $DIR/attribute.rs:13:1
    |
-LL | #[proc_macro_derive = "foo"]
-   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+LL | #[proc_macro_derive = ""]
+   | ^^^^^^^^^^^^^^^^^^^^^^^^^
 
-error: aborting due to 8 previous errors
+error: aborting due to 14 previous errors
 
diff --git a/src/test/ui/proc-macro/shadow-builtin.rs b/src/test/ui/proc-macro/shadow-builtin.rs
deleted file mode 100644
index afcc0ebc346..00000000000
--- a/src/test/ui/proc-macro/shadow-builtin.rs
+++ /dev/null
@@ -1,14 +0,0 @@
-// force-host
-// no-prefer-dynamic
-
-#![crate_type = "proc-macro"]
-
-extern crate proc_macro;
-
-use proc_macro::TokenStream;
-
-#[proc_macro_derive(PartialEq)]
-//~^ ERROR: cannot override a built-in #[derive] mode
-pub fn foo(input: TokenStream) -> TokenStream {
-    input
-}
diff --git a/src/test/ui/proc-macro/shadow-builtin.stderr b/src/test/ui/proc-macro/shadow-builtin.stderr
deleted file mode 100644
index 668579509dc..00000000000
--- a/src/test/ui/proc-macro/shadow-builtin.stderr
+++ /dev/null
@@ -1,8 +0,0 @@
-error: cannot override a built-in #[derive] mode
-  --> $DIR/shadow-builtin.rs:10:21
-   |
-LL | #[proc_macro_derive(PartialEq)]
-   |                     ^^^^^^^^^
-
-error: aborting due to previous error
-