Skip to content

Don't redefine structs that have been forward declared #1866

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

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions src/codegen/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ struct CodegenResult<'a> {
/// Being these two different declarations.
functions_seen: HashSet<String>,
vars_seen: HashSet<String>,
structs_seen: HashSet<String>,

/// Used for making bindings to overloaded functions. Maps from a canonical
/// function name to the number of overloads we have already codegen'd for
Expand All @@ -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(),
}
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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.
//
Expand Down Expand Up @@ -2169,6 +2183,10 @@ impl CodeGenerator for CompInfo {
}
});
}

if !fields.is_empty() {
result.saw_struct(canonical_name.as_str());
}
}
}

Expand Down