Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions bindgen-tests/tests/expectations/tests/field_attributes.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions bindgen-tests/tests/headers/field_attributes.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
struct S {
/// <div rustbindgen attribute="#[deprecated] #[cfg(not(any(foo, bar)))]"></div>
int field_1;
/// <div rustbindgen attribute="#[cfg(not(baz))]"></div>
char field_2;
};
10 changes: 10 additions & 0 deletions bindgen/codegen/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1567,19 +1567,29 @@ impl FieldCodegen<'_> for FieldData {
let accessor_kind =
self.annotations().accessor_kind().unwrap_or(accessor_kind);

let attributes: Vec<proc_macro2::TokenStream> = self
.annotations()
.attributes()
.iter()
.map(|s| s.parse().unwrap())
.collect::<Vec<_>>();

match visibility {
FieldVisibilityKind::Private => {
field.append_all(quote! {
#( #attributes )*
#field_ident : #ty ,
});
}
FieldVisibilityKind::PublicCrate => {
field.append_all(quote! {
#( #attributes )*
pub(crate) #field_ident : #ty ,
});
}
FieldVisibilityKind::Public => {
field.append_all(quote! {
#( #attributes )*
pub #field_ident : #ty ,
});
}
Expand Down
2 changes: 1 addition & 1 deletion bindgen/ir/annotations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ pub(crate) struct Annotations {
constify_enum_variant: bool,
/// List of explicit derives for this type.
derives: Vec<String>,
/// List of explicit attributes for this type.
/// List of explicit attributes for this type/field.
attributes: Vec<String>,
}

Expand Down
Loading