Skip to content

Commit 808d311

Browse files
authored
Fix bindings generation for bare function exports (#459)
* Fix bindings generation for bare function exports Move around a `use` statement * Fix post-return from top-level exports
1 parent ce99872 commit 808d311

2 files changed

Lines changed: 7 additions & 8 deletions

File tree

crates/gen-guest-rust/src/lib.rs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,9 @@ impl InterfaceGenerator<'_> {
327327
uwrite!(
328328
self.src,
329329
"
330+
#[allow(unused_imports)]
331+
use wit_bindgen_guest_rust::rt::{{alloc, vec::Vec, string::String}};
332+
330333
#[repr(align({align}))]
331334
struct _RetArea([u8; {size}]);
332335
static mut _RET_AREA: _RetArea = _RetArea([0; {size}]);
@@ -347,9 +350,6 @@ impl InterfaceGenerator<'_> {
347350
"
348351
#[allow(clippy::all)]
349352
pub mod {snake} {{
350-
#[allow(unused_imports)]
351-
use wit_bindgen_guest_rust::rt::{{alloc, vec::Vec, string::String}};
352-
353353
{module}
354354
}}
355355
"
@@ -528,11 +528,7 @@ impl InterfaceGenerator<'_> {
528528
macro_src.push_str(") {\n");
529529

530530
// Finish out the macro here
531-
uwrite!(
532-
macro_src,
533-
"{prefix}{module_name}::post_return_{name_snake}::<$t>(",
534-
prefix = self.gen.opts.macro_call_prefix.as_deref().unwrap_or("")
535-
);
531+
uwrite!(macro_src, "{prefix}post_return_{name_snake}::<$t>(");
536532
for param in params.iter() {
537533
uwrite!(macro_src, "{param},");
538534
}

tests/codegen/just-export.wit

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
default world foo {
2+
export generate: func(name: string, wit: list<u8>) -> result<list<tuple<string, list<u8>>>, string>
3+
}

0 commit comments

Comments
 (0)