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 e169561
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@
- Add option to use DST structs for flexible arrays (--flexarray-dst, #2772).
- Add option to dynamically load variables (#2812).
- Add option in CLI to use rustified non-exhaustive enums (--rustified-non-exhaustive-enum, #2847).
- Add field_type_name to FieldInfo.
## Changed
- Remove which and lazy-static dependencies (#2809, #2817).
- Generate compile-time layout tests (#2787).
Expand Down
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 e169561

Please sign in to comment.