Skip to content

Commit 04fdb10

Browse files
author
bors-servo
authored
Auto merge of #889 - photoszzt:fix_recursive_whitelist_opaque, r=fitzgen
Fix recursive whitelisting and handling of opaque for derive default Fix regression of derive default analysis. Also fix opaque handing exposed by the above fix. r? @fitzgen
2 parents b1cfa78 + 8c6a253 commit 04fdb10

7 files changed

+19
-22
lines changed

src/ir/analysis/derive_default.rs

+7-4
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ impl<'ctx, 'gen> MonotoneFramework for CannotDeriveDefault<'ctx, 'gen> {
158158
}
159159
};
160160

161-
if ty.is_opaque(self.ctx, item) {
161+
if item.is_opaque(self.ctx, &()) {
162162
let layout_can_derive = ty.layout(self.ctx).map_or(true, |l| {
163163
l.opaque().can_trivially_derive_default()
164164
});
@@ -265,7 +265,8 @@ impl<'ctx, 'gen> MonotoneFramework for CannotDeriveDefault<'ctx, 'gen> {
265265

266266
let bases_cannot_derive = info.base_members()
267267
.iter()
268-
.any(|base| self.cannot_derive_default.contains(&base.ty));
268+
.any(|base| !self.ctx.whitelisted_items().contains(&base.ty) ||
269+
self.cannot_derive_default.contains(&base.ty));
269270
if bases_cannot_derive {
270271
trace!(" base members cannot derive Default, so we can't \
271272
either");
@@ -277,12 +278,14 @@ impl<'ctx, 'gen> MonotoneFramework for CannotDeriveDefault<'ctx, 'gen> {
277278
.any(|f| {
278279
match *f {
279280
Field::DataMember(ref data) => {
280-
self.cannot_derive_default.contains(&data.ty())
281+
!self.ctx.whitelisted_items().contains(&data.ty()) ||
282+
self.cannot_derive_default.contains(&data.ty())
281283
}
282284
Field::Bitfields(ref bfu) => {
283285
bfu.bitfields()
284286
.iter().any(|b| {
285-
self.cannot_derive_default.contains(&b.ty())
287+
!self.ctx.whitelisted_items().contains(&b.ty()) ||
288+
self.cannot_derive_default.contains(&b.ty())
286289
})
287290
}
288291
}

tests/expectations/tests/no-derive-debug.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
/// and replacement for another type that doesn't implement it would prevent it
1010
/// from building if --no-derive-debug didn't work.
1111
#[repr(C)]
12-
#[derive(Default, Copy)]
12+
#[derive(Copy)]
1313
pub struct bar {
1414
pub foo: foo,
1515
pub baz: ::std::os::raw::c_int,
@@ -34,3 +34,6 @@ fn bindgen_test_layout_bar() {
3434
impl Clone for bar {
3535
fn clone(&self) -> Self { *self }
3636
}
37+
impl Default for bar {
38+
fn default() -> Self { unsafe { ::std::mem::zeroed() } }
39+
}

tests/expectations/tests/no-recursive-whitelisting.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
pub enum Bar {}
77

88
#[repr(C)]
9-
#[derive(Debug, Default, Copy)]
9+
#[derive(Debug, Copy)]
1010
pub struct Foo {
1111
pub baz: *mut Bar,
1212
}
@@ -25,3 +25,6 @@ fn bindgen_test_layout_Foo() {
2525
impl Clone for Foo {
2626
fn clone(&self) -> Self { *self }
2727
}
28+
impl Default for Foo {
29+
fn default() -> Self { unsafe { ::std::mem::zeroed() } }
30+
}

tests/expectations/tests/opaque-template-inst-member-2.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,9 @@
55

66

77
#[repr(C)]
8-
#[derive(Debug, Copy, Clone)]
8+
#[derive(Debug, Default, Copy, Clone)]
99
pub struct OpaqueTemplate {
1010
}
11-
impl Default for OpaqueTemplate {
12-
fn default() -> Self { unsafe { ::std::mem::zeroed() } }
13-
}
1411
#[repr(C)]
1512
#[derive(Debug, Default, Copy)]
1613
pub struct ContainsOpaqueTemplate {

tests/expectations/tests/opaque-template-inst-member.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,9 @@
55

66

77
#[repr(C)]
8-
#[derive(Copy, Clone)]
8+
#[derive(Default, Copy, Clone)]
99
pub struct OpaqueTemplate {
1010
}
11-
impl Default for OpaqueTemplate {
12-
fn default() -> Self { unsafe { ::std::mem::zeroed() } }
13-
}
1411
#[repr(C)]
1512
pub struct ContainsOpaqueTemplate {
1613
pub mBlah: [u32; 101usize],

tests/expectations/tests/opaque_pointer.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,9 @@ impl Clone for OtherOpaque {
2222
}
2323
/// <div rustbindgen opaque></div>
2424
#[repr(C)]
25-
#[derive(Debug, Copy, Clone)]
25+
#[derive(Debug, Default, Copy, Clone)]
2626
pub struct Opaque {
2727
}
28-
impl Default for Opaque {
29-
fn default() -> Self { unsafe { ::std::mem::zeroed() } }
30-
}
3128
#[repr(C)]
3229
#[derive(Debug, Copy)]
3330
pub struct WithOpaquePtr {

tests/expectations/tests/template.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -171,12 +171,9 @@ impl Default for PODButContainsDtor {
171171
}
172172
/// <div rustbindgen opaque>
173173
#[repr(C)]
174-
#[derive(Debug, Copy, Clone)]
174+
#[derive(Debug, Default, Copy, Clone)]
175175
pub struct Opaque {
176176
}
177-
impl Default for Opaque {
178-
fn default() -> Self { unsafe { ::std::mem::zeroed() } }
179-
}
180177
#[repr(C)]
181178
#[derive(Debug, Default, Copy)]
182179
pub struct POD {

0 commit comments

Comments
 (0)