Commit Graph

397 Commits

Author SHA1 Message Date
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
David Tolnay
6ca15ddb0c
Add ui test of mutable slice return from reference arguments 2021-03-28 04:23:05 -04:00
David Tolnay
6b026f572d
Format test suite with clang-format 11 2021-03-28 01:58:14 -04:00
David Tolnay
933ab95200
Further improve span of errors within implicit impls 2021-03-27 01:57:19 -04:00
David Tolnay
eb55cee41e
Improve span of errors on impls of type with lifetimes 2021-03-27 01:23:04 -04:00
David Tolnay
c547547b03
Add ui test of impls on a nonlocal Rust type 2021-03-27 01:23:04 -04:00
David Tolnay
7238e8d116
Add test of passing by alias type by pin mut ref 2021-03-27 01:04:27 -04:00
David Tolnay
b55bd6392b
Allow mutable return reference on signatures with any lifetime in argument 2021-03-26 17:59:14 -04:00
David Tolnay
944521ad0f
Add some more mut return ui tests 2021-03-26 17:58:38 -04:00
David Tolnay
4a024613f1
Fix wording of unsupported vector element type error
Vectors have elements, not targets. (Pointers, like unique_ptr and
shared_ptr, have targets -- matching the terminology of Target in the
std::ops::Deref trait.)
2021-03-26 17:14:24 -04:00
David Tolnay
04376c7d94
Permit mut from ref in unsafe-to-call signatures 2021-03-26 17:08:48 -04:00
David Tolnay
2dec4215e3
Include unsafe token in notional span of extern fn signatures 2021-03-26 17:07:54 -04:00
David Tolnay
ddfb7cdb39
Add ui test of checking mutable return from a shared reference argument 2021-03-26 17:07:05 -04:00
David Tolnay
453da7ff7d
Update ui test with public path of UniquePtrTarget 2021-03-25 02:09:16 -04:00
David Tolnay
5f04fda69d
Merge pull request #750 from dtolnay/pointers
Pointer to pointer, pointer to reference, reference to pointer
2021-03-22 19:41:13 -07:00
David Tolnay
d2d225c10c
East const to make nested pointer types work 2021-03-22 19:23:51 -07:00
David Tolnay
bd313d5e92
Add dedicated error message for ptr to ptr and ref to ptr 2021-03-22 19:23:51 -07:00
David Tolnay
2a2264c483
Add dedicated error message for pointer to reference 2021-03-22 19:23:50 -07:00
David Tolnay
aba7ab1bb0
Detect pointer argument inside of function pointer 2021-03-22 19:18:18 -07:00
David Tolnay
b8682334c8
Add failing ui test showing unsafety of fn ptr not enforced 2021-03-22 19:18:18 -07:00
David Tolnay
824d691923
Format PR 689 with clang-format 2021-03-22 19:06:06 -07:00
David Tolnay
7bb11c30ce
Sort pointer ffi test functions consistently 2021-03-22 19:06:05 -07:00
David Tolnay
d0af9d320e
Disable missing Unsafety doc comment clippy lint for test suite 2021-03-22 19:06:05 -07:00
David Tolnay
274c06f495
Divide up pointer UI tests 2021-03-22 19:06:04 -07:00
David Tolnay
7c3197eba8
Format PR 689 with rustfmt 2021-03-22 19:06:02 -07:00
David Tolnay
9fc8138823
Merge pull request #689 from adetaylor/pointers
Support raw pointers in cxx::bridge.
2021-03-22 19:04:37 -07:00
David Tolnay
de01edf706
Update C++ formatting to clang-format 11 2021-03-22 15:00:59 -07:00
adetaylor
f67287db6f
Merge branch 'master' into pointers 2021-02-17 15:32:06 -08:00
David Tolnay
da9f1b9471
Improve span of shared struct Drop error 2021-02-11 22:11:13 -08:00
David Tolnay
894ad11042
Update shared type drop test stderr file 2021-02-11 22:11:13 -08:00
David Tolnay
a910126402
Add ui test of handwritten Drop for shared struct 2021-02-11 22:11:13 -08:00
David Tolnay
dfafc8b210
Move span of inherited pub to next consecutive token 2021-02-11 22:03:48 -08:00
David Tolnay
624bab9123
Test Vec<usize> and Vec<isize> instantiation 2021-02-08 22:45:31 -08:00
David Tolnay
d15608434d
Touch up error message from PR 688 2021-02-07 13:36:35 -08:00
David Tolnay
14113b1c22
Merge pull request #688 from fletcherw/enum_receiver
Clarify error for using enum as method receiver
2021-02-07 13:34:56 -08:00
Adrian Taylor
7d51573f82 Merge branch 'master' of github.com:dtolnay/cxx into pointers 2021-02-05 15:03:02 -08:00
David Tolnay
2ed9d13d20
Ignore clippy upper_case_acronyms lint in ffi module
The user may prefer to use C++ naming conventions rather than Rust
naming conventions on the language boundary, which isn't necessarily
bad.
2021-01-31 18:55:55 -08:00
David Tolnay
9db5278dd4
Ignore upper_case_acronyms clippy lint
warning: name `CFG` contains a capitalized acronym
       --> gen/build/src/cfg.rs:350:9
        |
    350 |         CFG,
        |         ^^^ help: consider making the acronym lowercase, except the initial letter: `Cfg`
        |
        = note: `#[warn(clippy::upper_case_acronyms)]` on by default
        = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#upper_case_acronyms
2021-01-31 18:45:37 -08:00
David Tolnay
dcc1db841e
Add regression test of let_cxx_string in async fn
error: future cannot be sent between threads safely
      --> tests/cxx_string.rs:14:5
       |
    13 |     fn assert_send(_: impl Send) {}
       |                            ---- required by this bound in `assert_send`
    14 |     assert_send(f());
       |     ^^^^^^^^^^^ future returned by `f` is not `Send`
       |
       = help: within `impl Future`, the trait `Send` is not implemented for `*const ()`
    note: future is not `Send` as this value is used across an await
      --> tests/cxx_string.rs:9:9
       |
    6  |         let_cxx_string!(s = "...");
       |         --------------------------- has type `StackString` which is not `Send`
    ...
    9  |         g(&s).await;
       |         ^^^^^^^^^^^ await occurs here, with `mut $var` maybe used later
    10 |     }
       |     - `mut $var` is later dropped here
2021-01-27 11:25:48 -08:00