-
Notifications
You must be signed in to change notification settings - Fork 747
Add --no-default flag #1654
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add --no-default flag #1654
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -140,10 +140,10 @@ impl<'ctx> CannotDerive<'ctx> { | |
fn constrain_type(&mut self, item: &Item, ty: &Type) -> CanDerive { | ||
if !self.ctx.whitelisted_items().contains(&item.id()) { | ||
trace!( | ||
" cannot derive {} for blacklisted type", | ||
" cannot derive {} for blacklisted type, but it can be implemented", | ||
self.derive_trait | ||
); | ||
return CanDerive::No; | ||
return CanDerive::Manually; | ||
} | ||
|
||
if self.derive_trait.not_by_name(self.ctx, &item) { | ||
|
@@ -156,15 +156,18 @@ impl<'ctx> CannotDerive<'ctx> { | |
|
||
trace!("ty: {:?}", ty); | ||
if item.is_opaque(self.ctx, &()) { | ||
if !self.derive_trait.can_derive_union() && | ||
ty.is_union() && | ||
if ty.is_union() && | ||
self.ctx.options().rust_features().untagged_union | ||
{ | ||
trace!( | ||
" cannot derive {} for Rust unions", | ||
self.derive_trait | ||
); | ||
return CanDerive::No; | ||
let can_derive = self.derive_trait.can_derive_union(); | ||
if can_derive != CanDerive::Yes { | ||
trace!( | ||
" cannot derive {} for Rust unions ({:?})", | ||
self.derive_trait, | ||
can_derive, | ||
); | ||
return can_derive; | ||
} | ||
} | ||
|
||
let layout_can_derive = | ||
|
@@ -179,7 +182,13 @@ impl<'ctx> CannotDerive<'ctx> { | |
self.derive_trait | ||
); | ||
} | ||
_ => { | ||
CanDerive::Manually => { | ||
trace!( | ||
" we cannot derive {} for the layout, but it can be implemented", | ||
self.derive_trait | ||
); | ||
} | ||
CanDerive::No => { | ||
trace!( | ||
" we cannot derive {} for the layout", | ||
self.derive_trait | ||
|
@@ -226,11 +235,12 @@ impl<'ctx> CannotDerive<'ctx> { | |
if inner_type != CanDerive::Yes { | ||
trace!( | ||
" arrays of T for which we cannot derive {} \ | ||
also cannot derive {}", | ||
also cannot derive {}, ({:?})", | ||
self.derive_trait, | ||
self.derive_trait | ||
self.derive_trait, | ||
inner_type | ||
); | ||
return CanDerive::No; | ||
return inner_type; | ||
} | ||
|
||
if len == 0 && !self.derive_trait.can_derive_incomplete_array() | ||
|
@@ -308,62 +318,74 @@ impl<'ctx> CannotDerive<'ctx> { | |
} | ||
|
||
if info.kind() == CompKind::Union { | ||
if self.derive_trait.can_derive_union() { | ||
if self.ctx.options().rust_features().untagged_union && | ||
// https://github.com/rust-lang/rust/issues/36640 | ||
(!info.self_template_params(self.ctx).is_empty() || | ||
!item.all_template_params(self.ctx).is_empty()) | ||
{ | ||
trace!( | ||
" cannot derive {} for Rust union because issue 36640", self.derive_trait | ||
); | ||
return CanDerive::No; | ||
} | ||
// fall through to be same as non-union handling | ||
} else { | ||
if self.ctx.options().rust_features().untagged_union { | ||
trace!( | ||
" cannot derive {} for Rust unions", | ||
self.derive_trait | ||
); | ||
return CanDerive::No; | ||
} | ||
|
||
let layout_can_derive = | ||
ty.layout(self.ctx).map_or(CanDerive::Yes, |l| { | ||
l.opaque() | ||
.array_size_within_derive_limit(self.ctx) | ||
}); | ||
match layout_can_derive { | ||
CanDerive::Yes => { | ||
match self.derive_trait.can_derive_union() { | ||
CanDerive::Yes => { | ||
if self.ctx.options().rust_features().untagged_union && | ||
// https://github.com/rust-lang/rust/issues/36640 | ||
(!info.self_template_params(self.ctx).is_empty() || | ||
!item.all_template_params(self.ctx).is_empty()) | ||
{ | ||
trace!( | ||
" union layout can trivially derive {}", | ||
self.derive_trait | ||
" cannot derive {} for Rust union because issue 36640", self.derive_trait | ||
); | ||
return CanDerive::No; | ||
} | ||
_ => { | ||
// fall through to be same as non-union handling | ||
} | ||
trait_can_derive => { | ||
if self.ctx.options().rust_features().untagged_union | ||
{ | ||
trace!( | ||
" union layout cannot derive {}", | ||
self.derive_trait | ||
); | ||
" cannot derive {} for Rust unions ({:?})", | ||
self.derive_trait, | ||
trait_can_derive, | ||
); | ||
return trait_can_derive; | ||
} | ||
}; | ||
return layout_can_derive; | ||
|
||
let layout_can_derive = ty.layout(self.ctx).map_or( | ||
CanDerive::Yes, | ||
|l| { | ||
l.opaque().array_size_within_derive_limit( | ||
self.ctx, | ||
) | ||
}, | ||
); | ||
match layout_can_derive { | ||
CanDerive::Yes => { | ||
trace!( | ||
" union layout can trivially derive {}", | ||
self.derive_trait | ||
); | ||
} | ||
_ => { | ||
trace!( | ||
" union layout cannot derive {}, ({:?})", | ||
self.derive_trait, | ||
layout_can_derive, | ||
); | ||
} | ||
}; | ||
return layout_can_derive; | ||
} | ||
} | ||
} | ||
|
||
if !self.derive_trait.can_derive_compound_with_vtable() && | ||
item.has_vtable(self.ctx) | ||
{ | ||
trace!( | ||
" cannot derive {} for comp with vtable", | ||
self.derive_trait | ||
); | ||
return CanDerive::No; | ||
if item.has_vtable(self.ctx) { | ||
let can_derive = | ||
self.derive_trait.can_derive_compound_with_vtable(); | ||
if can_derive != CanDerive::Yes { | ||
trace!( | ||
" cannot derive {} for comp with vtable ({:?})", | ||
self.derive_trait, | ||
can_derive, | ||
); | ||
return can_derive; | ||
} | ||
} | ||
|
||
let pred = self.derive_trait.consider_edge_comp(); | ||
return self.constrain_join(item, pred); | ||
self.constrain_join(item, pred) | ||
} | ||
|
||
TypeKind::ResolvedTypeRef(..) | | ||
|
@@ -432,6 +454,7 @@ impl DeriveTrait { | |
fn not_by_name(&self, ctx: &BindgenContext, item: &Item) -> bool { | ||
match self { | ||
DeriveTrait::Copy => ctx.no_copy_by_name(item), | ||
DeriveTrait::Default => ctx.no_default_by_name(item), | ||
DeriveTrait::Hash => ctx.no_hash_by_name(item), | ||
DeriveTrait::PartialEqOrPartialOrd => { | ||
ctx.no_partialeq_by_name(item) | ||
|
@@ -476,10 +499,11 @@ impl DeriveTrait { | |
} | ||
} | ||
|
||
fn can_derive_union(&self) -> bool { | ||
fn can_derive_union(&self) -> CanDerive { | ||
match self { | ||
DeriveTrait::Copy => true, | ||
_ => false, | ||
DeriveTrait::Copy => CanDerive::Yes, | ||
DeriveTrait::Default => CanDerive::Manually, | ||
_ => CanDerive::No, | ||
} | ||
} | ||
|
||
|
@@ -490,10 +514,10 @@ impl DeriveTrait { | |
} | ||
} | ||
|
||
fn can_derive_compound_with_vtable(&self) -> bool { | ||
fn can_derive_compound_with_vtable(&self) -> CanDerive { | ||
match self { | ||
DeriveTrait::Default => false, | ||
_ => true, | ||
DeriveTrait::Default => CanDerive::Manually, | ||
_ => CanDerive::Yes, | ||
} | ||
} | ||
|
||
|
@@ -549,8 +573,8 @@ impl DeriveTrait { | |
fn can_derive_pointer(&self) -> CanDerive { | ||
match self { | ||
DeriveTrait::Default => { | ||
trace!(" pointer cannot derive Default"); | ||
CanDerive::No | ||
trace!(" pointer cannot derive Default, but it may be implemented"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm, how can it be implemented for a pointer? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Literally speaking we can't implement anything on pointers, but
does seem to compile for composite types that contain pointers. |
||
CanDerive::Manually | ||
} | ||
_ => { | ||
trace!(" pointer can derive {}", self); | ||
|
@@ -570,8 +594,8 @@ impl DeriveTrait { | |
(DeriveTrait::Default, TypeKind::ObjCInterface(..)) | | ||
(DeriveTrait::Default, TypeKind::ObjCId) | | ||
(DeriveTrait::Default, TypeKind::ObjCSel) => { | ||
trace!(" types that always cannot derive Default"); | ||
CanDerive::No | ||
trace!(" types that always cannot derive Default, but may implement it manually"); | ||
CanDerive::Manually | ||
} | ||
(DeriveTrait::Default, TypeKind::UnresolvedTypeRef(..)) => { | ||
unreachable!( | ||
|
Uh oh!
There was an error while loading. Please reload this page.