Skip to content
Merged
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
14 changes: 6 additions & 8 deletions rs_bindings_from_cc/generate_bindings/generate_function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1080,14 +1080,12 @@ fn generate_func_body(
..
}
| ImplKind::Struct { is_renamed_unpin_constructor: true, .. } => {
// SAFETY: A user-defined constructor is not guaranteed to
// initialize all the fields. To make the `assume_init()` call
// below safe, the memory is zero-initialized first. This is a
// bit safer, because zero-initialized memory represents a valid
// value for the currently supported field types (this may
// change once the bindings generator starts supporting
// reference fields). TODO(b/213243309): Double-check if
// zero-initialization is desirable here.
// SAFETY: Constructors are guaranteed to run all subobject constructors, but primitive
// fields are not necessarily initialized. By zeroing the memory first, we ensure that
// all primitives are initialized to zero. All C++ primitives, when mapped to Rust
// primitives, can accept a zero value (pointers, floats, bools, ints, etc.). One
// notable exception is C++ references, but those cannot be default-initialized, so
// we don't need to worry about them.
Ok(quote! {
#thunk_prepare
let mut tmp = ::core::mem::MaybeUninit::<Self>::zeroed();
Expand Down