@@ -282,22 +282,35 @@ mod llvm_enzyme {
282
282
span,
283
283
} ;
284
284
285
+ // We're avoid duplicating the attributes `#[rustc_autodiff]` and `#[inline(never)]`.
286
+ fn same_attribute ( attr : & ast:: AttrKind , item : & ast:: AttrKind ) -> bool {
287
+ match ( attr, item) {
288
+ ( ast:: AttrKind :: Normal ( a) , ast:: AttrKind :: Normal ( b) ) => {
289
+ let a = & a. item . path ;
290
+ let b = & b. item . path ;
291
+ a. segments . len ( ) == b. segments . len ( )
292
+ && a. segments . iter ( ) . zip ( b. segments . iter ( ) ) . all ( |( a, b) | a. ident == b. ident )
293
+ }
294
+ _ => false ,
295
+ }
296
+ }
297
+
285
298
// Don't add it multiple times:
286
299
let orig_annotatable: Annotatable = match item {
287
300
Annotatable :: Item ( ref mut iitem) => {
288
- if !iitem. attrs . iter ( ) . any ( |a| a . id == attr. id ) {
301
+ if !iitem. attrs . iter ( ) . any ( |a| same_attribute ( & a . kind , & attr. kind ) ) {
289
302
iitem. attrs . push ( attr) ;
290
303
}
291
- if !iitem. attrs . iter ( ) . any ( |a| a . id == inline_never. id ) {
304
+ if !iitem. attrs . iter ( ) . any ( |a| same_attribute ( & a . kind , & inline_never. kind ) ) {
292
305
iitem. attrs . push ( inline_never. clone ( ) ) ;
293
306
}
294
307
Annotatable :: Item ( iitem. clone ( ) )
295
308
}
296
309
Annotatable :: AssocItem ( ref mut assoc_item, i @ Impl ) => {
297
- if !assoc_item. attrs . iter ( ) . any ( |a| a . id == attr. id ) {
310
+ if !assoc_item. attrs . iter ( ) . any ( |a| same_attribute ( & a . kind , & attr. kind ) ) {
298
311
assoc_item. attrs . push ( attr) ;
299
312
}
300
- if !assoc_item. attrs . iter ( ) . any ( |a| a . id == inline_never. id ) {
313
+ if !assoc_item. attrs . iter ( ) . any ( |a| same_attribute ( & a . kind , & inline_never. kind ) ) {
301
314
assoc_item. attrs . push ( inline_never. clone ( ) ) ;
302
315
}
303
316
Annotatable :: AssocItem ( assoc_item. clone ( ) , i)
0 commit comments