diff options
author | Elichai Turkel <elichai.turkel@gmail.com> | 2019-11-04 17:41:49 +0200 |
---|---|---|
committer | Emilio Cobos Álvarez <emilio@crisal.io> | 2019-11-08 13:46:40 +0100 |
commit | 99aff6e254faf5ff3e0ed7350f890ec57d41e0ec (patch) | |
tree | 7572fe1253bcbaeb31653bc6932cbe5adb992438 /src/codegen/mod.rs | |
parent | ec35b7ab7e8a0eabfb2c9ed27133d97cb35fd5ca (diff) |
Add support for MaybeUninit
Diffstat (limited to 'src/codegen/mod.rs')
-rw-r--r-- | src/codegen/mod.rs | 35 |
1 files changed, 27 insertions, 8 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! { |