no fields or methods created for opaque
@@ -1551,9 +1551,12 @@ impl CodeGenerator for CompInfo {
//
// Also, we need to generate the vtable in such a way it "inherits" from
// the parent too.
+ let is_opaque = item.is_opaque(ctx, &());
let mut fields = vec![];
let mut struct_layout =
StructLayoutTracker::new(ctx, self, &canonical_name);
+
+ if !is_opaque {
if self.needs_explicit_vtable(ctx, item) {
let vtable =
Vtable::new(item.id(), self.methods(), self.base_members());
@@ -1603,6 +1606,7 @@ impl CodeGenerator for CompInfo {
StructFieldBuilder::named(field_name).pub_().build_ty(inner);
fields.extend(Some(field));
}
+ }
if is_union {
result.saw_union();
if !self.can_be_rust_union(ctx) {
@@ -1610,17 +1614,15 @@ impl CodeGenerator for CompInfo {
}
}
- let layout = item.kind().expect_type().layout(ctx);
-
+ let mut methods = vec![];
+ if !is_opaque {
+ let mut anon_field_names = AnonFieldNames::default();
+ let codegen_depth = item.codegen_depth(ctx);
let fields_should_be_private =
item.annotations().private_fields().unwrap_or(false);
let struct_accessor_kind = item.annotations()
.accessor_kind()
.unwrap_or(FieldAccessorKind::None);
-
- let mut methods = vec![];
- let mut anon_field_names = AnonFieldNames::default();
- let codegen_depth = item.codegen_depth(ctx);
for field in self.fields() {
field.codegen(
ctx,
@@ -1636,8 +1638,10 @@ impl CodeGenerator for CompInfo {
(),
);
}
+ }
- if is_union {
+ let layout = item.kind().expect_type().layout(ctx);
+ if is_union && !is_opaque {
let layout = layout.expect("Unable to get layout information?");
let ty = BlobTyBuilder::new(layout).build();
@@ -1654,11 +1658,12 @@ impl CodeGenerator for CompInfo {
fields.push(field);
}
- // Yeah, sorry about that.
- let is_opaque = item.is_opaque(ctx, &());
if is_opaque {
- fields.clear();
- methods.clear();
+ // Opaque item should not have generated methods, fields
+ debug_assert!(fields.is_empty());
+ debug_assert!(methods.is_empty());
+ // fields.clear();
+ // methods.clear();
match layout {
Some(l) => {
