Skip to content

Commit 0d066fb

Browse files
committed
attempt adding attributes via annotations
1 parent 94c67b8 commit 0d066fb

File tree

1 file changed

+53
-38
lines changed

1 file changed

+53
-38
lines changed

bindgen/codegen/mod.rs

Lines changed: 53 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1073,20 +1073,18 @@ impl CodeGenerator for Type {
10731073
kind: AttributeItemKind::Struct,
10741074
})
10751075
});
1076-
attributes.extend(
1077-
custom_attributes
1078-
.iter()
1079-
.map(|s| s.parse().unwrap()),
1080-
);
1076+
1077+
// HACK: Smuggle annotations back into the system for type aliases
1078+
item.annotations()
1079+
.attributes()
1080+
.extend(custom_attributes.iter().map(|s| s.parse().unwrap()));
1081+
10811082
attributes.extend(
10821083
item.annotations().attributes()
10831084
.iter()
10841085
.map(|s| s.parse().unwrap()),
10851086
);
1086-
10871087

1088-
1089-
10901088
quote! {
10911089
#( #attributes )*
10921090
pub struct #rust_name
@@ -2530,13 +2528,6 @@ impl CodeGenerator for CompInfo {
25302528
attributes.push(attributes::derives(&derives));
25312529
}
25322530

2533-
attributes.extend(
2534-
item.annotations()
2535-
.attributes()
2536-
.iter()
2537-
.map(|s| s.parse().unwrap()),
2538-
);
2539-
25402531
let custom_attributes = ctx.options().all_callbacks(|cb| {
25412532
cb.add_attributes(&AttributeInfo {
25422533
name: &canonical_name,
@@ -2547,8 +2538,18 @@ impl CodeGenerator for CompInfo {
25472538
},
25482539
})
25492540
});
2550-
attributes.extend(custom_attributes.iter().map(|s| s.parse().unwrap()));
2541+
// HACK: Smuggle annotations back into the system for type aliases
2542+
item.annotations()
2543+
.attributes()
2544+
.extend(custom_attributes.iter().map(|s| s.parse().unwrap()));
25512545

2546+
attributes.extend(
2547+
item.annotations()
2548+
.attributes()
2549+
.iter()
2550+
.map(|s| s.parse().unwrap()),
2551+
);
2552+
25522553
if item.must_use(ctx) {
25532554
attributes.push(attributes::must_use());
25542555
}
@@ -3155,13 +3156,6 @@ impl Method {
31553156
let block = ctx.wrap_unsafe_ops(quote! ( #( #stmts );*));
31563157

31573158
let mut attrs = vec![attributes::inline()];
3158-
attrs.extend(
3159-
function_item
3160-
.annotations()
3161-
.attributes()
3162-
.iter()
3163-
.map(|s| s.parse().unwrap()),
3164-
);
31653159

31663160
let custom_attributes = ctx.options().all_callbacks(|cb| {
31673161
cb.add_attributes(&AttributeInfo {
@@ -3171,7 +3165,19 @@ impl Method {
31713165
)),
31723166
})
31733167
});
3174-
attrs.extend(custom_attributes.iter().map(|s| s.parse().unwrap()));
3168+
3169+
// HACK: Smuggle annotations back into the system for type aliases
3170+
function_item.annotations()
3171+
.attributes()
3172+
.extend(custom_attributes.iter().map(|s| s.parse().unwrap()));
3173+
3174+
attrs.extend(
3175+
function_item
3176+
.annotations()
3177+
.attributes()
3178+
.iter()
3179+
.map(|s| s.parse().unwrap()),
3180+
);
31753181

31763182
if signature.must_use() {
31773183
attrs.push(attributes::must_use());
@@ -3741,12 +3747,6 @@ impl CodeGenerator for Enum {
37413747
// In most cases this will be a no-op, since custom_derives will be empty.
37423748
derives.extend(custom_derives.iter().map(|s| s.as_str()));
37433749

3744-
attrs.extend(
3745-
item.annotations()
3746-
.attributes()
3747-
.iter()
3748-
.map(|s| s.parse().unwrap()),
3749-
);
37503750

37513751
// The custom attribute callback may return a list of attributes;
37523752
// add them to the end of the list.
@@ -3756,8 +3756,18 @@ impl CodeGenerator for Enum {
37563756
kind: AttributeItemKind::Enum,
37573757
})
37583758
});
3759-
attrs.extend(custom_attributes.iter().map(|s| s.parse().unwrap()));
37603759

3760+
// HACK: Smuggle annotations back into the system for type aliases
3761+
item.annotations()
3762+
.attributes()
3763+
.extend(custom_attributes.iter().map(|s| s.parse().unwrap()));
3764+
3765+
attrs.extend(
3766+
item.annotations()
3767+
.attributes()
3768+
.iter()
3769+
.map(|s| s.parse().unwrap()),
3770+
);
37613771
attrs.push(attributes::derives(&derives));
37623772
}
37633773

@@ -4617,20 +4627,25 @@ impl CodeGenerator for Function {
46174627
}
46184628

46194629
let mut attributes = vec![];
4620-
attributes.extend(
4621-
item.annotations()
4622-
.attributes()
4623-
.iter()
4624-
.map(|s| s.parse().unwrap()),
4625-
);
46264630

46274631
let custom_attributes = ctx.options().all_callbacks(|cb| {
46284632
cb.add_attributes(&AttributeInfo {
46294633
name: &canonical_name,
46304634
kind: AttributeItemKind::Function(self.kind()),
46314635
})
46324636
});
4633-
attributes.extend(custom_attributes.iter().map(|s| s.parse().unwrap()));
4637+
4638+
// HACK: Smuggle annotations back into the system for type aliases
4639+
item.annotations()
4640+
.attributes()
4641+
.extend(custom_attributes.iter().map(|s| s.parse().unwrap()));
4642+
4643+
attributes.extend(
4644+
item.annotations()
4645+
.attributes()
4646+
.iter()
4647+
.map(|s| s.parse().unwrap()),
4648+
);
46344649

46354650
if true {
46364651
let must_use = signature.must_use() || {

0 commit comments

Comments
 (0)