diff --git a/src/codegen/mod.rs b/src/codegen/mod.rs index 203da256b8..fdbce07393 100644 --- a/src/codegen/mod.rs +++ b/src/codegen/mod.rs @@ -223,6 +223,7 @@ struct CodegenResult<'a> { /// Being these two different declarations. functions_seen: HashSet, vars_seen: HashSet, + structs_seen: HashSet, /// Used for making bindings to overloaded functions. Maps from a canonical /// function name to the number of overloads we have already codegen'd for @@ -242,6 +243,7 @@ impl<'a> CodegenResult<'a> { codegen_id: codegen_id, items_seen: Default::default(), functions_seen: Default::default(), + structs_seen: Default::default(), vars_seen: Default::default(), overload_counters: Default::default(), } @@ -283,6 +285,14 @@ impl<'a> CodegenResult<'a> { self.functions_seen.insert(name.into()); } + fn seen_struct(&self, name: &str) -> bool { + self.structs_seen.contains(name) + } + + fn saw_struct(&mut self, name: &str) { + self.structs_seen.insert(name.into()); + } + /// Get the overload number for the given function name. Increments the /// counter internally so the next time we ask for the overload for this /// name, we get the incremented value, and so on. @@ -1646,6 +1656,10 @@ impl CodeGenerator for CompInfo { let canonical_name = item.canonical_name(ctx); let canonical_ident = ctx.rust_ident(&canonical_name); + + if result.seen_struct(canonical_name.as_str()) { + return; + } // Generate the vtable from the method list if appropriate. // @@ -2169,6 +2183,10 @@ impl CodeGenerator for CompInfo { } }); } + + if !fields.is_empty() { + result.saw_struct(canonical_name.as_str()); + } } }