From 43202f34db9439d2009e98ca90c56bc3c0977c42 Mon Sep 17 00:00:00 2001 From: Yan Chen Date: Wed, 11 Feb 2026 19:23:27 -0800 Subject: [PATCH 1/3] fix borrowed handle lift --- crates/rust/src/bindgen.rs | 8 +------- tests/codegen/issue1466.wit | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 7 deletions(-) create mode 100644 tests/codegen/issue1466.wit diff --git a/crates/rust/src/bindgen.rs b/crates/rust/src/bindgen.rs index 5ac5b60c0..3fb72cc11 100644 --- a/crates/rust/src/bindgen.rs +++ b/crates/rust/src/bindgen.rs @@ -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); diff --git a/tests/codegen/issue1466.wit b/tests/codegen/issue1466.wit new file mode 100644 index 000000000..52e064a8f --- /dev/null +++ b/tests/codegen/issue1466.wit @@ -0,0 +1,18 @@ +package foo:foo; + +interface original { + resource extra-options; + record options { + extra: option>, + } +} + +interface adapter { + use original.{options}; + f: func(x: options); +} + +world root { + export original; + export adapter; +} From 923682e7330be2e9cb14dcdf163bee5eb8bf594e Mon Sep 17 00:00:00 2001 From: Yan Chen Date: Wed, 11 Feb 2026 19:55:07 -0800 Subject: [PATCH 2/3] rename export_cabi trait name from T to T_ --- crates/rust/src/bindgen.rs | 8 ++++---- crates/rust/src/interface.rs | 4 ++-- tests/codegen/issue1466.wit | 3 ++- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/crates/rust/src/bindgen.rs b/crates/rust/src/bindgen.rs index 3fb72cc11..4b3d75292 100644 --- a/crates/rust/src/bindgen.rs +++ b/crates/rust/src/bindgen.rs @@ -895,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) => { @@ -916,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")); } } diff --git a/crates/rust/src/interface.rs b/crates/rust/src/interface.rs index ae0f991c8..a35bcf2ec 100644 --- a/crates/rust/src/interface.rs +++ b/crates/rust/src/interface.rs @@ -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\ + pub unsafe fn _export_{name_snake}_cabi\ ", ); let params = self.print_export_sig(func, async_); @@ -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}\ + pub unsafe fn __post_return_{name_snake}\ " ); let params = self.print_post_return_sig(func); diff --git a/tests/codegen/issue1466.wit b/tests/codegen/issue1466.wit index 52e064a8f..ffda4bca5 100644 --- a/tests/codegen/issue1466.wit +++ b/tests/codegen/issue1466.wit @@ -9,7 +9,8 @@ interface original { interface adapter { use original.{options}; - f: func(x: options); + variant t { t } + f: func(x: options, t: t); } world root { From 6873c4f675ff441673286df9e363c3bdb23ba31e Mon Sep 17 00:00:00 2001 From: Yan Chen Date: Wed, 11 Feb 2026 21:44:13 -0800 Subject: [PATCH 3/3] fix --- tests/codegen/issue1466.wit | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/codegen/issue1466.wit b/tests/codegen/issue1466.wit index ffda4bca5..5718c870a 100644 --- a/tests/codegen/issue1466.wit +++ b/tests/codegen/issue1466.wit @@ -9,7 +9,7 @@ interface original { interface adapter { use original.{options}; - variant t { t } + variant t { a } f: func(x: options, t: t); }