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

tests/ffi: strange error with a function returning Vec<Buffer> #1098

Closed
wants to merge 2 commits into from

Conversation

naufraghi
Copy link

@naufraghi naufraghi commented Sep 19, 2022

The error triggers a warning for the Buffer field in Array that was already there but somehow silent.

cargo:warning=.../out/cxxbridge/sources/tests/ffi/lib.rs.cc:1387:45:
    error: static assertion failed: type tests::Buffer should be trivially
           move constructible and trivially destructible in C++ to be used
           as a field of `Array` or vector element in Vec<Buffer> in Rust
cargo:warning= 1387 |     ::rust::IsRelocatable<::tests::Buffer>::value,

The error triggers a warning for the Buffer field in Array
that was already there but somehow silent.

  cargo:warning=.../out/cxxbridge/sources/tests/ffi/lib.rs.cc:1387:45:
        error: static assertion failed: type tests::Buffer should be trivially
               move constructible and trivially destructible in C++ to be used
               as a field of `Array` or vector element in Vec<Buffer> in Rust
  cargo:warning= 1387 |     ::rust::IsRelocatable<::tests::Buffer>::value,
I'm not sure what's happening here, I had the doubt that the
tuple like struct was not supported, so I moved to a plain
struct with named fields and the error disappeared.

I think that this is not a solution, but only that I have
hidden again some issue in wrapping Trivial structs.
@naufraghi
Copy link
Author

Long story short, I'd like to use a trivial struct inside a Vec, but it did not work. I had to wrap it inside a struct as a field to have it work.

struct Foo {
   data: Vec<TrivialData>
}

does not link, missing Vec constructor.

struct DataWrapper {    // <--- shared
   d: TrivialData
}

struct Foo {
   data: Vec<DataWrapper>
}

So I dived into the code to understand if that case was covered, tried to add a test and found a strange error.

@naufraghi
Copy link
Author

I'd like to help, either adding support for the use case or improving the error or the documentation or the tests, feel free to suggest some direction and I'll have a look in my spare time. Thanks anyway!

@dtolnay
Copy link
Owner

dtolnay commented Sep 19, 2022

c858291 should work as of cxx 1.0.76.

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 this pull request may close these issues.

2 participants