diff --git a/crates/rust/src/bindgen.rs b/crates/rust/src/bindgen.rs index 5ac5b60c0..4b3d75292 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); @@ -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) => { @@ -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")); } } 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 new file mode 100644 index 000000000..5718c870a --- /dev/null +++ b/tests/codegen/issue1466.wit @@ -0,0 +1,19 @@ +package foo:foo; + +interface original { + resource extra-options; + record options { + extra: option>, + } +} + +interface adapter { + use original.{options}; + variant t { a } + f: func(x: options, t: t); +} + +world root { + export original; + export adapter; +}