diff --git a/src/codegen/mod.rs b/src/codegen/mod.rs index 7350bb4920..4ebc48bfb6 100644 --- a/src/codegen/mod.rs +++ b/src/codegen/mod.rs @@ -38,21 +38,24 @@ struct CodegenResult { items: Vec
>,
saw_union: bool,
items_seen: HashSet >
where F: FnOnce(&mut Self)
{
@@ -265,23 +277,30 @@ impl CodeGenerator for Var {
ctx: &BindgenContext,
result: &mut CodegenResult,
item: &Item) {
- let name = item.canonical_name(ctx);
+ let canonical_name = item.canonical_name(ctx);
+
+ if result.seen_var(&canonical_name) {
+ return;
+ }
+ result.saw_var(&canonical_name);
+
let ty = self.ty().to_rust_ty(ctx);
if let Some(val) = self.val() {
- let const_item = aster::AstBuilder::new().item().pub_().const_(name)
+ let const_item = aster::AstBuilder::new().item().pub_()
+ .const_(canonical_name)
.expr().int(val).build(ty);
result.push(const_item)
} else {
let mut attrs = vec![];
if let Some(mangled) = self.mangled_name() {
attrs.push(attributes::link_name(mangled));
- } else if name != self.name() {
+ } else if canonical_name != self.name() {
attrs.push(attributes::link_name(self.name()));
}
let item = ast::ForeignItem {
- ident: ctx.rust_ident_raw(&name),
+ ident: ctx.rust_ident_raw(&canonical_name),
attrs: attrs,
node: ast::ForeignItemKind::Static(ty, !self.is_const()),
id: ast::DUMMY_NODE_ID,
diff --git a/tests/expectations/decl_extern_int_twice.rs b/tests/expectations/decl_extern_int_twice.rs
new file mode 100644
index 0000000000..603a51b14f
--- /dev/null
+++ b/tests/expectations/decl_extern_int_twice.rs
@@ -0,0 +1,10 @@
+/* automatically generated by rust-bindgen */
+
+
+#![allow(non_snake_case)]
+
+
+extern "C" {
+ #[link_name = "foo"]
+ pub static mut foo: ::std::os::raw::c_int;
+}
diff --git a/tests/headers/decl_extern_int_twice.h b/tests/headers/decl_extern_int_twice.h
new file mode 100644
index 0000000000..06f80e8715
--- /dev/null
+++ b/tests/headers/decl_extern_int_twice.h
@@ -0,0 +1,2 @@
+extern int foo;
+extern int foo;