diff options
-rw-r--r-- | src/codegen/mod.rs | 35 | ||||
-rw-r--r-- | src/features.rs | 9 |
2 files changed, 35 insertions, 9 deletions
diff --git a/src/codegen/mod.rs b/src/codegen/mod.rs index 2be98ebf..a3755867 100644 --- a/src/codegen/mod.rs +++ b/src/codegen/mod.rs @@ -2156,13 +2156,26 @@ impl MethodCodegen for Method { // variable called `__bindgen_tmp` we're going to create. if self.is_constructor() { let prefix = ctx.trait_prefix(); - let tmp_variable_decl = quote! { - let mut __bindgen_tmp = ::#prefix::mem::uninitialized() + let tmp_variable_decl = if ctx + .options() + .rust_features() + .maybe_uninit + { + exprs[0] = quote! { + __bindgen_tmp.as_mut_ptr() + }; + quote! { + let mut __bindgen_tmp = ::#prefix::mem::MaybeUninit::uninit() + } + } else { + exprs[0] = quote! { + &mut __bindgen_tmp + }; + quote! { + let mut __bindgen_tmp = ::#prefix::mem::uninitialized() + } }; stmts.push(tmp_variable_decl); - exprs[0] = quote! { - &mut __bindgen_tmp - }; } else if !self.is_static() { assert!(!exprs.is_empty()); exprs[0] = quote! { @@ -2177,9 +2190,15 @@ impl MethodCodegen for Method { stmts.push(call); if self.is_constructor() { - stmts.push(quote! { - __bindgen_tmp - }); + stmts.push(if ctx.options().rust_features().maybe_uninit { + quote! { + __bindgen_tmp.assume_init() + } + } else { + quote! { + __bindgen_tmp + } + }) } let block = quote! { diff --git a/src/features.rs b/src/features.rs index 07b80418..94ae645f 100644 --- a/src/features.rs +++ b/src/features.rs @@ -118,6 +118,9 @@ macro_rules! rust_target_base { /// Rust stable 1.33 /// * repr(packed(N)) ([PR](https://github.com/rust-lang/rust/pull/57049)) => Stable_1_33 => 1.33; + /// Rust stable 1.36 + /// * `MaybeUninit` instead of `mem::uninitialized()` ([PR](https://github.com/rust-lang/rust/pull/60445)) + => Stable_1_36 => 1.36; /// Nightly rust /// * `thiscall` calling convention ([Tracking issue](https://github.com/rust-lang/rust/issues/42202)) /// * `non_exhaustive` enums/structs ([Tracking issue](https://github.com/rust-lang/rust/issues/44109)) @@ -130,7 +133,7 @@ rust_target_base!(rust_target_def); rust_target_base!(rust_target_values_def); /// Latest stable release of Rust -pub const LATEST_STABLE_RUST: RustTarget = RustTarget::Stable_1_33; +pub const LATEST_STABLE_RUST: RustTarget = RustTarget::Stable_1_36; /// Create RustFeatures struct definition, new(), and a getter for each field macro_rules! rust_feature_def { @@ -212,6 +215,9 @@ rust_feature_def!( Stable_1_33 { => repr_packed_n; } + Stable_1_36 { + => maybe_uninit; + } Nightly { => thiscall_abi; => non_exhaustive; @@ -256,6 +262,7 @@ mod test { f_nightly.untagged_union && f_nightly.associated_const && f_nightly.builtin_clone_impls && + f_nightly.maybe_uninit && f_nightly.repr_align && f_nightly.thiscall_abi ); |