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

Vector fixes #148

Merged
merged 102 commits into from
Apr 26, 2020
Merged

Vector fixes #148

merged 102 commits into from
Apr 26, 2020

Conversation

dtolnay
Copy link
Owner

@dtolnay dtolnay commented Apr 26, 2020

This is a followup to #67 to get the std::vector and std::vec::Vec bindings in better shape.

The vector support needs to be covered by our test suite, but it doesn't
need to be featured to this extent in our intro code.
It's possible for `std` to mean something different from `::std` if the
user's ffi mod contains a type named `std`.
A vector whose element type is highly aligned need not itself be highly
aligned. If C++ passed in a reference to a vector which is less aligned
than its element type, and Rust thought vectors were more highly aligned
then they really are, then that would have been undefined behavior.
This autotrait impl is already inferred.
I assume VectorTarget was copied from the naming of UniquePtrTarget, but
pointers have a "target" (i.e. Deref<Target = T>) while vectors have an
"element".
We only implement VectorElement for sized types anyway.
Vectors have elements, not targets. Pointers have targets.
The previous logic incorrectly accepted Atoms outside the intended set,
and also emitted duplicate errors for opaque C++ types.
These will need to diverge shortly; in particular we'd like to support
Rust vectors containing Rust strings and C++ vectors containing C++
strings.
Without this, on some compilers:

    src/cxx.cc:252:30: error: specialization of ‘template<class T> rust::cxxbridge02::Vec<T>::Vec()’ in different namespace [-fpermissive]
       rust::Vec<CXX_TYPE>::Vec() noexcept {
                                  ^
    src/cxx.cc:274:3: note: in expansion of macro ‘RUST_VEC_OPS’
       MACRO(u8, uint8_t)
       ^
    src/cxx.cc:295:1: note: in expansion of macro ‘FOR_EACH_SIZED_PRIMITIVE’
     FOR_EACH_SIZED_PRIMITIVE(RUST_VEC_OPS)
     ^
    In file included from src/cxx.cc:1:0:
    include/cxx.h:216:3: error:   from definition of ‘template<class T> rust::cxxbridge02::Vec<T>::Vec()’ [-fpermissive]
       Vec() noexcept;
       ^
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.

1 participant