summaryrefslogtreecommitdiff
path: root/src/ir/analysis/derive_debug.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/ir/analysis/derive_debug.rs')
-rw-r--r--src/ir/analysis/derive_debug.rs120
1 files changed, 71 insertions, 49 deletions
diff --git a/src/ir/analysis/derive_debug.rs b/src/ir/analysis/derive_debug.rs
index 8f2be22a..14630155 100644
--- a/src/ir/analysis/derive_debug.rs
+++ b/src/ir/analysis/derive_debug.rs
@@ -1,17 +1,17 @@
//! Determining which types for which we can emit `#[derive(Debug)]`.
use super::{ConstrainResult, MonotoneFramework, generate_dependencies};
-use std::collections::HashSet;
-use std::collections::HashMap;
+use ir::comp::CompKind;
+use ir::comp::Field;
+use ir::comp::FieldMethods;
use ir::context::{BindgenContext, ItemId};
+use ir::derive::CanTriviallyDeriveDebug;
use ir::item::IsOpaque;
use ir::traversal::EdgeKind;
use ir::ty::RUST_DERIVE_IN_ARRAY_LIMIT;
use ir::ty::TypeKind;
-use ir::comp::Field;
-use ir::comp::FieldMethods;
-use ir::derive::CanTriviallyDeriveDebug;
-use ir::comp::CompKind;
+use std::collections::HashMap;
+use std::collections::HashSet;
/// An analysis that finds for each IR item whether debug cannot be derived.
///
@@ -34,7 +34,8 @@ use ir::comp::CompKind;
/// cannot derive debug.
#[derive(Debug, Clone)]
pub struct CannotDeriveDebug<'ctx, 'gen>
- where 'gen: 'ctx
+where
+ 'gen: 'ctx,
{
ctx: &'ctx BindgenContext<'gen>,
@@ -141,7 +142,10 @@ impl<'ctx, 'gen> MonotoneFramework for CannotDeriveDebug<'ctx, 'gen> {
};
}
- if ty.layout(self.ctx).map_or(false, |l| l.align > RUST_DERIVE_IN_ARRAY_LIMIT) {
+ if ty.layout(self.ctx).map_or(false, |l| {
+ l.align > RUST_DERIVE_IN_ARRAY_LIMIT
+ })
+ {
// We have to be conservative: the struct *could* have enough
// padding that we emit an array that is longer than
// `RUST_DERIVE_IN_ARRAY_LIMIT`. If we moved padding calculations
@@ -162,7 +166,7 @@ impl<'ctx, 'gen> MonotoneFramework for CannotDeriveDebug<'ctx, 'gen> {
TypeKind::Enum(..) |
TypeKind::Reference(..) |
TypeKind::BlockPointer |
- TypeKind::Named |
+ TypeKind::TypeParam |
TypeKind::UnresolvedTypeRef(..) |
TypeKind::ObjCInterface(..) |
TypeKind::ObjCId |
@@ -173,8 +177,10 @@ impl<'ctx, 'gen> MonotoneFramework for CannotDeriveDebug<'ctx, 'gen> {
TypeKind::Array(t, len) => {
if self.cannot_derive_debug.contains(&t) {
- trace!(" arrays of T for which we cannot derive Debug \
- also cannot derive Debug");
+ trace!(
+ " arrays of T for which we cannot derive Debug \
+ also cannot derive Debug"
+ );
return self.insert(id);
}
@@ -191,12 +197,16 @@ impl<'ctx, 'gen> MonotoneFramework for CannotDeriveDebug<'ctx, 'gen> {
TypeKind::TemplateAlias(t, _) |
TypeKind::Alias(t) => {
if self.cannot_derive_debug.contains(&t) {
- trace!(" aliases and type refs to T which cannot derive \
- Debug also cannot derive Debug");
+ trace!(
+ " aliases and type refs to T which cannot derive \
+ Debug also cannot derive Debug"
+ );
self.insert(id)
} else {
- trace!(" aliases and type refs to T which can derive \
- Debug can also derive Debug");
+ trace!(
+ " aliases and type refs to T which can derive \
+ Debug can also derive Debug"
+ );
ConstrainResult::Same
}
}
@@ -213,9 +223,10 @@ impl<'ctx, 'gen> MonotoneFramework for CannotDeriveDebug<'ctx, 'gen> {
return self.insert(id);
}
- if ty.layout(self.ctx)
- .map_or(true,
- |l| l.opaque().can_trivially_derive_debug()) {
+ if ty.layout(self.ctx).map_or(true, |l| {
+ l.opaque().can_trivially_derive_debug()
+ })
+ {
trace!(" union layout can trivially derive Debug");
return ConstrainResult::Same;
} else {
@@ -224,32 +235,33 @@ impl<'ctx, 'gen> MonotoneFramework for CannotDeriveDebug<'ctx, 'gen> {
}
}
- let bases_cannot_derive = info.base_members()
- .iter()
- .any(|base| self.cannot_derive_debug.contains(&base.ty));
+ let bases_cannot_derive =
+ info.base_members().iter().any(|base| {
+ self.cannot_derive_debug.contains(&base.ty)
+ });
if bases_cannot_derive {
- trace!(" base members cannot derive Debug, so we can't \
- either");
+ trace!(
+ " base members cannot derive Debug, so we can't \
+ either"
+ );
return self.insert(id);
}
- let fields_cannot_derive = info.fields()
- .iter()
- .any(|f| {
- match *f {
- Field::DataMember(ref data) => {
- self.cannot_derive_debug.contains(&data.ty())
- }
- Field::Bitfields(ref bfu) => {
- bfu.bitfields()
- .iter().any(|b| {
- self.cannot_derive_debug.contains(&b.ty())
- })
- }
+ let fields_cannot_derive =
+ info.fields().iter().any(|f| match *f {
+ Field::DataMember(ref data) => {
+ self.cannot_derive_debug.contains(&data.ty())
+ }
+ Field::Bitfields(ref bfu) => {
+ bfu.bitfields().iter().any(|b| {
+ self.cannot_derive_debug.contains(&b.ty())
+ })
}
});
if fields_cannot_derive {
- trace!(" fields cannot derive Debug, so we can't either");
+ trace!(
+ " fields cannot derive Debug, so we can't either"
+ );
return self.insert(id);
}
@@ -258,10 +270,13 @@ impl<'ctx, 'gen> MonotoneFramework for CannotDeriveDebug<'ctx, 'gen> {
}
TypeKind::Pointer(inner) => {
- let inner_type = self.ctx.resolve_type(inner).canonical_type(self.ctx);
+ let inner_type =
+ self.ctx.resolve_type(inner).canonical_type(self.ctx);
if let TypeKind::Function(ref sig) = *inner_type.kind() {
if !sig.can_trivially_derive_debug() {
- trace!(" function pointer that can't trivially derive Debug");
+ trace!(
+ " function pointer that can't trivially derive Debug"
+ );
return self.insert(id);
}
}
@@ -270,12 +285,15 @@ impl<'ctx, 'gen> MonotoneFramework for CannotDeriveDebug<'ctx, 'gen> {
}
TypeKind::TemplateInstantiation(ref template) => {
- let args_cannot_derive = template.template_arguments()
- .iter()
- .any(|arg| self.cannot_derive_debug.contains(&arg));
+ let args_cannot_derive =
+ template.template_arguments().iter().any(|arg| {
+ self.cannot_derive_debug.contains(&arg)
+ });
if args_cannot_derive {
- trace!(" template args cannot derive Debug, so \
- insantiation can't either");
+ trace!(
+ " template args cannot derive Debug, so \
+ insantiation can't either"
+ );
return self.insert(id);
}
@@ -283,11 +301,14 @@ impl<'ctx, 'gen> MonotoneFramework for CannotDeriveDebug<'ctx, 'gen> {
!template.template_definition().is_opaque(self.ctx, &()),
"The early ty.is_opaque check should have handled this case"
);
- let def_cannot_derive = self.cannot_derive_debug
- .contains(&template.template_definition());
+ let def_cannot_derive = self.cannot_derive_debug.contains(
+ &template.template_definition(),
+ );
if def_cannot_derive {
- trace!(" template definition cannot derive Debug, so \
- insantiation can't either");
+ trace!(
+ " template definition cannot derive Debug, so \
+ insantiation can't either"
+ );
return self.insert(id);
}
@@ -304,7 +325,8 @@ impl<'ctx, 'gen> MonotoneFramework for CannotDeriveDebug<'ctx, 'gen> {
}
fn each_depending_on<F>(&self, id: ItemId, mut f: F)
- where F: FnMut(ItemId),
+ where
+ F: FnMut(ItemId),
{
if let Some(edges) = self.dependencies.get(&id) {
for item in edges {