Skip to content

Commit e0b37b1

Browse files
committed
Add tests for malformed input in #[proc_macro_derive]
1 parent c0086b9 commit e0b37b1

File tree

4 files changed

+118
-84
lines changed

4 files changed

+118
-84
lines changed

src/test/ui/proc-macro/attribute.rs

Lines changed: 57 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -4,53 +4,73 @@
44
#![crate_type = "proc-macro"]
55

66
extern crate proc_macro;
7+
use proc_macro::*;
78

89
#[proc_macro_derive]
910
//~^ ERROR: attribute must be of the form
10-
pub fn foo1(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
11-
input
12-
}
11+
pub fn foo1(input: TokenStream) -> TokenStream { input }
1312

14-
#[proc_macro_derive = "foo"]
13+
#[proc_macro_derive = ""]
1514
//~^ ERROR: attribute must be of the form
16-
pub fn foo2(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
17-
input
18-
}
19-
20-
#[proc_macro_derive(
21-
a = "b"
22-
)]
23-
//~^^ ERROR: must only be one word
24-
pub fn foo3(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
25-
input
26-
}
27-
28-
#[proc_macro_derive(b, c, d)]
15+
pub fn foo2(input: TokenStream) -> TokenStream { input }
16+
17+
#[proc_macro_derive(d3, a, b)]
18+
//~^ ERROR: attribute must have either one or two arguments
19+
pub fn foo3(input: TokenStream) -> TokenStream { input }
20+
21+
#[proc_macro_derive(d4, attributes(a), b)]
2922
//~^ ERROR: attribute must have either one or two arguments
30-
pub fn foo4(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
31-
input
32-
}
23+
pub fn foo4(input: TokenStream) -> TokenStream { input }
24+
25+
#[proc_macro_derive("a")]
26+
//~^ ERROR: not a meta item
27+
pub fn foo5(input: TokenStream) -> TokenStream { input }
28+
29+
#[proc_macro_derive(d6 = "")]
30+
//~^ ERROR: must only be one word
31+
pub fn foo6(input: TokenStream) -> TokenStream { input }
32+
33+
#[proc_macro_derive(m::d7)]
34+
//FIXME ERROR: must only be one word
35+
pub fn foo7(input: TokenStream) -> TokenStream { input }
3336

34-
#[proc_macro_derive(d(e))]
37+
#[proc_macro_derive(d8(a))]
3538
//~^ ERROR: must only be one word
36-
pub fn foo5(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
37-
input
38-
}
39+
pub fn foo8(input: TokenStream) -> TokenStream { input }
3940

40-
#[proc_macro_derive(f, attributes(g = "h"))]
41+
#[proc_macro_derive(self)]
42+
//FIXME ERROR: `self` cannot be a name of derive macro
43+
pub fn foo9(input: TokenStream) -> TokenStream { input }
44+
45+
#[proc_macro_derive(PartialEq)]
46+
//~^ ERROR: cannot override a built-in #[derive] mode
47+
pub fn foo10(input: TokenStream) -> TokenStream { input }
48+
49+
#[proc_macro_derive(d11, a)]
50+
//~^ ERROR: second argument must be `attributes`
51+
//~| ERROR: attribute must be of form: `attributes(foo, bar)`
52+
pub fn foo11(input: TokenStream) -> TokenStream { input }
53+
54+
#[proc_macro_derive(d12, attributes)]
55+
//~^ ERROR: attribute must be of form: `attributes(foo, bar)`
56+
pub fn foo12(input: TokenStream) -> TokenStream { input }
57+
58+
#[proc_macro_derive(d13, attributes("a"))]
59+
//~^ ERROR: not a meta item
60+
pub fn foo13(input: TokenStream) -> TokenStream { input }
61+
62+
#[proc_macro_derive(d14, attributes(a = ""))]
4163
//~^ ERROR: must only be one word
42-
pub fn foo6(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
43-
input
44-
}
64+
pub fn foo14(input: TokenStream) -> TokenStream { input }
65+
66+
#[proc_macro_derive(d15, attributes(m::a))]
67+
//FIXME ERROR: must only be one word
68+
pub fn foo15(input: TokenStream) -> TokenStream { input }
4569

46-
#[proc_macro_derive(i, attributes(j(k)))]
70+
#[proc_macro_derive(d16, attributes(a(b)))]
4771
//~^ ERROR: must only be one word
48-
pub fn foo7(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
49-
input
50-
}
72+
pub fn foo16(input: TokenStream) -> TokenStream { input }
5173

52-
#[proc_macro_derive(l, attributes(m), n)]
53-
//~^ ERROR: attribute must have either one or two arguments
54-
pub fn foo8(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
55-
input
56-
}
74+
#[proc_macro_derive(d17, attributes(self))]
75+
//FIXME ERROR: `self` cannot be a name of derive helper attribute
76+
pub fn foo17(input: TokenStream) -> TokenStream { input }
Lines changed: 61 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,86 @@
1-
error: must only be one word
2-
--> $DIR/attribute.rs:21:5
1+
error: attribute must have either one or two arguments
2+
--> $DIR/attribute.rs:17:1
33
|
4-
LL | a = "b"
5-
| ^^^^^^^
4+
LL | #[proc_macro_derive(d3, a, b)]
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
66

77
error: attribute must have either one or two arguments
8-
--> $DIR/attribute.rs:28:1
8+
--> $DIR/attribute.rs:21:1
9+
|
10+
LL | #[proc_macro_derive(d4, attributes(a), b)]
11+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
12+
13+
error: not a meta item
14+
--> $DIR/attribute.rs:25:21
915
|
10-
LL | #[proc_macro_derive(b, c, d)]
11-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
16+
LL | #[proc_macro_derive("a")]
17+
| ^^^
1218

1319
error: must only be one word
14-
--> $DIR/attribute.rs:34:21
20+
--> $DIR/attribute.rs:29:21
1521
|
16-
LL | #[proc_macro_derive(d(e))]
17-
| ^^^^
22+
LL | #[proc_macro_derive(d6 = "")]
23+
| ^^^^^^^
1824

1925
error: must only be one word
20-
--> $DIR/attribute.rs:40:35
26+
--> $DIR/attribute.rs:37:21
27+
|
28+
LL | #[proc_macro_derive(d8(a))]
29+
| ^^^^^
30+
31+
error: cannot override a built-in #[derive] mode
32+
--> $DIR/attribute.rs:45:21
33+
|
34+
LL | #[proc_macro_derive(PartialEq)]
35+
| ^^^^^^^^^
36+
37+
error: second argument must be `attributes`
38+
--> $DIR/attribute.rs:49:26
2139
|
22-
LL | #[proc_macro_derive(f, attributes(g = "h"))]
23-
| ^^^^^^^
40+
LL | #[proc_macro_derive(d11, a)]
41+
| ^
42+
43+
error: attribute must be of form: `attributes(foo, bar)`
44+
--> $DIR/attribute.rs:49:26
45+
|
46+
LL | #[proc_macro_derive(d11, a)]
47+
| ^
48+
49+
error: attribute must be of form: `attributes(foo, bar)`
50+
--> $DIR/attribute.rs:54:26
51+
|
52+
LL | #[proc_macro_derive(d12, attributes)]
53+
| ^^^^^^^^^^
54+
55+
error: not a meta item
56+
--> $DIR/attribute.rs:58:37
57+
|
58+
LL | #[proc_macro_derive(d13, attributes("a"))]
59+
| ^^^
2460

2561
error: must only be one word
26-
--> $DIR/attribute.rs:46:35
62+
--> $DIR/attribute.rs:62:37
2763
|
28-
LL | #[proc_macro_derive(i, attributes(j(k)))]
29-
| ^^^^
64+
LL | #[proc_macro_derive(d14, attributes(a = ""))]
65+
| ^^^^^^
3066

31-
error: attribute must have either one or two arguments
32-
--> $DIR/attribute.rs:52:1
67+
error: must only be one word
68+
--> $DIR/attribute.rs:70:37
3369
|
34-
LL | #[proc_macro_derive(l, attributes(m), n)]
35-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
70+
LL | #[proc_macro_derive(d16, attributes(a(b)))]
71+
| ^^^^
3672

3773
error: attribute must be of the form `#[proc_macro_derive(TraitName, /*opt*/ attributes(name1, name2, ...))]`
38-
--> $DIR/attribute.rs:8:1
74+
--> $DIR/attribute.rs:9:1
3975
|
4076
LL | #[proc_macro_derive]
4177
| ^^^^^^^^^^^^^^^^^^^^
4278

4379
error: attribute must be of the form `#[proc_macro_derive(TraitName, /*opt*/ attributes(name1, name2, ...))]`
44-
--> $DIR/attribute.rs:14:1
80+
--> $DIR/attribute.rs:13:1
4581
|
46-
LL | #[proc_macro_derive = "foo"]
47-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
82+
LL | #[proc_macro_derive = ""]
83+
| ^^^^^^^^^^^^^^^^^^^^^^^^^
4884

49-
error: aborting due to 8 previous errors
85+
error: aborting due to 14 previous errors
5086

src/test/ui/proc-macro/shadow-builtin.rs

Lines changed: 0 additions & 14 deletions
This file was deleted.

src/test/ui/proc-macro/shadow-builtin.stderr

Lines changed: 0 additions & 8 deletions
This file was deleted.

0 commit comments

Comments
 (0)