@@ -282,22 +282,35 @@ mod llvm_enzyme {
282282 span,
283283 } ;
284284
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+
285298 // Don't add it multiple times:
286299 let orig_annotatable: Annotatable = match item {
287300 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 ) ) {
289302 iitem. attrs . push ( attr) ;
290303 }
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 ) ) {
292305 iitem. attrs . push ( inline_never. clone ( ) ) ;
293306 }
294307 Annotatable :: Item ( iitem. clone ( ) )
295308 }
296309 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 ) ) {
298311 assoc_item. attrs . push ( attr) ;
299312 }
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 ) ) {
301314 assoc_item. attrs . push ( inline_never. clone ( ) ) ;
302315 }
303316 Annotatable :: AssocItem ( assoc_item. clone ( ) , i)
0 commit comments