1
Fork 0

Add tests for malformed input in #[proc_macro_derive]

This commit is contained in:
Vadim Petrochenkov 2019-02-28 08:51:35 +03:00
parent 2c8bbf50db
commit e2009ea5ff
4 changed files with 122 additions and 88 deletions

View file

@ -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
}
pub fn foo2(input: TokenStream) -> 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)]
#[proc_macro_derive(d3, a, b)]
//~^ ERROR: attribute must have either one or two arguments
pub fn foo4(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
input
}
pub fn foo3(input: TokenStream) -> TokenStream { input }
#[proc_macro_derive(d(e))]
//~^ ERROR: must only be one word
pub fn foo5(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
input
}
#[proc_macro_derive(f, attributes(g = "h"))]
//~^ ERROR: must only be one word
pub fn foo6(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
input
}
#[proc_macro_derive(i, attributes(j(k)))]
//~^ ERROR: must only be one word
pub fn foo7(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
input
}
#[proc_macro_derive(l, attributes(m), n)]
#[proc_macro_derive(d4, attributes(a), b)]
//~^ ERROR: attribute must have either one or two arguments
pub fn foo8(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(d8(a))]
//~^ ERROR: must only be one word
pub fn foo8(input: TokenStream) -> TokenStream { input }
#[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 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(d16, attributes(a(b)))]
//~^ ERROR: must only be one word
pub fn foo16(input: TokenStream) -> 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 }

View file

@ -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(b, c, d)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
LL | #[proc_macro_derive(d4, attributes(a), b)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: not a meta item
--> $DIR/attribute.rs:25:21
|
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(f, attributes(g = "h"))]
| ^^^^^^^
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(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

View file

@ -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
}

View file

@ -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