Skip redundant type definition generation in the `wit_bindgen::generate!` for the remapped types defined in the WIT source
- 主要語言
- Rust
- 星號
- 115
- 分支
- 84
- 平均合併
- 1 天 8 小時
- 30 天內合併 PR
- 15
描述
Discovered while working on #722
### Why
The Rust user-defined type (e.g. [`EnumA`](https://github.com/0xMiden/compiler/blob/547e4d030389ac5f0967b38c98a6cd4049fee751/examples/basic-wallet/src/lib.rs?plain=1#L27-L30)) has its definition generated in the WIT by the `#[export_type]` and `#[component]` macros. Then the `wit_bindgen::generate!` macro generates the bindings which include type definitions for all types defined in WIT. So we end up with another type definition in the bindings.
The problem is that when a user types a type name LSP suggests two imports for the type and if the user picks the one from the generated bindings it will not compile.
Although we pass type remapping in the parameter in the macro and it uses the user-defined type in the bindings, there is still a type definition generated. This is because the type remapping I authored a while ago only skips type definition generation for the imported WIT types. Not the ones defined in the current WIT source.
### How
The type definition generation happens in https://github.com/bytecodealliance/wit-bindgen/blob/cff17ba4ff41a8c974eb5d2767aaae807aea9d4d/crates/rust/src/interface.rs?plain=1#L2559-L2561. The idea is to check if the type is in the `self.gen.with` (remapped) and skip the generation.
The goal is to not have a type definition for the remapped type defined in the WIT on `wit_bindgen::generate!` macro expansion.
貢獻指南
評估
這個 Issue 還沒有評估資料。