Skip to content

Commit 3dee8ba

Browse files
workingjubileepvdrz
authored andcommitted
Add FieldInfo::field_type_name
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`.
1 parent 0267b0e commit 3dee8ba

File tree

3 files changed

+6
-0
lines changed

3 files changed

+6
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,7 @@
238238
- Add option to use DST structs for flexible arrays (--flexarray-dst, #2772).
239239
- Add option to dynamically load variables (#2812).
240240
- Add option in CLI to use rustified non-exhaustive enums (--rustified-non-exhaustive-enum, #2847).
241+
- Add field_type_name to FieldInfo.
241242
## Changed
242243
- Remove which and lazy-static dependencies (#2809, #2817).
243244
- Generate compile-time layout tests (#2787).

bindgen/callbacks.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,4 +280,6 @@ pub struct FieldInfo<'a> {
280280
pub type_name: &'a str,
281281
/// The name of the field.
282282
pub field_name: &'a str,
283+
/// The name of the type of the field.
284+
pub field_type_name: Option<&'a str>,
283285
}

bindgen/codegen/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1547,6 +1547,7 @@ impl FieldCodegen<'_> for FieldData {
15471547
cb.field_visibility(FieldInfo {
15481548
type_name: &parent_item.canonical_name(ctx),
15491549
field_name,
1550+
field_type_name: field_ty.name(),
15501551
})
15511552
}),
15521553
self.annotations(),
@@ -1952,6 +1953,7 @@ impl<'a> FieldCodegen<'a> for Bitfield {
19521953

19531954
let bitfield_ty_item = ctx.resolve_item(self.ty());
19541955
let bitfield_ty = bitfield_ty_item.expect_type();
1956+
let bitfield_ty_ident = bitfield_ty.name();
19551957

19561958
let bitfield_ty_layout = bitfield_ty
19571959
.layout(ctx)
@@ -1976,6 +1978,7 @@ impl<'a> FieldCodegen<'a> for Bitfield {
19761978
cb.field_visibility(FieldInfo {
19771979
type_name: &parent_item.canonical_name(ctx),
19781980
field_name,
1981+
field_type_name: bitfield_ty_ident,
19791982
})
19801983
})
19811984
});

0 commit comments

Comments
 (0)