Commit Graph

435 Commits

Author SHA1 Message Date
David Tolnay
3df4cc84a1
Update ui test suite to nightly-2022-02-09 2022-02-08 18:34:22 -08:00
David Tolnay
47465d2bf1
Touch up PR 984 2021-12-31 13:36:34 -08:00
David Tolnay
a4bc81f48a
Merge pull request #984 from benesch/lossy
Add String::lossy constructors to C++ API
2021-12-31 13:19:37 -08:00
Nikhil Benesch
3724105cea
Add String::lossy constructors to C++ API
This constructor maps to `String::from_utf8_lossy` or
`String::from_utf16_lossy`. It's useful in situations where producing a
slightly garbled string on invalid Unicode data is preferable to
crashing the process, e.g. when passing error messages from C++ to Rust.
2021-12-27 13:26:09 -05:00
Nikhil Benesch
e3918b5422
Add Vec<T>::truncate to C++ API
Based on the model of #951, which added `Vec<T>::clear`. The `truncate`
method is the more general form of clear.

(If we wanted to, we could delete the binding for `clear` and implement
`clear` as a call to `truncate(0)` on the C++ side, but seemed worth
leaving in in case the Rust `clear` implementation one day gets
smarter.)
2021-12-26 15:18:50 -05:00
David Tolnay
def09ab798
Add link to cxx-async repo in async error message 2021-12-12 20:25:28 -08:00
David Tolnay
8e309b2f2d
Add an async extern C++ function to the ui test 2021-12-12 20:22:58 -08:00
David Tolnay
c756a7405d
Update ui test suite to nightly-2021-12-13 2021-12-12 19:09:16 -08:00
David Tolnay
5e076627a7
Add ui test with denied elided lifetime 2021-12-10 13:24:42 -08:00
David Tolnay
aa3e828402
Merge pull request #951 from rookboom/vector_clear
Add Vec clear
2021-12-08 17:11:50 -08:00
David Tolnay
b0b6fd8788
Add CI builds on no_std and no_alloc 2021-12-07 15:44:13 -08:00
David Tolnay
d2a3315eb5
Update ui test suite to nightly-2021-12-02 2021-12-01 18:52:35 -08:00
David Tolnay
9e55768c03
Update ui test suite to nightly-2021-11-22 2021-11-21 18:48:05 -08:00
David Tolnay
6d6a93d79c
Merge pull request #954 from hlopko/use_defs_bzl
Migrate cxx for bazelbuild/rules_rust#591
2021-10-26 19:40:45 -07:00
David Tolnay
6fec63d89d
Update ui tests to most recent trybuild normalization 2021-10-26 13:02:25 -07:00
Marcel Hlopko
0ad4fe5543 Migrate cxx for bazelbuild/rules_rust#591 2021-10-26 08:16:00 +02:00
David Tolnay
10173e5499
Update ui test suite to nightly-2021-10-26 2021-10-25 19:34:49 -07:00
David Tolnay
d8ef03b0da
Work around distracting guidance from rustc on types needed 2021-10-25 19:33:41 -07:00
Johan Verwey
54187c9e82
Added 'clear' method to rust::Vec 2021-10-20 08:10:32 -07:00
David Tolnay
9f83380038
Ui test changes for trybuild 1.0.49 2021-10-08 02:44:10 -04:00
David Tolnay
fff869fcda
Update ui test files 2021-10-07 00:40:08 -04:00
David Tolnay
36d9ac1fab
Update ui test suite to nightly-2021-09-14 2021-09-14 19:14:18 -07:00
David Tolnay
8f56cbbace
Expose capacity and reserve on rust::String 2021-08-27 13:14:05 -07:00
David Tolnay
f1e2af8472
Update ui test suite to nightly-2021-08-20 2021-08-19 20:38:47 -07:00
David Tolnay
4d45418b75
Update ui test suite to nightly-2021-08-18 2021-08-17 19:29:23 -07:00
David Tolnay
4309c43a5b
Remove rules that override rules_rust's default edition 2021-08-14 13:09:16 -07:00
David Tolnay
a104fd6b67
Tweak extern Rust Result spans to work with nightly-2021-08-12 2021-08-11 19:26:00 -07:00
David Tolnay
5369efd9bc
Update ui test suite to nightly-2021-08-12 2021-08-11 19:18:46 -07:00
Gerhard de Clercq
31a410246a Added UTF-16 rust::String initialization
This patch exposes String::from_utf16 to the C++ interface
for rust::String.
2021-08-03 07:17:20 +02:00
David Tolnay
20cb73ae6f
Support slice of trivial extern type alias 2021-07-23 14:16:46 -07:00
David Tolnay
17d3878b8b
Update ui test suite to nightly-2021-07-21 2021-07-20 19:44:26 -07:00
David Tolnay
17986044ec
Delete derive_nonclone ui test
Starting with nightly-2021-07-20, this test annoyingly produces
different diagnostics depending on whether the `rust-src` Rustup
component is installed, which is annoying for contributors running the
ui test suite locally. It is not super high value to have this test.
2021-07-19 20:58:09 -07:00
David Tolnay
b0df255cb6
Update ui test suite to nightly-2021-07-20 2021-07-19 19:21:16 -07:00
David Tolnay
db90502926
Update CxxVector autotrait diagnostic 2021-05-01 14:45:51 -07:00
David Tolnay
0fa63a1980
Add regression test of issue 857
This currently fails to compile.

    error: `extern` block uses type `String`, which is not FFI-safe
       --> tests/ffi/lib.rs:329:34
        |
    329 |     impl CxxVector<SharedString> {}
        |                                  ^^ not FFI-safe
        |
    note: the lint level is defined here
       --> tests/ffi/lib.rs:23:1
        |
    23  | #[cxx::bridge(namespace = "tests")]
        | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        = help: consider adding a `#[repr(C)]` or `#[repr(transparent)]` attribute to this struct
        = note: this struct has unspecified layout
        = note: this error originates in an attribute macro (in Nightly builds, run with -Z macro-backtrace for more info)
2021-05-01 14:40:37 -07:00
David Tolnay
9168da2514
Add ui test of CxxVector autotrait impls 2021-05-01 14:21:34 -07:00
David Tolnay
248994aa51
Tweak opaque type repr for slightly more evocative errors 2021-05-01 14:20:32 -07:00
David Tolnay
9521519a43
Add CxxVector::pop in Rust 2021-04-16 15:50:55 -07:00
David Tolnay
fc26d6d64c
Add CxxVector::push in Rust 2021-04-16 15:24:05 -07:00
David Tolnay
18c6016b04
Add regression test for issue 739
Currently fails to build.

    error[E0261]: use of undeclared lifetime name `'a`
       --> tests/ffi/lib.rs:162:59
        |
    23  | #[cxx::bridge(namespace = "tests")]
        |                                    - lifetime `'a` is missing in item created through this procedural macro
    ...
    162 |         fn c_take_callback_ref_lifetime<'a>(callback: fn(&'a String));
        |                                                           ^^ undeclared lifetime
        |
        = note: for more information on higher-ranked polymorphism, visit https://doc.rust-lang.org/nomicon/hrtb.html
        = help: if you want to experiment with in-band lifetime bindings, add `#![feature(in_band_lifetimes)]` to the crate attributes
    help: consider making the type lifetime-generic with a new `'a` lifetime
        |
    162 |         fn c_take_callback_ref_lifetime<'a>(callback: for<'a> fn(&'a String));
        |                                                       ^^^^^^^
2021-04-10 15:14:59 -07:00
David Tolnay
ea4656c88b
Suppress ptr_arg clippy lint in test suite
warning: writing `&String` instead of `&str` involves a new object where a slice will do
       --> tests/test.rs:207:24
        |
    207 |     fn callback_ref(s: &String) {
        |                        ^^^^^^^ help: change this to: `&str`
        |
        = note: `#[warn(clippy::ptr_arg)]` on by default
        = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#ptr_arg
2021-04-08 20:52:01 -07:00
David Tolnay
6e2223bf79
Add regression test for issue 738
Currently fails to build.

    In file included from cxx-test-suite-32b8d00ca9482f5f/out/cxxbridge/crate/tests/ffi/tests.h:2,
                     from tests.cc:1:
    cxx-test-suite-32b8d00ca9482f5f/out/cxxbridge/include/rust/cxx.h: In instantiation of ‘Ret rust::cxxbridge1::Fn<Ret(Args ...)>::operator()(Args ...) const [with Ret = void; Args = {rust::cxxbridge1::String&}]’:
    tests.cc:504:18:   required from here
    cxx-test-suite-32b8d00ca9482f5f/out/cxxbridge/include/rust/cxx.h:478:29: error: cannot bind non-const lvalue reference of type ‘rust::cxxbridge1::String&’ to an rvalue of type ‘std::remove_reference<rust::cxxbridge1::String&>::type’ {aka ‘rust::cxxbridge1::String’}
      478 |   return (*this->trampoline)(std::move(args)..., this->fn);
          |          ~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    cxx-test-suite-32b8d00ca9482f5f/out/cxxbridge/include/rust/cxx.h:478:58: error: return-statement with a value, in function returning ‘void’ [-fpermissive]
      478 |   return (*this->trampoline)(std::move(args)..., this->fn);
          |                                                          ^
2021-04-08 20:47:21 -07:00
David Tolnay
d7705ddaad
Add ui test of invalid use of 'static as lifetime param name 2021-04-08 18:12:51 -07:00
David Tolnay
035d798242
Update ui test suite to nightly-2021-04-09 2021-04-08 18:08:20 -07:00
David Tolnay
6723ac25ba
Update ui test suite to nightly-2021-04-08 2021-04-07 20:07:23 -07:00
David Tolnay
e294a2b52c
Fill in angle brackets with appropriate span if elided from impl key 2021-04-02 01:23:22 -04:00
David Tolnay
11064ffba0
Check in bad ui test output resulting from issue 805 2021-04-02 01:20:43 -04:00
David Tolnay
16dca756b8
Add ui test for type in uniqueptr expecting named lifetime 2021-04-02 01:20:12 -04:00
David Tolnay
847efb86f9
Add regression test of returning pinned mut opaque type
Currently fails to build:

    error[E0308]: mismatched types
      --> tests/ffi/module.rs:18:1
       |
    18 | #[cxx::bridge(namespace = "tests")]
       | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected struct `Pin`, found `&mut _`
       |
       = note:         expected struct `Pin<&mut other::E>`
               found mutable reference `&mut _`
       = note: this error originates in an attribute macro (in Nightly builds, run with -Z macro-backtrace for more info)

because we are generating this incorrect code on the Rust side:

    pub fn c_return_opaque_mut_pin(e: ::std::pin::Pin<&mut E>) -> ::std::pin::Pin<&mut E> {
        extern "C" {
            #[link_name = "tests$cxxbridge1$c_return_opaque_mut_pin"]
            fn __c_return_opaque_mut_pin(e: *mut ::std::ffi::c_void)
                -> *mut ::std::ffi::c_void;
        }
        unsafe {
            &mut *__c_return_opaque_mut_pin(
                ::std::pin::Pin::into_inner_unchecked(e) as *mut E as *mut ::std::ffi::c_void
            )
            .cast()
        }
    }
2021-03-30 18:04:32 -04:00
David Tolnay
22cb28882a
Recognize mutable slice in return position of a safe function 2021-03-28 04:23:06 -04:00