-
Notifications
You must be signed in to change notification settings - Fork 13.2k
/
Copy pathproc-macro.rs
72 lines (61 loc) · 2.42 KB
/
proc-macro.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
//@ force-host
//@ no-prefer-dynamic
//@ compile-flags: --crate-type proc-macro --document-private-items
#![crate_type="proc-macro"]
#![crate_name="some_macros"]
//@ has some_macros/index.html
//@ has - '//a/[@href="attr.some_proc_attr.html"]' 'some_proc_attr'
//! include a link to [some_proc_macro!] to make sure it works.
extern crate proc_macro;
use proc_macro::TokenStream;
//@ has some_macros/index.html
//@ has - '//h2' 'Macros'
//@ has - '//h2' 'Attribute Macros'
//@ has - '//h2' 'Derive Macros'
//@ !has - '//h2' 'Functions'
//@ has some_macros/all.html
//@ has - '//a[@href="macro.some_proc_macro.html"]' 'some_proc_macro'
//@ has - '//a[@href="attr.some_proc_attr.html"]' 'some_proc_attr'
//@ has - '//a[@href="derive.SomeDerive.html"]' 'SomeDerive'
//@ !has - '//a/@href' 'fn.some_proc_macro.html'
//@ !has - '//a/@href' 'fn.some_proc_attr.html'
//@ !has - '//a/@href' 'fn.some_derive.html'
//@ has some_macros/index.html '//a/@href' 'macro.some_proc_macro.html'
//@ !has - '//a/@href' 'fn.some_proc_macro.html'
//@ has some_macros/macro.some_proc_macro.html
//@ !has some_macros/fn.some_proc_macro.html
/// a proc-macro that swallows its input and does nothing.
#[proc_macro]
pub fn some_proc_macro(_input: TokenStream) -> TokenStream {
TokenStream::new()
}
//@ has some_macros/index.html '//a/@href' 'attr.some_proc_attr.html'
//@ !has - '//a/@href' 'fn.some_proc_attr.html'
//@ has some_macros/attr.some_proc_attr.html
//@ !has some_macros/fn.some_proc_attr.html
/// a proc-macro attribute that passes its item through verbatim.
#[proc_macro_attribute]
pub fn some_proc_attr(_attr: TokenStream, item: TokenStream) -> TokenStream {
item
}
//@ has some_macros/index.html '//a/@href' 'derive.SomeDerive.html'
//@ !has - '//a/@href' 'fn.some_derive.html'
//@ has some_macros/derive.SomeDerive.html
//@ !has some_macros/fn.some_derive.html
/// a derive attribute that adds nothing to its input.
#[proc_macro_derive(SomeDerive)]
pub fn some_derive(_item: TokenStream) -> TokenStream {
TokenStream::new()
}
//@ has some_macros/foo/index.html
mod foo {
//@ has - '//code' 'pub use some_proc_macro;'
//@ has - '//a/@href' '../macro.some_proc_macro.html'
pub use some_proc_macro;
//@ has - '//code' 'pub use some_proc_attr;'
//@ has - '//a/@href' '../attr.some_proc_attr.html'
pub use some_proc_attr;
//@ has - '//code' 'pub use some_derive;'
//@ has - '//a/@href' '../derive.SomeDerive.html'
pub use some_derive;
}