Skip to main content

rustc_builtin_macros/
eii.rs

1use rustc_ast::token::{Delimiter, TokenKind};
2use rustc_ast::tokenstream::{DelimSpacing, DelimSpan, Spacing, TokenStream, TokenTree};
3use rustc_ast::{
4    Attribute, DUMMY_NODE_ID, EiiDecl, EiiImpl, ItemKind, MetaItem, Mutability, Path, StmtKind,
5    Visibility, ast,
6};
7use rustc_ast_pretty::pprust::path_to_string;
8use rustc_expand::base::{Annotatable, ExtCtxt};
9use rustc_span::{ErrorGuaranteed, Ident, Span, kw, sym};
10use thin_vec::{ThinVec, thin_vec};
11
12use crate::diagnostics::{
13    EiiAttributeNotSupported, EiiBothDeclAndImpl, EiiExternTargetExpectedList,
14    EiiExternTargetExpectedMacro, EiiExternTargetExpectedUnsafe, EiiMacroExpectedMaxOneArgument,
15    EiiMultipleImplementations, EiiOnlyOnce, EiiSharedMacroInStatementPosition,
16    EiiSharedMacroTarget, EiiStaticArgumentRequired, EiiStaticDefaultApple, EiiStaticMutable,
17};
18
19/// ```rust
20/// #[eii]
21/// fn panic_handler();
22///
23/// // or:
24///
25/// #[eii(panic_handler)]
26/// fn panic_handler();
27///
28/// // expansion:
29///
30/// extern "Rust" {
31///     fn panic_handler();
32/// }
33///
34/// #[rustc_builtin_macro(eii_shared_macro)]
35/// #[eii_declaration(panic_handler)]
36/// macro panic_handler() {}
37/// ```
38pub(crate) fn eii(
39    ecx: &mut ExtCtxt<'_>,
40    span: Span,
41    meta_item: &ast::MetaItem,
42    item: Annotatable,
43) -> Vec<Annotatable> {
44    eii_(ecx, span, meta_item, item, false)
45}
46
47pub(crate) fn unsafe_eii(
48    ecx: &mut ExtCtxt<'_>,
49    span: Span,
50    meta_item: &ast::MetaItem,
51    item: Annotatable,
52) -> Vec<Annotatable> {
53    eii_(ecx, span, meta_item, item, true)
54}
55
56fn eii_(
57    ecx: &mut ExtCtxt<'_>,
58    eii_attr_span: Span,
59    meta_item: &ast::MetaItem,
60    orig_item: Annotatable,
61    impl_unsafe: bool,
62) -> Vec<Annotatable> {
63    let eii_attr_span = ecx.with_def_site_ctxt(eii_attr_span);
64
65    let item = if let Annotatable::Item(item) = orig_item {
66        item
67    } else if let Annotatable::Stmt(ref stmt) = orig_item
68        && let StmtKind::Item(ref item) = stmt.kind
69        && let ItemKind::Fn(ref f) = item.kind
70    {
71        ecx.dcx().emit_err(EiiSharedMacroInStatementPosition {
72            span: eii_attr_span.to(item.span),
73            name: path_to_string(&meta_item.path),
74            item_span: f.ident.span,
75        });
76        return ::alloc::boxed::box_assume_init_into_vec_unsafe(::alloc::intrinsics::write_box_via_move(::alloc::boxed::Box::new_uninit(),
        [orig_item]))vec![orig_item];
77    } else {
78        ecx.dcx().emit_err(EiiSharedMacroTarget {
79            span: eii_attr_span,
80            name: path_to_string(&meta_item.path),
81        });
82        return ::alloc::boxed::box_assume_init_into_vec_unsafe(::alloc::intrinsics::write_box_via_move(::alloc::boxed::Box::new_uninit(),
        [orig_item]))vec![orig_item];
83    };
84
85    let ast::Item { attrs, id: _, span: _, vis, kind, tokens: _ } = item.as_ref();
86    let (item_span, foreign_item_name) = match kind {
87        ItemKind::Fn(func) => (func.sig.span, func.ident),
88        ItemKind::Static(stat) => {
89            // See https://github.com/rust-lang/rust/issues/157649
90            if let Some(expr) = &stat.expr
91                && ecx.sess.target.is_like_darwin
92            {
93                ecx.dcx().emit_err(EiiStaticDefaultApple {
94                    span: expr.span,
95                    name: path_to_string(&meta_item.path),
96                });
97                return ::alloc::vec::Vec::new()vec![];
98            }
99
100            // Statics must have an explicit name for the eii
101            if meta_item.is_word() {
102                ecx.dcx().emit_err(EiiStaticArgumentRequired {
103                    span: eii_attr_span,
104                    name: path_to_string(&meta_item.path),
105                });
106                return ::alloc::vec::Vec::new()vec![];
107            }
108
109            // Mut statics are currently not supported
110            if stat.mutability == Mutability::Mut {
111                ecx.dcx().emit_err(EiiStaticMutable {
112                    span: eii_attr_span,
113                    name: path_to_string(&meta_item.path),
114                });
115            }
116
117            (item.span, stat.ident)
118        }
119        _ => {
120            ecx.dcx().emit_err(EiiSharedMacroTarget {
121                span: eii_attr_span,
122                name: path_to_string(&meta_item.path),
123            });
124            return ::alloc::boxed::box_assume_init_into_vec_unsafe(::alloc::intrinsics::write_box_via_move(::alloc::boxed::Box::new_uninit(),
        [Annotatable::Item(item)]))vec![Annotatable::Item(item)];
125        }
126    };
127
128    match kind {
129        ItemKind::Fn(func) => {
130            if func.eii_impl.is_some() {
131                ecx.dcx().emit_err(EiiBothDeclAndImpl { span: eii_attr_span });
132                return ::alloc::boxed::box_assume_init_into_vec_unsafe(::alloc::intrinsics::write_box_via_move(::alloc::boxed::Box::new_uninit(),
        [Annotatable::Item(item)]))vec![Annotatable::Item(item)];
133            }
134        }
135        ItemKind::Static(stat) => {
136            if stat.eii_impl.is_some() {
137                ecx.dcx().emit_err(EiiBothDeclAndImpl { span: eii_attr_span });
138                return ::alloc::boxed::box_assume_init_into_vec_unsafe(::alloc::intrinsics::write_box_via_move(::alloc::boxed::Box::new_uninit(),
        [Annotatable::Item(item)]))vec![Annotatable::Item(item)];
139            }
140        }
141        _ => {
    ::core::panicking::panic_fmt(format_args!("internal error: entered unreachable code: {0}",
            format_args!("Target was checked earlier")));
}unreachable!("Target was checked earlier"),
142    };
143
144    // only clone what we need
145    let attrs = attrs.clone();
146    let vis = vis.clone();
147
148    let attrs_from_decl =
149        filter_attrs_for_multiple_eii_attr(ecx, attrs, eii_attr_span, &meta_item.path);
150    let (macro_attrs, foreign_item_attrs) = split_attrs(ecx, item_span, attrs_from_decl);
151
152    let Ok(macro_name) = name_for_impl_macro(ecx, foreign_item_name, meta_item) else {
153        // we don't need to wrap in Annotatable::Stmt conditionally since
154        // EII can't be used on items in statement position
155        return ::alloc::boxed::box_assume_init_into_vec_unsafe(::alloc::intrinsics::write_box_via_move(::alloc::boxed::Box::new_uninit(),
        [Annotatable::Item(item)]))vec![Annotatable::Item(item)];
156    };
157
158    let mut module_items = Vec::new();
159
160    if let Some(default_impl) = generate_default_impl(
161        ecx,
162        kind,
163        impl_unsafe,
164        macro_name,
165        eii_attr_span,
166        item_span,
167        foreign_item_name,
168    ) {
169        module_items.push(default_impl);
170    }
171
172    module_items.push(generate_foreign_item(
173        ecx,
174        eii_attr_span,
175        item_span,
176        kind,
177        vis,
178        foreign_item_attrs,
179    ));
180    module_items.push(generate_attribute_macro_to_implement(
181        ecx,
182        eii_attr_span,
183        macro_name,
184        foreign_item_name,
185        impl_unsafe,
186        macro_attrs,
187    ));
188
189    // we don't need to wrap in Annotatable::Stmt conditionally since
190    // EII can't be used on items in statement position
191    module_items.into_iter().map(Annotatable::Item).collect()
192}
193
194fn split_attrs(
195    ecx: &mut ExtCtxt<'_>,
196    span: Span,
197    attrs: ThinVec<Attribute>,
198) -> (ThinVec<Attribute>, ThinVec<Attribute>) {
199    let mut macro_attributes = ThinVec::new();
200    let mut foreign_item_attributes = ThinVec::new();
201
202    for attr in attrs {
203        match attr.name() {
204            // If an eii is marked a lang item, that's because we want to call its declaration, so
205            // mark the foreign item as the lang item
206            Some(sym::lang) => foreign_item_attributes.push(attr),
207            // Deprecating an eii means deprecating the macro and the foreign item
208            Some(sym::deprecated) => {
209                foreign_item_attributes.push(attr.clone());
210                macro_attributes.push(attr);
211            }
212            // The stability of an EII affects the usage of the macro and calling the foreign item
213            Some(sym::stable) | Some(sym::unstable) => {
214                foreign_item_attributes.push(attr.clone());
215                macro_attributes.push(attr);
216            }
217            // `#[track_caller]` goes on the foreign item only: it's the symbol callers link
218            // against, so it must carry the flag for call sites to pass the caller location.
219            // Implementations derive it during codegen (see `EiiImpls` in `codegen_attrs.rs`),
220            // so it must not be routed onto the default impl here.
221            Some(sym::track_caller) => {
222                foreign_item_attributes.push(attr);
223            }
224            // Doc attributes should be forwarded to the macro and the foreign item, since those are
225            // the two items you interact with as a user.
226            // FIXME: idk yet how EIIs show up in docs, might want to customize
227            _ if attr.is_doc_comment() => {
228                foreign_item_attributes.push(attr.clone());
229                macro_attributes.push(attr);
230            }
231            Some(sym::eii) => {
    ::core::panicking::panic_fmt(format_args!("internal error: entered unreachable code: {0}",
            format_args!("should already be filtered out")));
}unreachable!("should already be filtered out"),
232            _ => {
233                ecx.dcx().emit_err(EiiAttributeNotSupported { span, attr_span: attr.span() });
234            }
235        }
236    }
237
238    (macro_attributes, foreign_item_attributes)
239}
240
241/// Decide on the name of the macro that can be used to implement the EII.
242/// This is either an explicitly given name, or the name of the item in the
243/// declaration of the EII.
244fn name_for_impl_macro(
245    ecx: &mut ExtCtxt<'_>,
246    item_ident: Ident,
247    meta_item: &MetaItem,
248) -> Result<Ident, ErrorGuaranteed> {
249    if meta_item.is_word() {
250        Ok(item_ident)
251    } else if let Some([first]) = meta_item.meta_item_list()
252        && let Some(m) = first.meta_item()
253        && m.path.segments.len() == 1
254    {
255        Ok(m.path.segments[0].ident)
256    } else {
257        Err(ecx.dcx().emit_err(EiiMacroExpectedMaxOneArgument {
258            span: meta_item.span,
259            name: path_to_string(&meta_item.path),
260        }))
261    }
262}
263
264/// Ensure that in the list of attrs, there's only a single `eii` attribute.
265fn filter_attrs_for_multiple_eii_attr(
266    ecx: &mut ExtCtxt<'_>,
267    attrs: ThinVec<Attribute>,
268    eii_attr_span: Span,
269    eii_attr_path: &Path,
270) -> ThinVec<Attribute> {
271    attrs
272        .into_iter()
273        .filter(|i| {
274            if i.has_name(sym::eii) {
275                ecx.dcx().emit_err(EiiOnlyOnce {
276                    span: i.span,
277                    first_span: eii_attr_span,
278                    name: path_to_string(eii_attr_path),
279                });
280                false
281            } else {
282                true
283            }
284        })
285        .collect()
286}
287
288fn generate_default_impl(
289    ecx: &mut ExtCtxt<'_>,
290    item_kind: &ItemKind,
291    impl_unsafe: bool,
292    macro_name: Ident,
293    eii_attr_span: Span,
294    item_span: Span,
295    foreign_item_name: Ident,
296) -> Option<Box<ast::Item>> {
297    let attrs = ThinVec::new();
298
299    match item_kind {
300        ItemKind::Fn(func) => {
301            func.body.as_ref()?;
302        }
303        ItemKind::Static(stat) => {
304            stat.expr.as_ref()?;
305        }
306        _ => {
    ::core::panicking::panic_fmt(format_args!("internal error: entered unreachable code: {0}",
            format_args!("Target was checked earlier")));
}unreachable!("Target was checked earlier"),
307    };
308
309    let eii_impl = Box::new(EiiImpl {
310        node_id: DUMMY_NODE_ID,
311        inner_span: macro_name.span,
312        eii_macro_path: ast::Path::from_ident(macro_name),
313        impl_safety: if impl_unsafe {
314            ast::Safety::Unsafe(eii_attr_span)
315        } else {
316            ast::Safety::Default
317        },
318        span: eii_attr_span,
319        is_default: true,
320        known_eii_macro_resolution: Some(ecx.path(
321            foreign_item_name.span,
322            // prefix self to explicitly escape the const block generated below
323            // NOTE: this is why EIIs can't be used on statements
324            ::alloc::boxed::box_assume_init_into_vec_unsafe(::alloc::intrinsics::write_box_via_move(::alloc::boxed::Box::new_uninit(),
        [Ident::from_str_and_span("self", foreign_item_name.span),
                foreign_item_name]))vec![Ident::from_str_and_span("self", foreign_item_name.span), foreign_item_name],
325        )),
326    });
327
328    let mut item_kind = item_kind.clone();
329    match &mut item_kind {
330        ItemKind::Fn(func) => {
331            if !func.eii_impl.is_none() {
    ::core::panicking::panic("assertion failed: func.eii_impl.is_none()")
};assert!(func.eii_impl.is_none());
332            func.eii_impl = Some(eii_impl);
333        }
334        ItemKind::Static(stat) => {
335            if !stat.eii_impl.is_none() {
    ::core::panicking::panic("assertion failed: stat.eii_impl.is_none()")
};assert!(stat.eii_impl.is_none());
336            stat.eii_impl = Some(eii_impl);
337        }
338        _ => {
    ::core::panicking::panic_fmt(format_args!("internal error: entered unreachable code: {0}",
            format_args!("Target was checked earlier")));
}unreachable!("Target was checked earlier"),
339    };
340
341    let anon_mod = |span: Span, stmts: ThinVec<ast::Stmt>| {
342        let unit = ecx.ty(item_span, ast::TyKind::Tup(ThinVec::new()));
343        let underscore = Ident::new(kw::Underscore, item_span);
344        ecx.item_const(
345            span,
346            underscore,
347            unit,
348            Some(ecx.expr_block(ecx.block(span, stmts))),
349            ast::ConstItemKind::Body,
350        )
351    };
352
353    // const _: () = {
354    //     <orig item>
355    // }
356    Some(anon_mod(
357        item_span,
358        {
    let len = [()].len();
    let mut vec = ::thin_vec::ThinVec::with_capacity(len);
    vec.push(ecx.stmt_item(item_span, ecx.item(item_span, attrs, item_kind)));
    vec
}thin_vec![ecx.stmt_item(item_span, ecx.item(item_span, attrs, item_kind))],
359    ))
360}
361
362/// Generates a foreign item, like
363///
364/// ```rust, ignore
365/// extern "…" { safe fn item(); }
366/// ```
367fn generate_foreign_item(
368    ecx: &mut ExtCtxt<'_>,
369    eii_attr_span: Span,
370    item_span: Span,
371    item_kind: &ItemKind,
372    vis: Visibility,
373    attrs_from_decl: ThinVec<Attribute>,
374) -> Box<ast::Item> {
375    let mut foreign_item_attrs = attrs_from_decl;
376
377    // Add the rustc_eii_foreign_item on the foreign item. Usually, foreign items are mangled.
378    // This attribute makes sure that we later know that this foreign item's symbol should not be.
379    foreign_item_attrs.push(ecx.attr_word(sym::rustc_eii_foreign_item, eii_attr_span));
380
381    // We set the abi to the default "rust" abi, which can be overridden by `generate_foreign_func`,
382    // if a specific abi was specified on the EII function
383    let mut abi = Some(ast::StrLit {
384        symbol: sym::Rust,
385        suffix: None,
386        symbol_unescaped: sym::Rust,
387        style: ast::StrStyle::Cooked,
388        span: eii_attr_span,
389    });
390    let foreign_kind = match item_kind {
391        ItemKind::Fn(func) => generate_foreign_func(func.clone(), &mut abi),
392        ItemKind::Static(stat) => generate_foreign_static(stat.clone()),
393        _ => {
    ::core::panicking::panic_fmt(format_args!("internal error: entered unreachable code: {0}",
            format_args!("Target was checked earlier")));
}unreachable!("Target was checked earlier"),
394    };
395
396    ecx.item(
397        eii_attr_span,
398        ThinVec::new(),
399        ast::ItemKind::ForeignMod(ast::ForeignMod {
400            extern_span: eii_attr_span,
401            safety: ast::Safety::Unsafe(eii_attr_span),
402            abi,
403            items: From::from([Box::new(ast::ForeignItem {
404                attrs: foreign_item_attrs,
405                id: ast::DUMMY_NODE_ID,
406                span: item_span,
407                vis,
408                kind: foreign_kind,
409                tokens: None,
410            })]),
411        }),
412    )
413}
414
415fn generate_foreign_func(
416    mut func: Box<ast::Fn>,
417    abi: &mut Option<ast::StrLit>,
418) -> ast::ForeignItemKind {
419    match func.sig.header.ext {
420        // extern "X" fn  =>  extern "X" {}
421        ast::Extern::Explicit(lit, _) => *abi = Some(lit),
422        // extern fn  =>  extern {}
423        ast::Extern::Implicit(_) => *abi = None,
424        // no abi was specified, so we keep the default
425        ast::Extern::None => {}
426    };
427
428    // ABI has been moved to the extern {} block, so we remove it from the fn item.
429    func.sig.header.ext = ast::Extern::None;
430    func.body = None;
431
432    // And mark safe functions explicitly as `safe fn`.
433    if func.sig.header.safety == ast::Safety::Default {
434        func.sig.header.safety = ast::Safety::Safe(func.sig.span);
435    }
436
437    ast::ForeignItemKind::Fn(func)
438}
439
440fn generate_foreign_static(mut stat: Box<ast::StaticItem>) -> ast::ForeignItemKind {
441    if stat.safety == ast::Safety::Default {
442        stat.safety = ast::Safety::Safe(stat.ident.span);
443    }
444
445    stat.expr = None;
446
447    ast::ForeignItemKind::Static(stat)
448}
449
450/// Generate a stub macro (a bit like in core) that will roughly look like:
451///
452/// ```rust, ignore, example
453/// // Since this a stub macro, the actual code that expands it lives in the compiler.
454/// // This attribute tells the compiler that
455/// #[builtin_macro(eii_shared_macro)]
456/// // the metadata to link this macro to the generated foreign item.
457/// #[eii_declaration(<related_foreign_item>)]
458/// macro macro_name { () => {} }
459/// ```
460fn generate_attribute_macro_to_implement(
461    ecx: &mut ExtCtxt<'_>,
462    span: Span,
463    macro_name: Ident,
464    foreign_item_name: Ident,
465    impl_unsafe: bool,
466    attrs_from_decl: ThinVec<Attribute>,
467) -> Box<ast::Item> {
468    let mut macro_attrs = attrs_from_decl;
469
470    // Avoid "missing stability attribute" errors for eiis in std. See #146993.
471    macro_attrs.push(ecx.attr_name_value_str(sym::rustc_macro_transparency, sym::semiopaque, span));
472
473    // #[builtin_macro(eii_shared_macro)]
474    macro_attrs.push(ecx.attr_nested_word(sym::rustc_builtin_macro, sym::eii_shared_macro, span));
475
476    // cant use ecx methods here to construct item since we need it to be public
477    Box::new(ast::Item {
478        attrs: macro_attrs,
479        id: ast::DUMMY_NODE_ID,
480        span,
481        // pub
482        vis: ast::Visibility { span, kind: ast::VisibilityKind::Public },
483        kind: ast::ItemKind::MacroDef(
484            // macro macro_name
485            macro_name,
486            ast::MacroDef {
487                // { () => {} }
488                body: Box::new(ast::DelimArgs {
489                    dspan: DelimSpan::from_single(span),
490                    delim: Delimiter::Brace,
491                    tokens: TokenStream::from_iter([
492                        TokenTree::Delimited(
493                            DelimSpan::from_single(span),
494                            DelimSpacing::new(Spacing::Alone, Spacing::Alone),
495                            Delimiter::Parenthesis,
496                            TokenStream::default(),
497                        ),
498                        TokenTree::token_alone(TokenKind::FatArrow, span),
499                        TokenTree::Delimited(
500                            DelimSpan::from_single(span),
501                            DelimSpacing::new(Spacing::Alone, Spacing::Alone),
502                            Delimiter::Brace,
503                            TokenStream::default(),
504                        ),
505                    ]),
506                }),
507                macro_rules: false,
508                // #[eii_declaration(foreign_item_ident)]
509                eii_declaration: Some(ast::EiiDecl {
510                    foreign_item: ast::Path::from_ident(foreign_item_name),
511                    impl_unsafe,
512                }),
513            },
514        ),
515        tokens: None,
516    })
517}
518
519pub(crate) fn eii_declaration(
520    ecx: &mut ExtCtxt<'_>,
521    span: Span,
522    meta_item: &ast::MetaItem,
523    mut item: Annotatable,
524) -> Vec<Annotatable> {
525    let i = if let Annotatable::Item(ref mut item) = item {
526        item
527    } else if let Annotatable::Stmt(ref mut stmt) = item
528        && let StmtKind::Item(ref mut item) = stmt.kind
529    {
530        item
531    } else {
532        ecx.dcx().emit_err(EiiExternTargetExpectedMacro { span });
533        return ::alloc::boxed::box_assume_init_into_vec_unsafe(::alloc::intrinsics::write_box_via_move(::alloc::boxed::Box::new_uninit(),
        [item]))vec![item];
534    };
535
536    let ItemKind::MacroDef(_, d) = &mut i.kind else {
537        ecx.dcx().emit_err(EiiExternTargetExpectedMacro { span });
538        return ::alloc::boxed::box_assume_init_into_vec_unsafe(::alloc::intrinsics::write_box_via_move(::alloc::boxed::Box::new_uninit(),
        [item]))vec![item];
539    };
540
541    let Some(list) = meta_item.meta_item_list() else {
542        ecx.dcx().emit_err(EiiExternTargetExpectedList { span: meta_item.span });
543        return ::alloc::boxed::box_assume_init_into_vec_unsafe(::alloc::intrinsics::write_box_via_move(::alloc::boxed::Box::new_uninit(),
        [item]))vec![item];
544    };
545
546    if list.len() > 2 {
547        ecx.dcx().emit_err(EiiExternTargetExpectedList { span: meta_item.span });
548        return ::alloc::boxed::box_assume_init_into_vec_unsafe(::alloc::intrinsics::write_box_via_move(::alloc::boxed::Box::new_uninit(),
        [item]))vec![item];
549    }
550
551    let Some(extern_item_path) = list.get(0).and_then(|i| i.meta_item()).map(|i| i.path.clone())
552    else {
553        ecx.dcx().emit_err(EiiExternTargetExpectedList { span: meta_item.span });
554        return ::alloc::boxed::box_assume_init_into_vec_unsafe(::alloc::intrinsics::write_box_via_move(::alloc::boxed::Box::new_uninit(),
        [item]))vec![item];
555    };
556
557    let impl_unsafe = if let Some(i) = list.get(1) {
558        if i.lit().and_then(|i| i.kind.str()).is_some_and(|i| i == kw::Unsafe) {
559            true
560        } else {
561            ecx.dcx().emit_err(EiiExternTargetExpectedUnsafe { span: i.span() });
562            return ::alloc::boxed::box_assume_init_into_vec_unsafe(::alloc::intrinsics::write_box_via_move(::alloc::boxed::Box::new_uninit(),
        [item]))vec![item];
563        }
564    } else {
565        false
566    };
567
568    d.eii_declaration = Some(EiiDecl { foreign_item: extern_item_path, impl_unsafe });
569
570    // Return the original item and the new methods.
571    ::alloc::boxed::box_assume_init_into_vec_unsafe(::alloc::intrinsics::write_box_via_move(::alloc::boxed::Box::new_uninit(),
        [item]))vec![item]
572}
573
574/// all Eiis share this function as the implementation for their attribute.
575pub(crate) fn eii_shared_macro(
576    ecx: &mut ExtCtxt<'_>,
577    span: Span,
578    meta_item: &ast::MetaItem,
579    mut item: Annotatable,
580) -> Vec<Annotatable> {
581    let i = if let Annotatable::Item(ref mut item) = item {
582        item
583    } else if let Annotatable::Stmt(ref mut stmt) = item
584        && let StmtKind::Item(ref mut item) = stmt.kind
585    {
586        item
587    } else {
588        ecx.dcx().emit_err(EiiSharedMacroTarget { span, name: path_to_string(&meta_item.path) });
589        return ::alloc::boxed::box_assume_init_into_vec_unsafe(::alloc::intrinsics::write_box_via_move(::alloc::boxed::Box::new_uninit(),
        [item]))vec![item];
590    };
591
592    let eii_impl = match &mut i.kind {
593        ItemKind::Fn(func) => &mut func.eii_impl,
594        ItemKind::Static(stat) => &mut stat.eii_impl,
595        _ => {
596            ecx.dcx()
597                .emit_err(EiiSharedMacroTarget { span, name: path_to_string(&meta_item.path) });
598            return ::alloc::boxed::box_assume_init_into_vec_unsafe(::alloc::intrinsics::write_box_via_move(::alloc::boxed::Box::new_uninit(),
        [item]))vec![item];
599        }
600    };
601
602    let is_default = if meta_item.is_word() {
603        false
604    } else if let Some([first]) = meta_item.meta_item_list()
605        && let Some(m) = first.meta_item()
606        && m.path.segments.len() == 1
607    {
608        m.path.segments[0].ident.name == kw::Default
609    } else {
610        ecx.dcx().emit_err(EiiMacroExpectedMaxOneArgument {
611            span: meta_item.span,
612            name: path_to_string(&meta_item.path),
613        });
614        return ::alloc::boxed::box_assume_init_into_vec_unsafe(::alloc::intrinsics::write_box_via_move(::alloc::boxed::Box::new_uninit(),
        [item]))vec![item];
615    };
616
617    if eii_impl.is_some() {
618        ecx.dcx().emit_err(EiiMultipleImplementations { span });
619    }
620    *eii_impl = Some(Box::new(EiiImpl {
621        node_id: DUMMY_NODE_ID,
622        inner_span: meta_item.path.span,
623        eii_macro_path: meta_item.path.clone(),
624        impl_safety: meta_item.unsafety,
625        span,
626        is_default,
627        known_eii_macro_resolution: None,
628    }));
629
630    ::alloc::boxed::box_assume_init_into_vec_unsafe(::alloc::intrinsics::write_box_via_move(::alloc::boxed::Box::new_uninit(),
        [item]))vec![item]
631}