@@ -6,32 +6,49 @@ use rustc_ast_pretty::pprust::path_to_string;
66use rustc_expand:: base:: { Annotatable , ExtCtxt } ;
77use rustc_span:: { Ident , Span , kw, sym} ;
88
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 )
2435}
2536
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+ }
2845
29- ``` */
30- pub ( crate ) fn eii (
46+ fn eii_ (
3147 ecx : & mut ExtCtxt < ' _ > ,
3248 span : Span ,
3349 meta_item : & ast:: MetaItem ,
3450 item : Annotatable ,
51+ impl_unsafe : bool ,
3552) -> Vec < Annotatable > {
3653 let span = ecx. with_def_site_ctxt ( span) ;
3754
@@ -73,8 +90,6 @@ pub(crate) fn eii(
7390 return vec ! [ Annotatable :: Item ( P ( item) ) ] ;
7491 } ;
7592
76- let impl_unsafe = false ; // TODO
77-
7893 let abi = match func. sig . header . ext {
7994 // extern "X" fn => extern "X" {}
8095 ast:: Extern :: Explicit ( lit, _) => Some ( lit) ,
@@ -124,28 +139,6 @@ pub(crate) fn eii(
124139
125140 let macro_def = Annotatable :: Item ( P ( ast:: Item {
126141 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- } ,
149142 // #[builtin_macro(eii_macro)]
150143 ast:: Attribute {
151144 kind : ast:: AttrKind :: Normal ( P ( ast:: NormalAttr {
@@ -197,7 +190,11 @@ pub(crate) fn eii(
197190 ] ) ,
198191 } ) ,
199192 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+ } ) ,
201198 } ) ,
202199 tokens : None ,
203200 } ) ) ;
0 commit comments