Commit Graph

640 Commits

Author SHA1 Message Date
David Tolnay
e5cd1489e3
Fix remaining "C-linkage specified, but returns UDT" warnings on macOS 2021-01-02 21:28:14 -08:00
David Tolnay
8f940cf269
Explicitly delete opaque Rust type destructors
I guess MSVC finds this important enough to emit warnings about.

    cxxbridge\sources\tests\ffi\lib.rs.cc(1220): warning C4624: 'tests::R': destructor was implicitly defined as deleted
2021-01-02 18:45:02 -08:00
David Tolnay
fe77f3323b
Resolve MSVC "C-linkage specified, but returns UDT" warning
cxxbridge\sources\tests\ffi\lib.rs.cc(1335): warning C4190: 'tests$cxxbridge1$c_return_str' has C-linkage specified, but returns UDT 'rust::cxxbridge1::Str' which is incompatible with C
    cxxbridge\include\rust/cxx.h(93): note: see declaration of 'rust::cxxbridge1::Str'
    cxxbridge\sources\tests\ffi\lib.rs.cc(1340): warning C4190: 'tests$cxxbridge1$c_return_slice_char' has C-linkage specified, but returns UDT 'rust::cxxbridge1::Slice<const char>' which is incompatible with C
    cxxbridge\crate\tests/ffi/tests.h(93): note: see declaration of 'rust::cxxbridge1::Slice<const char>'
    cxxbridge\sources\tests\ffi\lib.rs.cc(1345): warning C4190: 'tests$cxxbridge1$c_return_mutsliceu8' has C-linkage specified, but returns UDT 'rust::cxxbridge1::Slice<uint8_t>' which is incompatible with C
    cxxbridge\crate\tests/ffi/tests.h(94): note: see declaration of 'rust::cxxbridge1::Slice<uint8_t>'
    cxxbridge\sources\tests\ffi\lib.rs.cc(1976): warning C4190: 'tests$cxxbridge1$r_return_str' has C-linkage specified, but returns UDT 'rust::cxxbridge1::Str' which is incompatible with C
    cxxbridge\include\rust/cxx.h(93): note: see declaration of 'rust::cxxbridge1::Str'
    cxxbridge\sources\tests\ffi\lib.rs.cc(1978): warning C4190: 'tests$cxxbridge1$r_return_sliceu8' has C-linkage specified, but returns UDT 'rust::cxxbridge1::Slice<const uint8_t>' which is incompatible with C
    cxxbridge\crate\tests/ffi/tests.h(163): note: see declaration of 'rust::cxxbridge1::Slice<const uint8_t>'
    cxxbridge\sources\tests\ffi\lib.rs.cc(1980): warning C4190: 'tests$cxxbridge1$r_return_mutsliceu8' has C-linkage specified, but returns UDT 'rust::cxxbridge1::Slice<uint8_t>' which is incompatible with C
    cxxbridge\crate\tests/ffi/tests.h(94): note: see declaration of 'rust::cxxbridge1::Slice<uint8_t>'
2021-01-02 18:34:50 -08:00
David Tolnay
8b22953347
Reduce indentation in write_data_structures 2021-01-02 18:30:45 -08:00
David Tolnay
36614d60d4
Move triviality static assertions to implementation files only 2021-01-02 18:30:15 -08:00
David Tolnay
e05de8796e
Move template class workaround to implementation files only 2021-01-02 18:21:06 -08:00
Cameron Pickett
3351bc7898 Fix warning mismatching struct and class
Fix for warning when running cargo test.

```
warning: /Users/pickett/Documents/GitHub/cxx/target/debug/build/cxx-test-suite-de711daed7f2e46d/out/cxxbridge/sources/tests/ffi/lib.rs.cc:1256:10: warning: struct template 'Slice' was previously declared as a class template; this is valid, but may result in linker errors under the Microsoft C++ ABI [-Wmismatched-tags]
warning: template struct ::rust::Slice<const char>;
warning:          ^
warning: /Users/pickett/Documents/GitHub/cxx/target/debug/build/cxx-test-suite-de711daed7f2e46d/out/cxxbridge/include/rust/cxx.h:146:7: note: previous use is here
warning: class Slice final
warning:       ^
warning: /Users/pickett/Documents/GitHub/cxx/target/debug/build/cxx-test-suite-de711daed7f2e46d/out/cxxbridge/sources/tests/ffi/lib.rs.cc:1256:10: note: did you mean class here?
warning: template struct ::rust::Slice<const char>;
warning:          ^~~~~~
warning:          class
```
2021-01-02 12:21:24 +00:00
David Tolnay
14dc792980
Restrict MSVC instantiation workaround to return positions only 2021-01-02 01:14:44 -08:00
David Tolnay
681f5c82cd
Remove rust::Slice repr conversion on the C++ side 2021-01-02 00:46:49 -08:00
David Tolnay
c45b6766f5
Merge pull request #637 from dtolnay/msvc
MSVC workaround for "C linkage function cannot return C++ class"
2021-01-02 00:46:05 -08:00
David Tolnay
7f65e7cda7
Remove rust::Str repr conversion on the C++ side 2021-01-02 00:34:19 -08:00
David Tolnay
440e24a29a
MSVC workaround for "C linkage function cannot return C++ class"
MSVC fails to compile code like the following unless there is an
explicit instantiation of the class template:

    template <typename T>
    class slice {};

    //template class slice<int>;

    extern "C" slice<int> repro() { return {}; }

Error:

    <source>(6): error C2526: 'repro': C linkage function cannot return C++ class 'slice<int>'
    <source>(6): note: see declaration of 'slice<int>'
    <source>(6): error C2562: 'repro': 'void' function returning a value
    <source>(6): note: see declaration of 'repro'
    Compiler returned: 2
2021-01-02 00:27:15 -08:00
David Tolnay
1e5fe237d8
Record lifetimes associated with generic type instantiation 2021-01-01 18:28:28 -08:00
David Tolnay
ed6ba4a63c
Add ForeignName wrapper around non-Rust names 2021-01-01 17:57:14 -08:00
David Tolnay
84ed6adda5
Track independent Rust/C++ names on struct fields and fn args 2021-01-01 15:46:10 -08:00
David Tolnay
3abed4794a
Generate all explicit and implicit impls based on one map 2021-01-01 14:28:38 -08:00
David Tolnay
77a5e758e6
Rename RustName -> NamedType 2021-01-01 14:15:26 -08:00
David Tolnay
95bc57fc47
Remove RustName::to_symbol in favor of explicit resolve 2021-01-01 13:36:49 -08:00
David Tolnay
bbcd75c0d1
Pull in syn 1.0.57 for const Punctuated::new support 2021-01-01 13:04:55 -08:00
David Tolnay
e352c1e140
Add wrapper to prevent iteration of unordered maps 2020-12-31 17:15:56 -08:00
David Tolnay
4c6052d749
Key impls by an enum rather than by Type 2020-12-31 15:31:28 -08:00
David Tolnay
5573e529e5
Emit docs on struct fields into generated C++ code 2020-12-31 11:07:52 -08:00
David Tolnay
3fab70e0de
Release 1.0.25 2020-12-31 10:51:19 -08:00
David Tolnay
5b41c09e9a
Defer Cargo links metadata printing until after code generation
This results in slightly less noise when code generation produces an
error during a Cargo build.

Before:

    process didn't exit successfully: `/git/example-cxx/target/debug/build/example-f20ef12178a95a23/build-script-build` (exit code: 1)
    --- stdout
    cargo:CXXBRIDGE_PREFIX=example
    cargo:CXXBRIDGE_DIR0=/git/example-cxx/target/debug/build/example-188c8410ffc8bb7d/out/cxxbridge/include
    cargo:CXXBRIDGE_DIR1=/git/example-cxx/target/debug/build/example-188c8410ffc8bb7d/out/cxxbridge/crate

    --- stderr

    error[cxxbridge]: extern type with lifetimes is not supported yet
      ┌─ src/main.rs:9:21
      │
    9 │         type Object<'a>;
      │                     ^^ extern type with lifetimes is not supported yet

After:

    process didn't exit successfully: `/git/example-cxx/target/debug/build/example-f20ef12178a95a23/build-script-build` (exit code: 1)
    --- stderr

    error[cxxbridge]: extern type with lifetimes is not supported yet
      ┌─ src/main.rs:9:21
      │
    9 │         type Object<'a>;
      │                     ^^ extern type with lifetimes is not supported yet
2020-12-30 20:11:33 -08:00
David Tolnay
524ff68081
Fix span placement on extern C++ type 2020-12-30 17:29:12 -08:00
David Tolnay
067638ea15
Store passthrough attributes for diagnostic lint levels 2020-12-30 16:50:05 -08:00
David Tolnay
4486f7261e
Preserve doc comments on enum variants 2020-12-30 00:01:26 -08:00
David Tolnay
b478fcbf0f
Add C++ symbol visibility annotations for Rust functions and impls 2020-12-29 16:48:02 -08:00
David Tolnay
1eadd2639a
Extract function for writing cxx_impl_annotations 2020-12-29 16:42:08 -08:00
David Tolnay
a5b8c38dc4
Release 1.0.24 2020-12-29 16:04:24 -08:00
David Tolnay
6064592053
Recognize .hh and .hpp as header extensions in cxxbridge-cmd 2020-12-29 15:53:01 -08:00
David Tolnay
9e3df911c5
Resolve redundant_closure_for_method_calls pedantic clippy lint 2020-12-29 15:33:28 -08:00
David Tolnay
6208af9ab5
Resolve map_flatten pedantic clippy lint 2020-12-29 15:30:56 -08:00
David Tolnay
05aa672b1e
Suppress all currently triggered clippy pedantic lints 2020-12-29 15:28:02 -08:00
David Tolnay
515cef8044
Format PR 613 with rustfmt 1.4.30-nightly 2020-12-29 15:19:55 -08:00
Per Mosegaard
ce088848c5
add support for .hh and .hpp headers 2020-12-29 21:10:14 +00:00
David Tolnay
ee3123241f
Store additional token information with extern type lifetimes 2020-12-28 22:12:28 -08:00
David Tolnay
3d2ef674a4
Add lifetimes to ExternType and TypeAlias syntax tree 2020-12-28 21:04:11 -08:00
David Tolnay
cb9408df8b
Release 1.0.23 2020-12-28 18:38:44 -08:00
David Tolnay
7a48785a8e
Add upgrade conversion from WeakPtr to SharedPtr 2020-12-28 18:09:55 -08:00
David Tolnay
85b6bc4a39
Add downgrade conversion from SharedPtr to WeakPtr 2020-12-28 18:06:17 -08:00
David Tolnay
215e77fbec
Add Rust std::weak_ptr binding 2020-12-28 17:41:20 -08:00
David Tolnay
7f056cdf46
Release 1.0.22 2020-12-28 11:42:43 -08:00
David Tolnay
8729da81ae
Clean up guards from C++ standard library type shims
These shims are only emitted into the cc file, not any headers, so there
is no way they would end up more than once in the compiled code.
2020-12-27 22:34:12 -08:00
David Tolnay
f7af2655c7
Clean up some unneeded guards on Box and Vec externs
These blocks contain extern function declarations only, not definitions.
It's okay for declarations to be repeated so the guard serves no
purpose.
2020-12-27 22:23:45 -08:00
David Tolnay
725bf505b4
Reuse Slice<T>'s iterator for Vec iteration too 2020-12-27 13:38:44 -08:00
David Tolnay
e1df7ddba0
Eliminate Vec stride symbol in favor of size_of 2020-12-27 13:29:06 -08:00
David Tolnay
5ce110e807
Update Slice implementation to respect runtime size_of 2020-12-27 13:19:45 -08:00
David Tolnay
eee622c4ac
Obtain accurate alignment for empty slice of opaque Rust type 2020-12-27 13:08:09 -08:00
David Tolnay
6f92baa8ff
Obtain Slice iterator stride in a way that works for opaque types 2020-12-27 12:59:47 -08:00