Skip to content

Commit 3609bd6

Browse files
elichaiemilio
authored andcommitted
Update and add tests for MaybeUninit
1 parent 99aff6e commit 3609bd6

9 files changed

+130
-27
lines changed

tests/expectations/tests/constructor-tp.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ extern "C" {
3737
impl Bar {
3838
#[inline]
3939
pub unsafe fn new() -> Self {
40-
let mut __bindgen_tmp = ::std::mem::uninitialized();
41-
Bar_Bar(&mut __bindgen_tmp);
42-
__bindgen_tmp
40+
let mut __bindgen_tmp = ::std::mem::MaybeUninit::uninit();
41+
Bar_Bar(__bindgen_tmp.as_mut_ptr());
42+
__bindgen_tmp.assume_init()
4343
}
4444
}

tests/expectations/tests/constructors.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,15 @@ extern "C" {
3939
impl TestOverload {
4040
#[inline]
4141
pub unsafe fn new(arg1: ::std::os::raw::c_int) -> Self {
42-
let mut __bindgen_tmp = ::std::mem::uninitialized();
43-
TestOverload_TestOverload(&mut __bindgen_tmp, arg1);
44-
__bindgen_tmp
42+
let mut __bindgen_tmp = ::std::mem::MaybeUninit::uninit();
43+
TestOverload_TestOverload(__bindgen_tmp.as_mut_ptr(), arg1);
44+
__bindgen_tmp.assume_init()
4545
}
4646
#[inline]
4747
pub unsafe fn new1(arg1: f64) -> Self {
48-
let mut __bindgen_tmp = ::std::mem::uninitialized();
49-
TestOverload_TestOverload1(&mut __bindgen_tmp, arg1);
50-
__bindgen_tmp
48+
let mut __bindgen_tmp = ::std::mem::MaybeUninit::uninit();
49+
TestOverload_TestOverload1(__bindgen_tmp.as_mut_ptr(), arg1);
50+
__bindgen_tmp.assume_init()
5151
}
5252
}
5353
#[repr(C)]
@@ -75,8 +75,8 @@ extern "C" {
7575
impl TestPublicNoArgs {
7676
#[inline]
7777
pub unsafe fn new() -> Self {
78-
let mut __bindgen_tmp = ::std::mem::uninitialized();
79-
TestPublicNoArgs_TestPublicNoArgs(&mut __bindgen_tmp);
80-
__bindgen_tmp
78+
let mut __bindgen_tmp = ::std::mem::MaybeUninit::uninit();
79+
TestPublicNoArgs_TestPublicNoArgs(__bindgen_tmp.as_mut_ptr());
80+
__bindgen_tmp.assume_init()
8181
}
8282
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
/* automatically generated by rust-bindgen */
2+
3+
#![allow(
4+
dead_code,
5+
non_snake_case,
6+
non_camel_case_types,
7+
non_upper_case_globals
8+
)]
9+
10+
#[repr(C)]
11+
#[derive(Debug, Default, Copy, Clone)]
12+
pub struct TestOverload {
13+
pub _address: u8,
14+
}
15+
#[test]
16+
fn bindgen_test_layout_TestOverload() {
17+
assert_eq!(
18+
::std::mem::size_of::<TestOverload>(),
19+
1usize,
20+
concat!("Size of: ", stringify!(TestOverload))
21+
);
22+
assert_eq!(
23+
::std::mem::align_of::<TestOverload>(),
24+
1usize,
25+
concat!("Alignment of ", stringify!(TestOverload))
26+
);
27+
}
28+
extern "C" {
29+
/// Calling this should use `mem::unintialized()` and not `MaybeUninit()` as only rust 1.36 includes that.
30+
#[link_name = "\u{1}_ZN12TestOverloadC1Ei"]
31+
pub fn TestOverload_TestOverload(
32+
this: *mut TestOverload,
33+
arg1: ::std::os::raw::c_int,
34+
);
35+
}
36+
extern "C" {
37+
/// Calling this should use `mem::unintialized()` and not `MaybeUninit()` as only rust 1.36 includes that.
38+
#[link_name = "\u{1}_ZN12TestOverloadC1Ed"]
39+
pub fn TestOverload_TestOverload1(this: *mut TestOverload, arg1: f64);
40+
}
41+
impl TestOverload {
42+
#[inline]
43+
pub unsafe fn new(arg1: ::std::os::raw::c_int) -> Self {
44+
let mut __bindgen_tmp = ::std::mem::uninitialized();
45+
TestOverload_TestOverload(&mut __bindgen_tmp, arg1);
46+
__bindgen_tmp
47+
}
48+
#[inline]
49+
pub unsafe fn new1(arg1: f64) -> Self {
50+
let mut __bindgen_tmp = ::std::mem::uninitialized();
51+
TestOverload_TestOverload1(&mut __bindgen_tmp, arg1);
52+
__bindgen_tmp
53+
}
54+
}
55+
#[repr(C)]
56+
#[derive(Debug, Default, Copy, Clone)]
57+
pub struct TestPublicNoArgs {
58+
pub _address: u8,
59+
}
60+
#[test]
61+
fn bindgen_test_layout_TestPublicNoArgs() {
62+
assert_eq!(
63+
::std::mem::size_of::<TestPublicNoArgs>(),
64+
1usize,
65+
concat!("Size of: ", stringify!(TestPublicNoArgs))
66+
);
67+
assert_eq!(
68+
::std::mem::align_of::<TestPublicNoArgs>(),
69+
1usize,
70+
concat!("Alignment of ", stringify!(TestPublicNoArgs))
71+
);
72+
}
73+
extern "C" {
74+
#[link_name = "\u{1}_ZN16TestPublicNoArgsC1Ev"]
75+
pub fn TestPublicNoArgs_TestPublicNoArgs(this: *mut TestPublicNoArgs);
76+
}
77+
impl TestPublicNoArgs {
78+
#[inline]
79+
pub unsafe fn new() -> Self {
80+
let mut __bindgen_tmp = ::std::mem::uninitialized();
81+
TestPublicNoArgs_TestPublicNoArgs(&mut __bindgen_tmp);
82+
__bindgen_tmp
83+
}
84+
}

tests/expectations/tests/gen-constructors.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ extern "C" {
3232
impl Foo {
3333
#[inline]
3434
pub unsafe fn new(a: ::std::os::raw::c_int) -> Self {
35-
let mut __bindgen_tmp = ::std::mem::uninitialized();
36-
Foo_Foo(&mut __bindgen_tmp, a);
37-
__bindgen_tmp
35+
let mut __bindgen_tmp = ::std::mem::MaybeUninit::uninit();
36+
Foo_Foo(__bindgen_tmp.as_mut_ptr(), a);
37+
__bindgen_tmp.assume_init()
3838
}
3939
}

tests/expectations/tests/issue-447.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,12 @@ pub mod root {
6767
pub unsafe fn new(
6868
arg1: root::mozilla::detail::GuardObjectNotifier,
6969
) -> Self {
70-
let mut __bindgen_tmp = ::std::mem::uninitialized();
71-
JSAutoCompartment_JSAutoCompartment(&mut __bindgen_tmp, arg1);
72-
__bindgen_tmp
70+
let mut __bindgen_tmp = ::std::mem::MaybeUninit::uninit();
71+
JSAutoCompartment_JSAutoCompartment(
72+
__bindgen_tmp.as_mut_ptr(),
73+
arg1,
74+
);
75+
__bindgen_tmp.assume_init()
7376
}
7477
}
7578
}

tests/expectations/tests/issue-807-opaque-types-methods-being-generated.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,9 @@ impl Opaque {
9595
}
9696
#[inline]
9797
pub unsafe fn new(pup: Pupper) -> Self {
98-
let mut __bindgen_tmp = ::std::mem::uninitialized();
99-
Opaque_Opaque(&mut __bindgen_tmp, pup);
100-
__bindgen_tmp
98+
let mut __bindgen_tmp = ::std::mem::MaybeUninit::uninit();
99+
Opaque_Opaque(__bindgen_tmp.as_mut_ptr(), pup);
100+
__bindgen_tmp.assume_init()
101101
}
102102
}
103103
extern "C" {

tests/expectations/tests/libclang-3.8/partial-specialization-and-inheritance.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ extern "C" {
4343
impl Usage {
4444
#[inline]
4545
pub unsafe fn new() -> Self {
46-
let mut __bindgen_tmp = ::std::mem::uninitialized();
47-
Usage_Usage(&mut __bindgen_tmp);
48-
__bindgen_tmp
46+
let mut __bindgen_tmp = ::std::mem::MaybeUninit::uninit();
47+
Usage_Usage(__bindgen_tmp.as_mut_ptr());
48+
__bindgen_tmp.assume_init()
4949
}
5050
}

tests/expectations/tests/var-tracing.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@ extern "C" {
4242
impl Bar {
4343
#[inline]
4444
pub unsafe fn new(baz: ::std::os::raw::c_int) -> Self {
45-
let mut __bindgen_tmp = ::std::mem::uninitialized();
46-
Bar_Bar(&mut __bindgen_tmp, baz);
47-
__bindgen_tmp
45+
let mut __bindgen_tmp = ::std::mem::MaybeUninit::uninit();
46+
Bar_Bar(__bindgen_tmp.as_mut_ptr(), baz);
47+
__bindgen_tmp.assume_init()
4848
}
4949
}
5050
#[repr(C)]

tests/headers/constructors_1_33.hpp

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// bindgen-flags: --rust-target 1.33
2+
3+
class TestOverload {
4+
// This one shouldnt' be generated.
5+
TestOverload();
6+
public:
7+
/// Calling this should use `mem::unintialized()` and not `MaybeUninit()` as only rust 1.36 includes that.
8+
TestOverload(int);
9+
/// Calling this should use `mem::unintialized()` and not `MaybeUninit()` as only rust 1.36 includes that.
10+
TestOverload(double);
11+
};
12+
13+
class TestPublicNoArgs {
14+
public:
15+
TestPublicNoArgs();
16+
};

0 commit comments

Comments
 (0)