From 827f57c0e999937254b3d9d44e20be3a39f74cc1 Mon Sep 17 00:00:00 2001 From: Jubilee Young Date: Fri, 5 Jul 2024 11:41:40 -0700 Subject: [PATCH] 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`. --- bindgen/callbacks.rs | 2 ++ bindgen/codegen/mod.rs | 3 +++ 2 files changed, 5 insertions(+) diff --git a/bindgen/callbacks.rs b/bindgen/callbacks.rs index 0f16c4c0bf..56cd97b9c8 100644 --- a/bindgen/callbacks.rs +++ b/bindgen/callbacks.rs @@ -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>, } diff --git a/bindgen/codegen/mod.rs b/bindgen/codegen/mod.rs index e2aaee9820..192b74ba4f 100644 --- a/bindgen/codegen/mod.rs +++ b/bindgen/codegen/mod.rs @@ -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(), @@ -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) @@ -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, }) }) });