@@ -25,6 +25,16 @@ mod llvm_enzyme {
2525
2626 use crate :: errors;
2727
28+ pub ( crate ) fn outer_normal_attr (
29+ kind : & P < rustc_ast:: NormalAttr > ,
30+ id : rustc_ast:: AttrId ,
31+ span : Span ,
32+ ) -> rustc_ast:: Attribute {
33+ let style = rustc_ast:: AttrStyle :: Outer ;
34+ let kind = rustc_ast:: AttrKind :: Normal ( kind. clone ( ) ) ;
35+ rustc_ast:: Attribute { kind, id, style, span }
36+ }
37+
2838 // If we have a default `()` return type or explicitley `()` return type,
2939 // then we often can skip doing some work.
3040 fn has_ret ( ty : & FnRetTy ) -> bool {
@@ -268,19 +278,9 @@ mod llvm_enzyme {
268278 } ;
269279 let inline_never_attr = P ( ast:: NormalAttr { item : inline_item, tokens : None } ) ;
270280 let new_id = ecx. sess . psess . attr_id_generator . mk_attr_id ( ) ;
271- let attr: ast:: Attribute = ast:: Attribute {
272- kind : ast:: AttrKind :: Normal ( rustc_ad_attr. clone ( ) ) ,
273- id : new_id,
274- style : ast:: AttrStyle :: Outer ,
275- span,
276- } ;
281+ let attr = outer_normal_attr ( & rustc_ad_attr, new_id, span) ;
277282 let new_id = ecx. sess . psess . attr_id_generator . mk_attr_id ( ) ;
278- let inline_never: ast:: Attribute = ast:: Attribute {
279- kind : ast:: AttrKind :: Normal ( inline_never_attr) ,
280- id : new_id,
281- style : ast:: AttrStyle :: Outer ,
282- span,
283- } ;
283+ let inline_never = outer_normal_attr ( & inline_never_attr, new_id, span) ;
284284
285285 // We're avoid duplicating the attributes `#[rustc_autodiff]` and `#[inline(never)]`.
286286 fn same_attribute ( attr : & ast:: AttrKind , item : & ast:: AttrKind ) -> bool {
@@ -325,13 +325,7 @@ mod llvm_enzyme {
325325 delim : rustc_ast:: token:: Delimiter :: Parenthesis ,
326326 tokens : ts,
327327 } ) ;
328- let d_attr: ast:: Attribute = ast:: Attribute {
329- kind : ast:: AttrKind :: Normal ( rustc_ad_attr. clone ( ) ) ,
330- id : new_id,
331- style : ast:: AttrStyle :: Outer ,
332- span,
333- } ;
334-
328+ let d_attr = outer_normal_attr ( & rustc_ad_attr, new_id, span) ;
335329 let d_annotatable = if is_impl {
336330 let assoc_item: AssocItemKind = ast:: AssocItemKind :: Fn ( asdf) ;
337331 let d_fn = P ( ast:: AssocItem {
0 commit comments