Skip to content

Commit 87097af

Browse files
committed
Use core when appropriate.
1 parent 0bb1d18 commit 87097af

File tree

7 files changed

+46
-45
lines changed

7 files changed

+46
-45
lines changed

src/codegen/mod.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -2084,6 +2084,7 @@ impl CodeGenerator for CompInfo {
20842084
.count() >
20852085
1;
20862086

2087+
let prefix = ctx.trait_prefix();
20872088

20882089
// The offset of #[repr(C)] union is always 0, don't need to recheck it.
20892090
let is_not_packed_union = is_union && !packed;
@@ -2112,19 +2113,19 @@ impl CodeGenerator for CompInfo {
21122113
{
21132114
// Create an instance of #canonical_ident struct from zero bit pattern
21142115
let struct_instance = unsafe {
2115-
std::mem::zeroed::<#canonical_ident>()
2116+
#prefix::mem::zeroed::<#canonical_ident>()
21162117
};
21172118

21182119
// Get the pointers to the struct and its field
21192120
let struct_ptr = &struct_instance as *const #canonical_ident;
2120-
let field_ptr = std::ptr::addr_of!(struct_instance.#field_name);
2121+
let field_ptr = #prefix::ptr::addr_of!(struct_instance.#field_name);
21212122

21222123
// Get the offset of the field
21232124
let struct_address = struct_ptr as usize;
21242125
let field_address = field_ptr as usize;
21252126

21262127
//Do not call the destructor
2127-
std::mem::forget(struct_instance);
2128+
#prefix::mem::forget(struct_instance);
21282129

21292130
field_address.checked_sub(struct_address).unwrap()
21302131
},

tests/expectations/tests/ctypes-prefix-path.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -33,38 +33,38 @@ fn bindgen_test_layout_foo() {
3333
);
3434
assert_eq!(
3535
{
36-
let struct_instance = unsafe { std::mem::zeroed::<foo>() };
36+
let struct_instance = unsafe { core::mem::zeroed::<foo>() };
3737
let struct_ptr = &struct_instance as *const foo;
38-
let field_ptr = std::ptr::addr_of!(struct_instance.a);
38+
let field_ptr = core::ptr::addr_of!(struct_instance.a);
3939
let struct_address = struct_ptr as usize;
4040
let field_address = field_ptr as usize;
41-
std::mem::forget(struct_instance);
41+
core::mem::forget(struct_instance);
4242
field_address.checked_sub(struct_address).unwrap()
4343
},
4444
0usize,
4545
concat!("Offset of field: ", stringify!(foo), "::", stringify!(a))
4646
);
4747
assert_eq!(
4848
{
49-
let struct_instance = unsafe { std::mem::zeroed::<foo>() };
49+
let struct_instance = unsafe { core::mem::zeroed::<foo>() };
5050
let struct_ptr = &struct_instance as *const foo;
51-
let field_ptr = std::ptr::addr_of!(struct_instance.b);
51+
let field_ptr = core::ptr::addr_of!(struct_instance.b);
5252
let struct_address = struct_ptr as usize;
5353
let field_address = field_ptr as usize;
54-
std::mem::forget(struct_instance);
54+
core::mem::forget(struct_instance);
5555
field_address.checked_sub(struct_address).unwrap()
5656
},
5757
4usize,
5858
concat!("Offset of field: ", stringify!(foo), "::", stringify!(b))
5959
);
6060
assert_eq!(
6161
{
62-
let struct_instance = unsafe { std::mem::zeroed::<foo>() };
62+
let struct_instance = unsafe { core::mem::zeroed::<foo>() };
6363
let struct_ptr = &struct_instance as *const foo;
64-
let field_ptr = std::ptr::addr_of!(struct_instance.bar);
64+
let field_ptr = core::ptr::addr_of!(struct_instance.bar);
6565
let struct_address = struct_ptr as usize;
6666
let field_address = field_ptr as usize;
67-
std::mem::forget(struct_instance);
67+
core::mem::forget(struct_instance);
6868
field_address.checked_sub(struct_address).unwrap()
6969
},
7070
8usize,

tests/expectations/tests/derive-debug-bitfield-core.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -114,12 +114,12 @@ fn bindgen_test_layout_C() {
114114
);
115115
assert_eq!(
116116
{
117-
let struct_instance = unsafe { std::mem::zeroed::<C>() };
117+
let struct_instance = unsafe { core::mem::zeroed::<C>() };
118118
let struct_ptr = &struct_instance as *const C;
119-
let field_ptr = std::ptr::addr_of!(struct_instance.large_array);
119+
let field_ptr = core::ptr::addr_of!(struct_instance.large_array);
120120
let struct_address = struct_ptr as usize;
121121
let field_address = field_ptr as usize;
122-
std::mem::forget(struct_instance);
122+
core::mem::forget(struct_instance);
123123
field_address.checked_sub(struct_address).unwrap()
124124
},
125125
4usize,

tests/expectations/tests/derive-partialeq-core.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@ fn bindgen_test_layout_C() {
2626
);
2727
assert_eq!(
2828
{
29-
let struct_instance = unsafe { std::mem::zeroed::<C>() };
29+
let struct_instance = unsafe { core::mem::zeroed::<C>() };
3030
let struct_ptr = &struct_instance as *const C;
31-
let field_ptr = std::ptr::addr_of!(struct_instance.large_array);
31+
let field_ptr = core::ptr::addr_of!(struct_instance.large_array);
3232
let struct_address = struct_ptr as usize;
3333
let field_address = field_ptr as usize;
34-
std::mem::forget(struct_instance);
34+
core::mem::forget(struct_instance);
3535
field_address.checked_sub(struct_address).unwrap()
3636
},
3737
0usize,

tests/expectations/tests/no-std.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -31,38 +31,38 @@ fn bindgen_test_layout_foo() {
3131
);
3232
assert_eq!(
3333
{
34-
let struct_instance = unsafe { std::mem::zeroed::<foo>() };
34+
let struct_instance = unsafe { core::mem::zeroed::<foo>() };
3535
let struct_ptr = &struct_instance as *const foo;
36-
let field_ptr = std::ptr::addr_of!(struct_instance.a);
36+
let field_ptr = core::ptr::addr_of!(struct_instance.a);
3737
let struct_address = struct_ptr as usize;
3838
let field_address = field_ptr as usize;
39-
std::mem::forget(struct_instance);
39+
core::mem::forget(struct_instance);
4040
field_address.checked_sub(struct_address).unwrap()
4141
},
4242
0usize,
4343
concat!("Offset of field: ", stringify!(foo), "::", stringify!(a))
4444
);
4545
assert_eq!(
4646
{
47-
let struct_instance = unsafe { std::mem::zeroed::<foo>() };
47+
let struct_instance = unsafe { core::mem::zeroed::<foo>() };
4848
let struct_ptr = &struct_instance as *const foo;
49-
let field_ptr = std::ptr::addr_of!(struct_instance.b);
49+
let field_ptr = core::ptr::addr_of!(struct_instance.b);
5050
let struct_address = struct_ptr as usize;
5151
let field_address = field_ptr as usize;
52-
std::mem::forget(struct_instance);
52+
core::mem::forget(struct_instance);
5353
field_address.checked_sub(struct_address).unwrap()
5454
},
5555
4usize,
5656
concat!("Offset of field: ", stringify!(foo), "::", stringify!(b))
5757
);
5858
assert_eq!(
5959
{
60-
let struct_instance = unsafe { std::mem::zeroed::<foo>() };
60+
let struct_instance = unsafe { core::mem::zeroed::<foo>() };
6161
let struct_ptr = &struct_instance as *const foo;
62-
let field_ptr = std::ptr::addr_of!(struct_instance.bar);
62+
let field_ptr = core::ptr::addr_of!(struct_instance.bar);
6363
let struct_address = struct_ptr as usize;
6464
let field_address = field_ptr as usize;
65-
std::mem::forget(struct_instance);
65+
core::mem::forget(struct_instance);
6666
field_address.checked_sub(struct_address).unwrap()
6767
},
6868
8usize,

tests/expectations/tests/use-core.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -28,38 +28,38 @@ fn bindgen_test_layout_foo() {
2828
);
2929
assert_eq!(
3030
{
31-
let struct_instance = unsafe { std::mem::zeroed::<foo>() };
31+
let struct_instance = unsafe { core::mem::zeroed::<foo>() };
3232
let struct_ptr = &struct_instance as *const foo;
33-
let field_ptr = std::ptr::addr_of!(struct_instance.a);
33+
let field_ptr = core::ptr::addr_of!(struct_instance.a);
3434
let struct_address = struct_ptr as usize;
3535
let field_address = field_ptr as usize;
36-
std::mem::forget(struct_instance);
36+
core::mem::forget(struct_instance);
3737
field_address.checked_sub(struct_address).unwrap()
3838
},
3939
0usize,
4040
concat!("Offset of field: ", stringify!(foo), "::", stringify!(a))
4141
);
4242
assert_eq!(
4343
{
44-
let struct_instance = unsafe { std::mem::zeroed::<foo>() };
44+
let struct_instance = unsafe { core::mem::zeroed::<foo>() };
4545
let struct_ptr = &struct_instance as *const foo;
46-
let field_ptr = std::ptr::addr_of!(struct_instance.b);
46+
let field_ptr = core::ptr::addr_of!(struct_instance.b);
4747
let struct_address = struct_ptr as usize;
4848
let field_address = field_ptr as usize;
49-
std::mem::forget(struct_instance);
49+
core::mem::forget(struct_instance);
5050
field_address.checked_sub(struct_address).unwrap()
5151
},
5252
4usize,
5353
concat!("Offset of field: ", stringify!(foo), "::", stringify!(b))
5454
);
5555
assert_eq!(
5656
{
57-
let struct_instance = unsafe { std::mem::zeroed::<foo>() };
57+
let struct_instance = unsafe { core::mem::zeroed::<foo>() };
5858
let struct_ptr = &struct_instance as *const foo;
59-
let field_ptr = std::ptr::addr_of!(struct_instance.bar);
59+
let field_ptr = core::ptr::addr_of!(struct_instance.bar);
6060
let struct_address = struct_ptr as usize;
6161
let field_address = field_ptr as usize;
62-
std::mem::forget(struct_instance);
62+
core::mem::forget(struct_instance);
6363
field_address.checked_sub(struct_address).unwrap()
6464
},
6565
8usize,

tests/expectations/tests/use-core_1_0.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -71,38 +71,38 @@ fn bindgen_test_layout_foo() {
7171
);
7272
assert_eq!(
7373
{
74-
let struct_instance = unsafe { std::mem::zeroed::<foo>() };
74+
let struct_instance = unsafe { core::mem::zeroed::<foo>() };
7575
let struct_ptr = &struct_instance as *const foo;
76-
let field_ptr = std::ptr::addr_of!(struct_instance.a);
76+
let field_ptr = core::ptr::addr_of!(struct_instance.a);
7777
let struct_address = struct_ptr as usize;
7878
let field_address = field_ptr as usize;
79-
std::mem::forget(struct_instance);
79+
core::mem::forget(struct_instance);
8080
field_address.checked_sub(struct_address).unwrap()
8181
},
8282
0usize,
8383
concat!("Offset of field: ", stringify!(foo), "::", stringify!(a))
8484
);
8585
assert_eq!(
8686
{
87-
let struct_instance = unsafe { std::mem::zeroed::<foo>() };
87+
let struct_instance = unsafe { core::mem::zeroed::<foo>() };
8888
let struct_ptr = &struct_instance as *const foo;
89-
let field_ptr = std::ptr::addr_of!(struct_instance.b);
89+
let field_ptr = core::ptr::addr_of!(struct_instance.b);
9090
let struct_address = struct_ptr as usize;
9191
let field_address = field_ptr as usize;
92-
std::mem::forget(struct_instance);
92+
core::mem::forget(struct_instance);
9393
field_address.checked_sub(struct_address).unwrap()
9494
},
9595
4usize,
9696
concat!("Offset of field: ", stringify!(foo), "::", stringify!(b))
9797
);
9898
assert_eq!(
9999
{
100-
let struct_instance = unsafe { std::mem::zeroed::<foo>() };
100+
let struct_instance = unsafe { core::mem::zeroed::<foo>() };
101101
let struct_ptr = &struct_instance as *const foo;
102-
let field_ptr = std::ptr::addr_of!(struct_instance.bar);
102+
let field_ptr = core::ptr::addr_of!(struct_instance.bar);
103103
let struct_address = struct_ptr as usize;
104104
let field_address = field_ptr as usize;
105-
std::mem::forget(struct_instance);
105+
core::mem::forget(struct_instance);
106106
field_address.checked_sub(struct_address).unwrap()
107107
},
108108
8usize,

0 commit comments

Comments
 (0)