Skip to content

Commit

Permalink
Add FieldInfo::field_type_name
Browse files Browse the repository at this point in the history
The relevance of making a ield private may depend on a field's type.
Some fields should be protected against manipulation by Rust code for
the same reason `Vec::set_len` is `unsafe`.
  • Loading branch information
workingjubilee committed Jul 5, 2024
1 parent 7600bf8 commit 827f57c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
2 changes: 2 additions & 0 deletions bindgen/callbacks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,4 +205,6 @@ pub struct FieldInfo<'a> {
pub type_name: &'a str,
/// The name of the field.
pub field_name: &'a str,
/// The name of the type of the field.
pub field_type_name: Option<&'a str>,
}
3 changes: 3 additions & 0 deletions bindgen/codegen/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1515,6 +1515,7 @@ impl<'a> FieldCodegen<'a> for FieldData {
cb.field_visibility(FieldInfo {
type_name: &parent_item.canonical_name(ctx),
field_name,
field_type_name: field_ty.name(),
})
}),
self.annotations(),
Expand Down Expand Up @@ -1889,6 +1890,7 @@ impl<'a> FieldCodegen<'a> for Bitfield {

let bitfield_ty_item = ctx.resolve_item(self.ty());
let bitfield_ty = bitfield_ty_item.expect_type();
let bitfield_ty_ident = bitfield_ty.name();

let bitfield_ty_layout = bitfield_ty
.layout(ctx)
Expand Down Expand Up @@ -1916,6 +1918,7 @@ impl<'a> FieldCodegen<'a> for Bitfield {
cb.field_visibility(FieldInfo {
type_name: &parent_item.canonical_name(ctx),
field_name,
field_type_name: bitfield_ty_ident,
})
})
});
Expand Down

0 comments on commit 827f57c

Please sign in to comment.