Skip to content

Skip redundant type definition generation in the wit_bindgen::generate! for the remapped types defined in the WIT source #730

@greenhat

Description

@greenhat

Discovered while working on #722

Why

The Rust user-defined type (e.g. EnumA) 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions