From bc08b355b2daf10565d368a87462c6d882460e55 Mon Sep 17 00:00:00 2001 From: Nick Fitzgerald Date: Thu, 29 Dec 2016 16:47:13 -0800 Subject: Do not derive Copy/Debug for some opaque types When we treat a type as opaque, either because it is explicitly annotated as such or because it is a template that has a non-type parameter, we need to check if the size is larger than RUST_DERIVE_IN_ARRAY_LIMIT. Performing this check requires information that is up the stack, in the `Item` rather than in the `CompInfo` or `Type`. Therefore, I introduced two traits to encapsulate whether a thing can derive `Debug` and `Copy` (the `CanDeriveDebug` and `CanDeriveCopy` traits, respectively) and implemented them for ALL THE THINGS. This allowes us to perform our various checks at the level where we have access to the necessary info, and to let sub-levels do their own checks with their sub-info. Fixes #372. --- libbindgen/src/codegen/mod.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'libbindgen/src/codegen/mod.rs') diff --git a/libbindgen/src/codegen/mod.rs b/libbindgen/src/codegen/mod.rs index 69d5f651..12aa7223 100644 --- a/libbindgen/src/codegen/mod.rs +++ b/libbindgen/src/codegen/mod.rs @@ -6,6 +6,7 @@ use aster; use ir::annotations::FieldAccessorKind; use ir::comp::{CompInfo, CompKind, Field, Method, MethodKind}; use ir::context::{BindgenContext, ItemId}; +use ir::derive::{CanDeriveCopy, CanDeriveDebug}; use ir::enum_ty::{Enum, EnumVariant, EnumVariantValue}; use ir::function::{Function, FunctionSig}; use ir::int::IntKind; @@ -765,12 +766,11 @@ impl CodeGenerator for CompInfo { let is_union = self.kind() == CompKind::Union; let mut derives = vec![]; - let ty = item.expect_type(); - if ty.can_derive_debug(ctx) { + if item.can_derive_debug(ctx, ()) { derives.push("Debug"); } - if item.can_derive_copy(ctx) && !item.annotations().disallow_copy() { + if item.can_derive_copy(ctx, ()) && !item.annotations().disallow_copy() { derives.push("Copy"); if !applicable_template_args.is_empty() { // FIXME: This requires extra logic if you have a big array in a -- cgit v1.2.3