87 Commits

Author SHA1 Message Date
David Tolnay
15a6c76352
Add test of invocation with multiple parse errors 2020-05-04 01:29:01 -07:00
Joel Galenson
db1ec31283 Expose the enum value to Rust as a field 2020-05-01 14:00:48 -07:00
David Tolnay
57d81a12fb
Merge pull request #180 from jgalenson/enums
Properly handle enum discriminant overflows.
2020-05-01 10:13:24 -07:00
Joel Galenson
04fa0967e2 Properly handle enum discriminant overflows.
This both checks for enum values that are illegal due to overflow and
ensures we do not overflow on valid enums.
2020-05-01 10:00:31 -07:00
David Tolnay
c4ddb4d172
Add tests for by-value-not-supported errors 2020-05-01 10:00:17 -07:00
David Tolnay
4037de267a
Use a better constant string idiom in test 2020-04-30 22:51:51 -07:00
David Tolnay
f5aeea2e4c
Touch up a variable name in vector test 2020-04-30 22:51:51 -07:00
David Tolnay
9beba146b7
Avoid relying on ADL for std::back_inserter 2020-04-30 22:51:50 -07:00
David Tolnay
d7984c2b7f
Touch up PR 170 2020-04-30 22:50:10 -07:00
David Tolnay
2b12b32113
Update PR 170 compiletests at nightly rustc 2020-04-30 22:03:25 -07:00
Joel Galenson
c03402aee5 Support C-style enums
This adds support for passing C-style enums between Rust and C++.

We use the Rust representation for enums suggested by dtolnay in #132.
Note that as this does not use real enums, Rust code cannot treat them
as normal enums, e.g., by converting them to integers.  But common
uses such as pattern matching remain unchanged.
2020-04-30 14:12:37 -07:00
David Tolnay
f8ed07327b
Split cxx runtime and build components 2020-04-29 18:23:14 -07:00
myronahn
da9be50ad8
Add all std::iterator_traits required types to const_iterator of rust::Vec<T> (#157)
https://en.cppreference.com/w/cpp/iterator/iterator_traits

`std::iterator_traits` requires the following 5 types:

- `difference_type` - a signed integer type that can be used to identify distance between iterators
- `value_type` - the type of the values that can be obtained by dereferencing the iterator. This type is void for output iterators.
- `pointer` - defines a pointer to the type iterated over (value_type)
- `reference` - defines a reference to the type iterated over (value_type)
- `iterator_category` - the category of the iterator. Must be one of iterator category tags.

The current `const_iterator` for `rust::Vec<T>` only defined `value_type` and `reference` which caused an error when using `std::copy` on gcc 7.5.0 on Ubuntu but seemed to work fine on MacOS.
2020-04-28 15:47:23 -07:00
David Tolnay
776fd8953d
Generalize reference-to-reference check to cover all positions
Checking this in check_type_ref allows it to apply anywhere that a
reference is written, such as return position which was not covered by
the previous logic.
2020-04-28 13:38:28 -07:00
Joel Galenson
2bd1312f2f Disallow passing a reference to a reference. 2020-04-28 10:14:41 -07:00
David Tolnay
378ca50c4c
Format PR 159 with clang-format 2020-04-27 16:47:55 -07:00
Joel Galenson
ba67607fa2 Allow wildcard argument names.
This adds support for wildcard variable names by internally giving
them unique names.
2020-04-27 16:00:50 -07:00
David Tolnay
83c69e92f7
Test Rust Vec in Rust signatures 2020-04-25 18:02:19 -07:00
David Tolnay
d2ce8a997b
Fix and test passing Vec by value from Rust to C 2020-04-25 18:02:19 -07:00
David Tolnay
7798969827
Fix and test returning Vec by reference from C to Rust 2020-04-25 18:02:19 -07:00
David Tolnay
8b9d176ea7
Fix and test fallible return of Vec from C to Rust 2020-04-25 18:02:19 -07:00
David Tolnay
b41e74c152
Test returning Vec by value from C to Rust 2020-04-25 18:02:18 -07:00
David Tolnay
de5340ec85
Test returning CxxVector by reference from C to Rust 2020-04-25 18:02:18 -07:00
David Tolnay
2244d1f553
Test passing CxxVector by reference from Rust to C 2020-04-25 18:02:17 -07:00
David Tolnay
1bcc9fe2e5
Test returning opaque types in CxxVector from C to Rust 2020-04-25 18:02:17 -07:00
David Tolnay
9b304204b7
Use more appropriate name for vector arguments in tests 2020-04-25 18:02:17 -07:00
David Tolnay
c87c215f56
Add begin/end iterators to rust::Vec 2020-04-25 18:02:15 -07:00
David Tolnay
e1dcdf7317
Parse vector's type as CxxVector 2020-04-25 18:02:13 -07:00
David Tolnay
c01d0a0f84
Rename CxxVector::size to len to match Rust conventions 2020-04-25 18:02:10 -07:00
David Tolnay
85db5a01b2
Touch up PR 67 2020-04-25 18:02:08 -07:00
David Tolnay
d1413040ae
Remove absolute paths in non-generated code 2020-04-25 18:02:07 -07:00
David Tolnay
4f6dd4e631
Simplify vector tests using UniquePtr deref 2020-04-25 18:02:07 -07:00
David Tolnay
507c2d75cf
Merge pull request #67 from myronahn/master
C++ std::vector<T> and Rust std::vec::Vec<T> support
2020-04-25 18:01:54 -07:00
David Tolnay
7c29546739
Revert some unrelated changes from PR 67 2020-04-25 13:13:43 -07:00
David Tolnay
37dd7e1174
Format with clang-format 2020-04-25 12:51:59 -07:00
Myron Ahn
eba35cfce7
C++ std::vector<T> and Rust std::vec::Vec<T> support
Add basic std::vector and std::vec::Vec support across FFI boundary.
2020-04-25 12:47:04 -07:00
David Tolnay
1044d44f30
Suppress irrelevant "required by this bound" from error message 2020-04-22 20:01:21 -07:00
David Tolnay
4b07ab92e3
Improve span of unsized opaque type error 2020-04-22 19:50:21 -07:00
David Tolnay
ab73957a4e
Add ui test for unnamed receiver type error message 2020-04-22 18:25:43 -07:00
David Tolnay
2dd73eaf03
Add ui test for reserved type names 2020-04-22 17:56:27 -07:00
David Tolnay
7a03847db2
Add ui test for unrecognized receiver type 2020-04-22 16:54:34 -07:00
David Tolnay
6d9f4aab20
Add ui test for disallowed lifetimes 2020-04-22 16:39:44 -07:00
Joel Galenson
e1e969d06f Allow &self without a type when the block only has one type 2020-04-22 08:44:49 -07:00
David Tolnay
5e29b217c3
Rely on UniquePtr Deref impl in tests 2020-04-17 16:44:03 -07:00
Joel Galenson
c1c4e7ac6b Support calling Rust methods from C++
These methods can be declared in the bridge by naming the first
argument self and making it a reference to the containing class, e.g.,
  fn get(self: &R) -> usize;
  fn set(self: &mut R, n: usize);
This syntax requires Rust 1.43.
2020-04-16 16:25:04 -07:00
Joel Galenson
3d4f612b34 Support calling C++ methods from Rust
These methods can be declared in the bridge by naming the first
argument self and making it a reference to the containing class, e.g.,
  fn get(self: &C) -> usize;
  fn set(self: &mut C, n: usize);
This syntax requires Rust 1.43.

Note that the implementation also changes the internal naming of shim
functions so that they also contain the name of the owning class, if
any.  This allows defining multiple methods with the same name on
different objects.
2020-04-16 16:24:48 -07:00
David Tolnay
633b1f5f1f
Switch C-style casting to reinterpret_casts 2020-04-14 16:42:06 -07:00
David Tolnay
efe81052e7
Touch up &[u8] PR 2020-04-14 16:42:06 -07:00
David Tolnay
eb952bac14
Format with rustfmt and clang-format 2020-04-14 16:42:06 -07:00
Adrian Taylor
ec9430e657 Adding missing tests; fixing typo. 2020-04-14 16:12:21 -07:00