cxx icon indicating copy to clipboard operation
cxx copied to clipboard

Improve error message on signatures containing self by value

Open dtolnay opened this issue 3 years ago • 2 comments

The current error is shown as:

error[cxxbridge]: unsupported signature
  ┌─ /dev/stdin:1:54
  │
1 │ #[cxx::bridge] mod ffi { extern "C++" { type T; fn f(self); }}
  │                                                      ^^^^ unsupported signature

Instead it should say what to use instead. &self or &mut self for shared structs and opaque Rust types, self: Pin<&mut Self> for an opaque C++ type, Box<T> or UniquePtr<T> if ownership needs to be transferred depending on opaque Rust or opaque C++ type.

dtolnay avatar Dec 13 '20 07:12 dtolnay

Regarding an improved error message...it doesn't seem like Box<T> receivers are supported currently? Did you intend to mention something else for the "if ownership needs to be transferred" case, or maybe there was an implied "use Box/UniquePtr but not as a method receiver" there?

sbrocket avatar Sep 14 '21 01:09 sbrocket

Yeah it would need to be a nonmember function where Box<T> or UniquePtr<T> is the argument type (as opposed to receiver).

dtolnay avatar Sep 14 '21 08:09 dtolnay