Skip to content
Merged
Show file tree
Hide file tree
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
16 changes: 5 additions & 11 deletions crates/rust/src/bindgen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -395,20 +395,14 @@ impl Bindgen for FunctionBindgen<'_, '_> {

let dealiased_resource = dealias(resolve, *resource);

let name = self.r#gen.type_path(dealiased_resource, true);
let result = if is_own {
let name = self.r#gen.type_path(dealiased_resource, true);
format!("{name}::from_handle({op} as u32)")
} else if self.r#gen.is_exported_resource(*resource) {
let name = resolve.types[*resource]
.name
.as_deref()
.unwrap()
.to_upper_camel_case();
format!("{name}Borrow::lift({op} as u32 as usize)")
} else {
let tmp = format!("handle{}", self.tmp());
self.handle_decls.push(format!("let {tmp};"));
let name = self.r#gen.type_path(dealiased_resource, true);
format!(
"{{\n
{tmp} = {name}::from_handle({op} as u32);
Expand Down Expand Up @@ -901,14 +895,14 @@ impl Bindgen for FunctionBindgen<'_, '_> {
self.push_str(&prev_src);
let constructor_type = match &func.kind {
FunctionKind::Freestanding | FunctionKind::AsyncFreestanding => {
self.push_str(&format!("T::{}", to_rust_ident(func.item_name())));
self.push_str(&format!("T_::{}", to_rust_ident(func.item_name())));
None
}
FunctionKind::Method(_)
| FunctionKind::Static(_)
| FunctionKind::AsyncMethod(_)
| FunctionKind::AsyncStatic(_) => {
self.push_str(&format!("T::{}", to_rust_ident(func.item_name())));
self.push_str(&format!("T_::{}", to_rust_ident(func.item_name())));
None
}
FunctionKind::Constructor(ty) => {
Expand All @@ -922,10 +916,10 @@ impl Bindgen for FunctionBindgen<'_, '_> {

match return_type {
ConstructorReturnType::Self_ => {
self.push_str(&format!("{ty}::new(T::new"));
self.push_str(&format!("{ty}::new(T_::new"));
}
ConstructorReturnType::Result { .. } => {
self.push_str(&format!("T::new"));
self.push_str(&format!("T_::new"));
}
}

Expand Down
4 changes: 2 additions & 2 deletions crates/rust/src/interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1058,7 +1058,7 @@ unsafe fn call_import(&mut self, _params: Self::ParamsLower, _results: *mut u8)
"\
#[doc(hidden)]
#[allow(non_snake_case, unused_unsafe)]
pub unsafe fn _export_{name_snake}_cabi<T: {trait_name}>\
pub unsafe fn _export_{name_snake}_cabi<T_: {trait_name}>\
",
);
let params = self.print_export_sig(func, async_);
Expand Down Expand Up @@ -1144,7 +1144,7 @@ unsafe fn call_import(&mut self, _params: Self::ParamsLower, _results: *mut u8)
"\
#[doc(hidden)]
#[allow(non_snake_case)]
pub unsafe fn __post_return_{name_snake}<T: {trait_name}>\
pub unsafe fn __post_return_{name_snake}<T_: {trait_name}>\
"
);
let params = self.print_post_return_sig(func);
Expand Down
19 changes: 19 additions & 0 deletions tests/codegen/issue1466.wit
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package foo:foo;

interface original {
resource extra-options;
record options {
extra: option<borrow<extra-options>>,
}
}

interface adapter {
use original.{options};
variant t { a }
f: func(x: options, t: t);
}

world root {
export original;
export adapter;
}
Loading