From cacf0a12e8d95bf11a228a6177dc27dcdaa63969 Mon Sep 17 00:00:00 2001 From: Archisman Mridha Date: Mon, 12 Feb 2024 21:45:15 +0530 Subject: [PATCH] Fix generating interface names which are Rust keywords Signed-off-by: Archisman Mridha --- crates/component-macro/tests/codegen.rs | 14 ++++++++++++++ crates/wit-bindgen/src/lib.rs | 4 ++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/crates/component-macro/tests/codegen.rs b/crates/component-macro/tests/codegen.rs index 66f9fb1c26bb..c7fb0f51a72d 100644 --- a/crates/component-macro/tests/codegen.rs +++ b/crates/component-macro/tests/codegen.rs @@ -148,3 +148,17 @@ mod trappable_errors { #[allow(dead_code)] type MyX = u32; } + +mod interface_name_with_rust_keyword { + wasmtime::component::bindgen!({ + inline: " + package foo:foo; + + interface crate { } + + world foo { + export crate; + } + " + }); +} diff --git a/crates/wit-bindgen/src/lib.rs b/crates/wit-bindgen/src/lib.rs index a73f6bcca4e5..4b65e7455ba2 100644 --- a/crates/wit-bindgen/src/lib.rs +++ b/crates/wit-bindgen/src/lib.rs @@ -185,7 +185,7 @@ impl Wasmtime { let pkgname = &resolve.packages[iface.package.unwrap()].name; path.push(pkgname.namespace.to_snake_case()); path.push(self.name_package_module(resolve, iface.package.unwrap())); - path.push(iface.name.as_ref().unwrap().to_snake_case()); + path.push(to_rust_ident(iface.name.as_ref().unwrap())); } } let entry = if let Some(remapped_path) = self.lookup_replacement(resolve, name, None) { @@ -440,7 +440,7 @@ impl Wasmtime { } let module = &gen.src[..]; - let snake = iface_name.to_snake_case(); + let snake = to_rust_ident(iface_name); let module = format!( "