Skip to content

Commit 1317463

Browse files
authored
Fix symbol conflicts in exported Rust functions (#593)
Closes #592
1 parent e69cf5d commit 1317463

2 files changed

Lines changed: 36 additions & 1 deletion

File tree

crates/rust/src/lib.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -566,6 +566,7 @@ impl InterfaceGenerator<'_> {
566566
uwrite!(
567567
macro_src,
568568
"
569+
const _: () = {{
569570
#[doc(hidden)]
570571
#[export_name = \"{export_name}\"]
571572
#[allow(non_snake_case)]
@@ -647,7 +648,8 @@ impl InterfaceGenerator<'_> {
647648
for param in params.iter() {
648649
uwrite!(macro_src, "{param},");
649650
}
650-
uwriteln!(macro_src, ")\n}}");
651+
uwriteln!(macro_src, ")\n}}"); // close function call and function
652+
uwriteln!(macro_src, "\n}};"); // close `const _: () = { ...`
651653

652654
let mut f = FunctionBindgen::new(self, params);
653655
f.gen.resolve.call(

crates/rust/tests/codegen.rs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,3 +168,36 @@ mod skip {
168168

169169
export_baz!(Component);
170170
}
171+
172+
mod symbol_does_not_conflict {
173+
wit_bindgen::generate!({
174+
inline: "
175+
package my:inline
176+
177+
interface foo1 {
178+
foo: func()
179+
}
180+
181+
interface foo2 {
182+
foo: func()
183+
}
184+
185+
world foo {
186+
export foo1
187+
export foo2
188+
}
189+
",
190+
});
191+
192+
struct Component;
193+
194+
impl exports::my::inline::foo1::Foo1 for Component {
195+
fn foo() {}
196+
}
197+
198+
impl exports::my::inline::foo2::Foo2 for Component {
199+
fn foo() {}
200+
}
201+
202+
export_foo!(Component);
203+
}

0 commit comments

Comments
 (0)