@@ -27,6 +27,16 @@ mod llvm_enzyme {
27
27
use crate :: errors;
28
28
use crate :: generic:: ty:: PathKind ;
29
29
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
+
30
40
// If we have a default `()` return type or explicitley `()` return type,
31
41
// then we often can skip doing some work.
32
42
fn has_ret ( ty : & FnRetTy ) -> bool {
@@ -347,28 +357,18 @@ mod llvm_enzyme {
347
357
} ;
348
358
let inline_never_attr = P ( ast:: NormalAttr { item : inline_item, tokens : None } ) ;
349
359
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) ;
356
361
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) ;
363
363
364
364
// 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 {
366
366
match ( attr, item) {
367
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 )
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 )
372
372
} ,
373
373
_ => false ,
374
374
}
@@ -377,19 +377,19 @@ mod llvm_enzyme {
377
377
// Don't add it multiple times:
378
378
let orig_annotatable: Annotatable = match item {
379
379
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 ) ) {
381
381
iitem. attrs . push ( attr) ;
382
382
}
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 ) ) {
384
384
iitem. attrs . push ( inline_never. clone ( ) ) ;
385
385
}
386
386
Annotatable :: Item ( iitem. clone ( ) )
387
387
}
388
388
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 ) ) {
390
390
assoc_item. attrs . push ( attr) ;
391
391
}
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 ) ) {
393
393
assoc_item. attrs . push ( inline_never. clone ( ) ) ;
394
394
}
395
395
Annotatable :: AssocItem ( assoc_item. clone ( ) , i)
@@ -404,12 +404,7 @@ mod llvm_enzyme {
404
404
delim : rustc_ast:: token:: Delimiter :: Parenthesis ,
405
405
tokens : ts,
406
406
} ) ;
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) ;
413
408
414
409
let d_annotatable = if is_impl {
415
410
let assoc_item: AssocItemKind = ast:: AssocItemKind :: Fn ( asdf) ;
0 commit comments