Skip to content

Commit 99aff6e

Browse files
elichaiemilio
authored andcommitted
Add support for MaybeUninit
1 parent ec35b7a commit 99aff6e

File tree

2 files changed

+35
-9
lines changed

2 files changed

+35
-9
lines changed

src/codegen/mod.rs

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2156,13 +2156,26 @@ impl MethodCodegen for Method {
21562156
// variable called `__bindgen_tmp` we're going to create.
21572157
if self.is_constructor() {
21582158
let prefix = ctx.trait_prefix();
2159-
let tmp_variable_decl = quote! {
2160-
let mut __bindgen_tmp = ::#prefix::mem::uninitialized()
2159+
let tmp_variable_decl = if ctx
2160+
.options()
2161+
.rust_features()
2162+
.maybe_uninit
2163+
{
2164+
exprs[0] = quote! {
2165+
__bindgen_tmp.as_mut_ptr()
2166+
};
2167+
quote! {
2168+
let mut __bindgen_tmp = ::#prefix::mem::MaybeUninit::uninit()
2169+
}
2170+
} else {
2171+
exprs[0] = quote! {
2172+
&mut __bindgen_tmp
2173+
};
2174+
quote! {
2175+
let mut __bindgen_tmp = ::#prefix::mem::uninitialized()
2176+
}
21612177
};
21622178
stmts.push(tmp_variable_decl);
2163-
exprs[0] = quote! {
2164-
&mut __bindgen_tmp
2165-
};
21662179
} else if !self.is_static() {
21672180
assert!(!exprs.is_empty());
21682181
exprs[0] = quote! {
@@ -2177,9 +2190,15 @@ impl MethodCodegen for Method {
21772190
stmts.push(call);
21782191

21792192
if self.is_constructor() {
2180-
stmts.push(quote! {
2181-
__bindgen_tmp
2182-
});
2193+
stmts.push(if ctx.options().rust_features().maybe_uninit {
2194+
quote! {
2195+
__bindgen_tmp.assume_init()
2196+
}
2197+
} else {
2198+
quote! {
2199+
__bindgen_tmp
2200+
}
2201+
})
21832202
}
21842203

21852204
let block = quote! {

src/features.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,9 @@ macro_rules! rust_target_base {
118118
/// Rust stable 1.33
119119
/// * repr(packed(N)) ([PR](https://github.com/rust-lang/rust/pull/57049))
120120
=> Stable_1_33 => 1.33;
121+
/// Rust stable 1.36
122+
/// * `MaybeUninit` instead of `mem::uninitialized()` ([PR](https://github.com/rust-lang/rust/pull/60445))
123+
=> Stable_1_36 => 1.36;
121124
/// Nightly rust
122125
/// * `thiscall` calling convention ([Tracking issue](https://github.com/rust-lang/rust/issues/42202))
123126
/// * `non_exhaustive` enums/structs ([Tracking issue](https://github.com/rust-lang/rust/issues/44109))
@@ -130,7 +133,7 @@ rust_target_base!(rust_target_def);
130133
rust_target_base!(rust_target_values_def);
131134

132135
/// Latest stable release of Rust
133-
pub const LATEST_STABLE_RUST: RustTarget = RustTarget::Stable_1_33;
136+
pub const LATEST_STABLE_RUST: RustTarget = RustTarget::Stable_1_36;
134137

135138
/// Create RustFeatures struct definition, new(), and a getter for each field
136139
macro_rules! rust_feature_def {
@@ -212,6 +215,9 @@ rust_feature_def!(
212215
Stable_1_33 {
213216
=> repr_packed_n;
214217
}
218+
Stable_1_36 {
219+
=> maybe_uninit;
220+
}
215221
Nightly {
216222
=> thiscall_abi;
217223
=> non_exhaustive;
@@ -256,6 +262,7 @@ mod test {
256262
f_nightly.untagged_union &&
257263
f_nightly.associated_const &&
258264
f_nightly.builtin_clone_impls &&
265+
f_nightly.maybe_uninit &&
259266
f_nightly.repr_align &&
260267
f_nightly.thiscall_abi
261268
);

0 commit comments

Comments
 (0)