@@ -6,32 +6,49 @@ use rustc_ast_pretty::pprust::path_to_string;
6
6
use rustc_expand:: base:: { Annotatable , ExtCtxt } ;
7
7
use rustc_span:: { Ident , Span , kw, sym} ;
8
8
9
- /* ```rust
10
-
11
- #[eii]
12
- fn panic_handler();
13
-
14
- #[eii(panic_handler)]
15
- fn panic_handler();
16
-
17
- #[eii(panic_handler, unsafe)]
18
- fn panic_handler();
19
-
20
- // expansion:
21
-
22
- extern "Rust" {
23
- fn panic_handler();
9
+ // ```rust
10
+ // #[eii]
11
+ // fn panic_handler();
12
+ //
13
+ // // or:
14
+ //
15
+ // #[eii(panic_handler)]
16
+ // fn panic_handler();
17
+ //
18
+ // // expansion:
19
+ //
20
+ // extern "Rust" {
21
+ // fn panic_handler();
22
+ // }
23
+ //
24
+ // #[rustc_builtin_macro(eii_macro)]
25
+ // #[eii_macro_for(panic_handler)]
26
+ // macro panic_handler() {}
27
+ // ```
28
+ pub ( crate ) fn eii (
29
+ ecx : & mut ExtCtxt < ' _ > ,
30
+ span : Span ,
31
+ meta_item : & ast:: MetaItem ,
32
+ item : Annotatable ,
33
+ ) -> Vec < Annotatable > {
34
+ eii_ ( ecx, span, meta_item, item, false )
24
35
}
25
36
26
- #[rustc_builtin_macro(eii_macro)] // eii_macro_for: panic_handler
27
- macro panic_handler() {}
37
+ pub ( crate ) fn unsafe_eii (
38
+ ecx : & mut ExtCtxt < ' _ > ,
39
+ span : Span ,
40
+ meta_item : & ast:: MetaItem ,
41
+ item : Annotatable ,
42
+ ) -> Vec < Annotatable > {
43
+ eii_ ( ecx, span, meta_item, item, true )
44
+ }
28
45
29
- ``` */
30
- pub ( crate ) fn eii (
46
+ fn eii_ (
31
47
ecx : & mut ExtCtxt < ' _ > ,
32
48
span : Span ,
33
49
meta_item : & ast:: MetaItem ,
34
50
item : Annotatable ,
51
+ impl_unsafe : bool ,
35
52
) -> Vec < Annotatable > {
36
53
let span = ecx. with_def_site_ctxt ( span) ;
37
54
@@ -73,8 +90,6 @@ pub(crate) fn eii(
73
90
return vec ! [ Annotatable :: Item ( P ( item) ) ] ;
74
91
} ;
75
92
76
- let impl_unsafe = false ; // TODO
77
-
78
93
let abi = match func. sig . header . ext {
79
94
// extern "X" fn => extern "X" {}
80
95
ast:: Extern :: Explicit ( lit, _) => Some ( lit) ,
@@ -124,28 +139,6 @@ pub(crate) fn eii(
124
139
125
140
let macro_def = Annotatable :: Item ( P ( ast:: Item {
126
141
attrs : ast:: AttrVec :: from_iter ( [
127
- // #[eii_macro_for(item_name)]
128
- ast:: Attribute {
129
- kind : ast:: AttrKind :: Normal ( P ( ast:: NormalAttr {
130
- item : ast:: AttrItem {
131
- unsafety : ast:: Safety :: Default ,
132
- path : ast:: Path :: from_ident ( Ident :: new ( sym:: eii_macro_for, span) ) ,
133
- args : ast:: AttrArgs :: Delimited ( ast:: DelimArgs {
134
- dspan : DelimSpan :: from_single ( span) ,
135
- delim : Delimiter :: Parenthesis ,
136
- tokens : TokenStream :: new ( vec ! [ tokenstream:: TokenTree :: Token (
137
- token:: Token :: from_ast_ident( item_name) ,
138
- Spacing :: Alone ,
139
- ) ] ) ,
140
- } ) ,
141
- tokens : None ,
142
- } ,
143
- tokens : None ,
144
- } ) ) ,
145
- id : ecx. sess . psess . attr_id_generator . mk_attr_id ( ) ,
146
- style : ast:: AttrStyle :: Outer ,
147
- span,
148
- } ,
149
142
// #[builtin_macro(eii_macro)]
150
143
ast:: Attribute {
151
144
kind : ast:: AttrKind :: Normal ( P ( ast:: NormalAttr {
@@ -197,7 +190,11 @@ pub(crate) fn eii(
197
190
] ) ,
198
191
} ) ,
199
192
macro_rules : false ,
200
- eii_macro_for : None ,
193
+ // #[eii_macro_for(item_name)]
194
+ eii_macro_for : Some ( ast:: EIIMacroFor {
195
+ extern_item_path : ast:: Path :: from_ident ( item_name) ,
196
+ impl_unsafe,
197
+ } ) ,
201
198
} ) ,
202
199
tokens : None ,
203
200
} ) ) ;
0 commit comments