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

Limit instantiation of Vec and Box shims to local element type #555

Merged
merged 1 commit into from
Dec 10, 2020
Merged

Conversation

dtolnay
Copy link
Owner

@dtolnay dtolnay commented Dec 10, 2020

This fixes a hole in the combination of #541 + #542 (which is why I'd excluded those PRs from the most recent release).

Without this restriction, the following crates would have typechecked but caused duplicate symbols which is UB:

// crate A

#[cxx::bridge]
mod ffi {
    struct S { x: i32 }
}
// crate B which depends on A

#[cxx::bridge]
mod ffi {
    extern "C++" {
        type S = a::S;
    }
    impl Vec<S> {}
}
// crate C which depends on A

#[cxx::bridge]
mod ffi {
    extern "C++" {
        type S = a::S;
    }
    impl Vec<S> {}
}

The nonlocal types design described in #496 (comment) prohibits the code in crates B and C (unsafe impl Vec<S> would be required for a nonlocal type S) but is not implemented yet. For now this PR is a pretty blunt restriction and will get substantially relaxed as #496 gets implemented.

@dtolnay dtolnay merged commit 0dee4b4 into master Dec 10, 2020
@dtolnay dtolnay deleted the impl branch December 10, 2020 06:51
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.

None yet

1 participant