@@ -27,6 +27,16 @@ mod llvm_enzyme {
2727 use crate :: errors;
2828 use crate :: generic:: ty:: PathKind ;
2929
30+ pub ( crate ) fn outer_normal_attr (
31+ kind : & P < rustc_ast:: NormalAttr > ,
32+ id : rustc_ast:: AttrId ,
33+ span : Span ,
34+ ) -> rustc_ast:: Attribute {
35+ let style = rustc_ast:: AttrStyle :: Outer ;
36+ let kind = rustc_ast:: AttrKind :: Normal ( kind. clone ( ) ) ;
37+ rustc_ast:: Attribute { kind, id, style, span }
38+ }
39+
3040 // If we have a default `()` return type or explicitley `()` return type,
3141 // then we often can skip doing some work.
3242 fn has_ret ( ty : & FnRetTy ) -> bool {
@@ -347,28 +357,18 @@ mod llvm_enzyme {
347357 } ;
348358 let inline_never_attr = P ( ast:: NormalAttr { item : inline_item, tokens : None } ) ;
349359 let new_id = ecx. sess . psess . attr_id_generator . mk_attr_id ( ) ;
350- let attr: ast:: Attribute = ast:: Attribute {
351- kind : ast:: AttrKind :: Normal ( rustc_ad_attr. clone ( ) ) ,
352- id : new_id,
353- style : ast:: AttrStyle :: Outer ,
354- span,
355- } ;
360+ let attr = outer_normal_attr ( & rustc_ad_attr, new_id, span) ;
356361 let new_id = ecx. sess . psess . attr_id_generator . mk_attr_id ( ) ;
357- let inline_never: ast:: Attribute = ast:: Attribute {
358- kind : ast:: AttrKind :: Normal ( inline_never_attr) ,
359- id : new_id,
360- style : ast:: AttrStyle :: Outer ,
361- span,
362- } ;
362+ let inline_never = outer_normal_attr ( & inline_never_attr, new_id, span) ;
363363
364364 // We're avoid duplicating the attributes `#[rustc_autodiff]` and `#[inline(never)]`.
365- fn same_attribute ( attr : & ast:: AttrKind , item : & ast:: AttrKind ) -> bool {
365+ fn is_same ( attr : & ast:: AttrKind , item : & ast:: AttrKind ) -> bool {
366366 match ( attr, item) {
367367 ( ast:: AttrKind :: Normal ( a) , ast:: AttrKind :: Normal ( b) ) => {
368- let a = & a. item . path ;
369- let b = & b. item . path ;
370- a. segments . len ( ) == b. segments . len ( )
371- && a. segments . iter ( ) . zip ( b. segments . iter ( ) ) . all ( |( a, b) | a. ident == b. ident )
368+ let a = & a. item . path . segments ;
369+ let b = & b. item . path . segments ;
370+ a. len ( ) == b. len ( )
371+ && a. iter ( ) . zip ( b. iter ( ) ) . all ( |( a, b) | a. ident == b. ident )
372372 } ,
373373 _ => false ,
374374 }
@@ -377,19 +377,19 @@ mod llvm_enzyme {
377377 // Don't add it multiple times:
378378 let orig_annotatable: Annotatable = match item {
379379 Annotatable :: Item ( ref mut iitem) => {
380- if !iitem. attrs . iter ( ) . any ( |a| same_attribute ( & a. kind , & attr. kind ) ) {
380+ if !iitem. attrs . iter ( ) . any ( |a| is_same ( & a. kind , & attr. kind ) ) {
381381 iitem. attrs . push ( attr) ;
382382 }
383- if !iitem. attrs . iter ( ) . any ( |a| same_attribute ( & a. kind , & inline_never. kind ) ) {
383+ if !iitem. attrs . iter ( ) . any ( |a| is_same ( & a. kind , & inline_never. kind ) ) {
384384 iitem. attrs . push ( inline_never. clone ( ) ) ;
385385 }
386386 Annotatable :: Item ( iitem. clone ( ) )
387387 }
388388 Annotatable :: AssocItem ( ref mut assoc_item, i @ Impl ) => {
389- if !assoc_item. attrs . iter ( ) . any ( |a| same_attribute ( & a. kind , & attr. kind ) ) {
389+ if !assoc_item. attrs . iter ( ) . any ( |a| is_same ( & a. kind , & attr. kind ) ) {
390390 assoc_item. attrs . push ( attr) ;
391391 }
392- if !assoc_item. attrs . iter ( ) . any ( |a| same_attribute ( & a. kind , & inline_never. kind ) ) {
392+ if !assoc_item. attrs . iter ( ) . any ( |a| is_same ( & a. kind , & inline_never. kind ) ) {
393393 assoc_item. attrs . push ( inline_never. clone ( ) ) ;
394394 }
395395 Annotatable :: AssocItem ( assoc_item. clone ( ) , i)
@@ -404,12 +404,7 @@ mod llvm_enzyme {
404404 delim : rustc_ast:: token:: Delimiter :: Parenthesis ,
405405 tokens : ts,
406406 } ) ;
407- let d_attr: ast:: Attribute = ast:: Attribute {
408- kind : ast:: AttrKind :: Normal ( rustc_ad_attr. clone ( ) ) ,
409- id : new_id,
410- style : ast:: AttrStyle :: Outer ,
411- span,
412- } ;
407+ let d_attr = outer_normal_attr ( & rustc_ad_attr, new_id, span) ;
413408
414409 let d_annotatable = if is_impl {
415410 let assoc_item: AssocItemKind = ast:: AssocItemKind :: Fn ( asdf) ;
0 commit comments