Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rust: error in record with resource #668

Closed
omersadika opened this issue Sep 13, 2023 · 1 comment · Fixed by #669
Closed

Rust: error in record with resource #668

omersadika opened this issue Sep 13, 2023 · 1 comment · Fixed by #669

Comments

@omersadika
Copy link

An example for a wit file that cause the error:

package test:test

interface test-import {
  resource resource-a {
    constructor(id: u32)
  }

  record record-a {
    resource-a: resource-a,
    resources: list<resource-a>,
  }

  resource resource-b {
    make: static func(record-a: record-a)
  }
}

world test-world {
  import test-import

}

With this rust code:

wit_bindgen::generate!({
    world: "test-world",
});

I get the following error:

error[E0507]: cannot move out of `*resource_a0` which is behind a shared reference
 --> src/lib.rs:1:1
  |
1 | / wit_bindgen::generate!({
2 | |     world: "test-world",
3 | | });
  | |  ^
  | |  |
  | |__`*resource_a0` moved due to this method call
  |    move occurs because `*resource_a0` has type `ResourceA`, which does not implement the `Copy` trait
  |
note: `ResourceA::into_handle` takes ownership of the receiver `self`, which moves `*resource_a0`
 --> src/lib.rs:1:1
  |
1 | / wit_bindgen::generate!({
2 | |     world: "test-world",
3 | | });
  | |__^
  = note: this error originates in the macro `wit_bindgen::generate` (in Nightly builds, run with -Z macro-backtrace for more info)

For more information about this error, try `rustc --explain E0507`.
error: could not compile `wasm-component-test` (lib) due to previous error

The combination that cause the error is a field of a resource and a another field with a list of the same type resource. If I remove one of the field, it compiles with no error.

alexcrichton added a commit to alexcrichton/witx-bindgen that referenced this issue Sep 14, 2023
I went ahead and did a bit more refactoring at the logic here since I
think the old conditions aren't as applicable any more (they haven't
aged well)

Closes bytecodealliance#668
@alexcrichton
Copy link
Member

Thanks for the report! I think this should be fixed by #669

sunfishcode pushed a commit that referenced this issue Sep 18, 2023
* Fix taking owned resource handles in Rust imports

I went ahead and did a bit more refactoring at the logic here since I
think the old conditions aren't as applicable any more (they haven't
aged well)

Closes #668

* Fix test compilation

* Ignore some more resources tests
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants