@@ -361,22 +361,35 @@ mod llvm_enzyme {
361361 span,
362362 } ;
363363
364+ // We're avoid duplicating the attributes `#[rustc_autodiff]` and `#[inline(never)]`.
365+ fn same_attribute ( attr : & ast:: AttrKind , item : & ast:: AttrKind ) -> bool {
366+ match ( attr, item) {
367+ ( 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 )
372+ } ,
373+ _ => false ,
374+ }
375+ }
376+
364377 // Don't add it multiple times:
365378 let orig_annotatable: Annotatable = match item {
366379 Annotatable :: Item ( ref mut iitem) => {
367- if !iitem. attrs . iter ( ) . any ( |a| a . id == attr. id ) {
380+ if !iitem. attrs . iter ( ) . any ( |a| same_attribute ( & a . kind , & attr. kind ) ) {
368381 iitem. attrs . push ( attr) ;
369382 }
370- if !iitem. attrs . iter ( ) . any ( |a| a . id == inline_never. id ) {
383+ if !iitem. attrs . iter ( ) . any ( |a| same_attribute ( & a . kind , & inline_never. kind ) ) {
371384 iitem. attrs . push ( inline_never. clone ( ) ) ;
372385 }
373386 Annotatable :: Item ( iitem. clone ( ) )
374387 }
375388 Annotatable :: AssocItem ( ref mut assoc_item, i @ Impl ) => {
376- if !assoc_item. attrs . iter ( ) . any ( |a| a . id == attr. id ) {
389+ if !assoc_item. attrs . iter ( ) . any ( |a| same_attribute ( & a . kind , & attr. kind ) ) {
377390 assoc_item. attrs . push ( attr) ;
378391 }
379- if !assoc_item. attrs . iter ( ) . any ( |a| a . id == inline_never. id ) {
392+ if !assoc_item. attrs . iter ( ) . any ( |a| same_attribute ( & a . kind , & inline_never. kind ) ) {
380393 assoc_item. attrs . push ( inline_never. clone ( ) ) ;
381394 }
382395 Annotatable :: AssocItem ( assoc_item. clone ( ) , i)
0 commit comments