@@ -361,22 +361,35 @@ mod llvm_enzyme {
361
361
span,
362
362
} ;
363
363
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
+
364
377
// Don't add it multiple times:
365
378
let orig_annotatable: Annotatable = match item {
366
379
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 ) ) {
368
381
iitem. attrs . push ( attr) ;
369
382
}
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 ) ) {
371
384
iitem. attrs . push ( inline_never. clone ( ) ) ;
372
385
}
373
386
Annotatable :: Item ( iitem. clone ( ) )
374
387
}
375
388
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 ) ) {
377
390
assoc_item. attrs . push ( attr) ;
378
391
}
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 ) ) {
380
393
assoc_item. attrs . push ( inline_never. clone ( ) ) ;
381
394
}
382
395
Annotatable :: AssocItem ( assoc_item. clone ( ) , i)
0 commit comments