@@ -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
@@ -74,8 +91,6 @@ pub(crate) fn eii(
7491 return vec ! [ Annotatable :: Item ( orig_item) ] ;
7592 } ;
7693
77- let impl_unsafe = false ; // TODO
78-
7994 let abi = match func. sig . header . ext {
8095 // extern "X" fn => extern "X" {}
8196 ast:: Extern :: Explicit ( lit, _) => Some ( lit) ,
@@ -123,28 +138,6 @@ pub(crate) fn eii(
123138
124139 let macro_def = Annotatable :: Item ( P ( ast:: Item {
125140 attrs : ast:: AttrVec :: from_iter ( [
126- // #[eii_macro_for(func.ident)]
127- ast:: Attribute {
128- kind : ast:: AttrKind :: Normal ( P ( ast:: NormalAttr {
129- item : ast:: AttrItem {
130- unsafety : ast:: Safety :: Default ,
131- path : ast:: Path :: from_ident ( Ident :: new ( sym:: eii_macro_for, span) ) ,
132- args : ast:: AttrArgs :: Delimited ( ast:: DelimArgs {
133- dspan : DelimSpan :: from_single ( span) ,
134- delim : Delimiter :: Parenthesis ,
135- tokens : TokenStream :: new ( vec ! [ tokenstream:: TokenTree :: Token (
136- token:: Token :: from_ast_ident( func. ident) ,
137- Spacing :: Alone ,
138- ) ] ) ,
139- } ) ,
140- tokens : None ,
141- } ,
142- tokens : None ,
143- } ) ) ,
144- id : ecx. sess . psess . attr_id_generator . mk_attr_id ( ) ,
145- style : ast:: AttrStyle :: Outer ,
146- span,
147- } ,
148141 // #[builtin_macro(eii_macro)]
149142 ast:: Attribute {
150143 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(func.ident)]
194+ eii_macro_for : Some ( ast:: EIIMacroFor {
195+ extern_item_path : ast:: Path :: from_ident ( func. ident ) ,
196+ impl_unsafe,
197+ } ) ,
201198 }
202199 ) ,
203200 tokens : None ,
0 commit comments