wit-bindgen icon indicating copy to clipboard operation
wit-bindgen copied to clipboard

Rust: Wrong lifetime parameters for generated struct

Open simonask opened this issue 1 year ago • 0 comments

For a particular combination of use, import, and export with aggregate types (records containing lists), wit-bindgen generates invalid Rust, producing the following compiler error:

struct takes 0 lifetime arguments but 1 lifetime argument was supplied
expected 0 lifetime arguments

wit-bindgen seems to mistakenly think that the generated MyList has a lifetime parameter when creating a typedef for it in the binding scope:

pub type MyList<'a> =
                    super::super::super::super::repro::repro::my_interface::MyList<'a>;

world.wit

package repro:[email protected];

interface my-interface {
    record my-list {
        // Not reproducible without this.
        groups: list<u32>,
    }
}

interface plugin-core {
    use my-interface.{my-list};

    record info {
        // Not reproducible without this.
        settings: my-list,
    }
}

interface plugin {
    use plugin-core.{info};

    // Not reproducible without this.
    use my-interface.{my-list};

    // Not reproducible without this.
    get-plugin-info: func() -> info;
}

world my-world {
    export plugin;
}

lib.rs

pub mod bindings {
    wit_bindgen::generate!(
        {
            world: "my-world",
            path: "wit",
            // Not reproducible with `false`.
            generate_unused_types: true,
            // Not reproducible with `Owning`.
            ownership: Borrowing { duplicate_if_necessary: true },
            additional_derives: [PartialEq, Clone],
        }
    );
}

simonask avatar Jun 14 '24 11:06 simonask