bytecodealliance / bytecodealliance/wit-bindgen

Rust: Wrong lifetime parameters for generated struct

Open
#974 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Rust
Stars
1.5k
Forks
286
Avg merge
6h 32m
Merged PRs (30d)
19

Description

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:repro@0.0.1;

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

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

```rust
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],
}
);
}
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.