Skip to content

Commit

Permalink
cxx-qt-gen: don't import Pin in hidden module resolving IDE integration
Browse files Browse the repository at this point in the history
Now that impls are outside of the bridge the developer needs
to import Pin anyway.

Closes #417
  • Loading branch information
ahayzen-kdab authored and Be-ing committed Jul 21, 2023
1 parent a345666 commit 956c74f
Show file tree
Hide file tree
Showing 16 changed files with 69 additions and 74 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed

- Do not use -bundle otherwise CMake builds are missing qt-static-initalizers (note this is broken in rustc 1.69)
- Do not import `Pin` in hidden module as invokables are outside now, resolving IDE integration

### Removed

Expand Down
12 changes: 6 additions & 6 deletions crates/cxx-qt-gen/src/generator/rust/property/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ mod tests {
impl MyObject {
#[doc = "Setter for the Q_PROPERTY "]
#[doc = "trivial_property"]
pub fn set_trivial_property(mut self: Pin<&mut Self>, value: i32) {
pub fn set_trivial_property(mut self: core::pin::Pin<&mut Self>, value: i32) {
if self.trivial_property == value {
return;
}
Expand Down Expand Up @@ -180,7 +180,7 @@ mod tests {
impl MyObject {
#[doc = "Setter for the Q_PROPERTY "]
#[doc = "opaque_property"]
pub fn set_opaque_property(mut self: Pin<&mut Self>, value: UniquePtr<QColor>) {
pub fn set_opaque_property(mut self: core::pin::Pin<&mut Self>, value: UniquePtr<QColor>) {
if self.opaque_property == value {
return;
}
Expand Down Expand Up @@ -232,7 +232,7 @@ mod tests {
impl MyObject {
#[doc = "Setter for the Q_PROPERTY "]
#[doc = "unsafe_property"]
pub fn set_unsafe_property(mut self: Pin<&mut Self>, value: *mut T) {
pub fn set_unsafe_property(mut self: core::pin::Pin<&mut Self>, value: *mut T) {
if self.unsafe_property == value {
return;
}
Expand Down Expand Up @@ -278,7 +278,7 @@ mod tests {
#[doc = "\n"]
#[doc = "Note that this method uses a AutoConnection connection type."]
#[must_use]
pub fn on_trivial_property_changed(self: Pin<&mut MyObject>, func: fn(Pin<&mut MyObject>, )) -> CxxQtQMetaObjectConnection
pub fn on_trivial_property_changed(self: core::pin::Pin<&mut MyObject>, func: fn(core::pin::Pin<&mut MyObject>, )) -> CxxQtQMetaObjectConnection
{
self.connect_trivial_property_changed(func, CxxQtConnectionType::AutoConnection)
}
Expand Down Expand Up @@ -319,7 +319,7 @@ mod tests {
#[doc = "\n"]
#[doc = "Note that this method uses a AutoConnection connection type."]
#[must_use]
pub fn on_opaque_property_changed(self: Pin<&mut MyObject>, func: fn(Pin<&mut MyObject>, )) -> CxxQtQMetaObjectConnection
pub fn on_opaque_property_changed(self: core::pin::Pin<&mut MyObject>, func: fn(core::pin::Pin<&mut MyObject>, )) -> CxxQtQMetaObjectConnection
{
self.connect_opaque_property_changed(func, CxxQtConnectionType::AutoConnection)
}
Expand Down Expand Up @@ -360,7 +360,7 @@ mod tests {
#[doc = "\n"]
#[doc = "Note that this method uses a AutoConnection connection type."]
#[must_use]
pub fn on_unsafe_property_changed(self: Pin<&mut MyObject>, func: fn(Pin<&mut MyObject>, )) -> CxxQtQMetaObjectConnection
pub fn on_unsafe_property_changed(self: core::pin::Pin<&mut MyObject>, func: fn(core::pin::Pin<&mut MyObject>, )) -> CxxQtQMetaObjectConnection
{
self.connect_unsafe_property_changed(func, CxxQtConnectionType::AutoConnection)
}
Expand Down
2 changes: 1 addition & 1 deletion crates/cxx-qt-gen/src/generator/rust/property/setter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ pub fn generate(
impl #cpp_class_name_rust {
#[doc = "Setter for the Q_PROPERTY "]
#[doc = #ident_str]
pub fn #setter_rust(mut self: Pin<&mut Self>, value: #ty) {
pub fn #setter_rust(mut self: core::pin::Pin<&mut Self>, value: #ty) {
if self.#ident == value {
// don't want to set the value again and reemit the signal,
// as this can cause binding loops
Expand Down
21 changes: 12 additions & 9 deletions crates/cxx-qt-gen/src/generator/rust/signals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,13 @@ pub fn generate_rust_signals(
})
.collect::<Vec<TokenStream>>();

let self_type = if signal.mutable {
quote! { Pin<&mut #qobject_name> }
let (self_type, self_type_cxx) = if signal.mutable {
(
quote! { core::pin::Pin<&mut #qobject_name> },
quote! { Pin<&mut #qobject_name> },
)
} else {
quote! { &#qobject_name }
(quote! { &#qobject_name }, quote! { &#qobject_name })
};

let mut unsafe_block = None;
Expand All @@ -63,7 +66,7 @@ pub fn generate_rust_signals(
#unsafe_block extern "C++" {
#(#attrs)*
#[rust_name = #signal_name_rust_str]
#unsafe_call fn #signal_name_cpp(self: #self_type, #(#parameters),*);
#unsafe_call fn #signal_name_cpp(self: #self_type_cxx, #(#parameters),*);
}
},
quote! {
Expand All @@ -73,7 +76,7 @@ pub fn generate_rust_signals(
#[doc = ", so that when the signal is emitted the function pointer is executed."]
#[must_use]
#[rust_name = #connect_ident_rust_str]
fn #connect_ident_cpp(self: #self_type, func: #unsafe_call fn(#self_type, #(#parameters),*), conn_type: CxxQtConnectionType) -> CxxQtQMetaObjectConnection;
fn #connect_ident_cpp(self: #self_type_cxx, func: #unsafe_call fn(#self_type_cxx, #(#parameters),*), conn_type: CxxQtConnectionType) -> CxxQtQMetaObjectConnection;
}
},
],
Expand Down Expand Up @@ -169,7 +172,7 @@ mod tests {
#[doc = "\n"]
#[doc = "Note that this method uses a AutoConnection connection type."]
#[must_use]
pub fn on_ready(self: Pin<&mut MyObject>, func: fn(Pin<&mut MyObject>, )) -> CxxQtQMetaObjectConnection
pub fn on_ready(self: core::pin::Pin<&mut MyObject>, func: fn(core::pin::Pin<&mut MyObject>, )) -> CxxQtQMetaObjectConnection
{
self.connect_ready(func, CxxQtConnectionType::AutoConnection)
}
Expand Down Expand Up @@ -244,7 +247,7 @@ mod tests {
#[doc = "\n"]
#[doc = "Note that this method uses a AutoConnection connection type."]
#[must_use]
pub fn on_data_changed(self: Pin<&mut MyObject>, func: fn(Pin<&mut MyObject>, trivial: i32, opaque: UniquePtr<QColor>)) -> CxxQtQMetaObjectConnection
pub fn on_data_changed(self: core::pin::Pin<&mut MyObject>, func: fn(core::pin::Pin<&mut MyObject>, trivial: i32, opaque: UniquePtr<QColor>)) -> CxxQtQMetaObjectConnection
{
self.connect_data_changed(func, CxxQtConnectionType::AutoConnection)
}
Expand Down Expand Up @@ -311,7 +314,7 @@ mod tests {
#[doc = "\n"]
#[doc = "Note that this method uses a AutoConnection connection type."]
#[must_use]
pub fn on_unsafe_signal(self: Pin<&mut MyObject>, func: fn(Pin<&mut MyObject>, param: *mut T)) -> CxxQtQMetaObjectConnection
pub fn on_unsafe_signal(self: core::pin::Pin<&mut MyObject>, func: fn(core::pin::Pin<&mut MyObject>, param: *mut T)) -> CxxQtQMetaObjectConnection
{
self.connect_unsafe_signal(func, CxxQtConnectionType::AutoConnection)
}
Expand Down Expand Up @@ -377,7 +380,7 @@ mod tests {
#[doc = "\n"]
#[doc = "Note that this method uses a AutoConnection connection type."]
#[must_use]
pub fn on_existing_signal(self: Pin<&mut MyObject>, func: fn(Pin<&mut MyObject>, )) -> CxxQtQMetaObjectConnection
pub fn on_existing_signal(self: core::pin::Pin<&mut MyObject>, func: fn(core::pin::Pin<&mut MyObject>, )) -> CxxQtQMetaObjectConnection
{
self.connect_existing_signal(func, CxxQtConnectionType::AutoConnection)
}
Expand Down
12 changes: 6 additions & 6 deletions crates/cxx-qt-gen/src/generator/rust/threading.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ pub fn generate(
#[doc(hidden)]
fn queue<F>(cxx_qt_thread: &#cxx_qt_thread_ident, f: F) -> std::result::Result<(), cxx::Exception>
where
F: FnOnce(std::pin::Pin<&mut #cpp_struct_ident>),
F: FnOnce(core::pin::Pin<&mut #cpp_struct_ident>),
F: Send + 'static,
{
// Wrap the given closure and pass in to C++ function as an opaque type
Expand All @@ -102,7 +102,7 @@ pub fn generate(
#[allow(clippy::boxed_local)]
#[doc(hidden)]
fn func(
obj: std::pin::Pin<&mut #cpp_struct_ident>,
obj: core::pin::Pin<&mut #cpp_struct_ident>,
arg: std::boxed::Box<#cxx_qt_thread_queued_fn_ident>,
) {
(arg.inner)(obj)
Expand All @@ -129,7 +129,7 @@ pub fn generate(
pub struct #cxx_qt_thread_queued_fn_ident {
// An opaque Rust type is required to be Sized.
// https://github.com/dtolnay/cxx/issues/665
inner: std::boxed::Box<dyn FnOnce(std::pin::Pin<&mut #cpp_struct_ident>) + Send>,
inner: std::boxed::Box<dyn FnOnce(core::pin::Pin<&mut #cpp_struct_ident>) + Send>,
}
},
],
Expand Down Expand Up @@ -228,7 +228,7 @@ mod tests {
#[doc(hidden)]
fn queue<F>(cxx_qt_thread: &MyObjectCxxQtThread, f: F) -> std::result::Result<(), cxx::Exception>
where
F: FnOnce(std::pin::Pin<&mut MyObject>),
F: FnOnce(core::pin::Pin<&mut MyObject>),
F: Send + 'static,
{
// Wrap the given closure and pass in to C++ function as an opaque type
Expand All @@ -237,7 +237,7 @@ mod tests {
#[allow(clippy::boxed_local)]
#[doc(hidden)]
fn func(
obj: std::pin::Pin<&mut MyObject>,
obj: core::pin::Pin<&mut MyObject>,
arg: std::boxed::Box<MyObjectCxxQtThreadQueuedFn>,
) {
(arg.inner)(obj)
Expand Down Expand Up @@ -267,7 +267,7 @@ mod tests {
pub struct MyObjectCxxQtThreadQueuedFn {
// An opaque Rust type is required to be Sized.
// https://github.com/dtolnay/cxx/issues/665
inner: std::boxed::Box<dyn FnOnce(std::pin::Pin<&mut MyObject>) + Send>,
inner: std::boxed::Box<dyn FnOnce(core::pin::Pin<&mut MyObject>) + Send>,
}
},
);
Expand Down
11 changes: 4 additions & 7 deletions crates/cxx-qt-gen/src/writer/rust/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ fn cxx_qt_common_blocks(qobject: &GeneratedRustQObject) -> Vec<TokenStream> {
self.cxx_qt_ffi_rust()
}

fn rust_mut(self: core::pin::Pin<&mut Self>) -> Pin<&mut Self::Rust> {
fn rust_mut(self: core::pin::Pin<&mut Self>) -> core::pin::Pin<&mut Self::Rust> {
self.cxx_qt_ffi_rust_mut()
}
}
Expand Down Expand Up @@ -154,7 +154,6 @@ pub fn write_rust(generated: &GeneratedRustBlocks) -> TokenStream {
/// Internal CXX-Qt module, made public temporarily between API changes
pub mod #cxx_qt_mod_ident {
use super::#cxx_mod_ident::*;
use std::pin::Pin;
use cxx_qt::CxxQtType;

#[doc(hidden)]
Expand Down Expand Up @@ -359,7 +358,6 @@ mod tests {
#[doc = r" Internal CXX-Qt module, made public temporarily between API changes"]
pub mod cxx_qt_ffi {
use super::ffi::*;
use std::pin::Pin;
use cxx_qt::CxxQtType;

#[doc(hidden)]
Expand Down Expand Up @@ -389,7 +387,7 @@ mod tests {
fn rust(&self) -> &Self::Rust {
self.cxx_qt_ffi_rust()
}
fn rust_mut(self: core::pin::Pin<&mut Self>) -> Pin<&mut Self::Rust> {
fn rust_mut(self: core::pin::Pin<&mut Self>) -> core::pin::Pin<&mut Self::Rust> {
self.cxx_qt_ffi_rust_mut()
}
}
Expand Down Expand Up @@ -468,7 +466,6 @@ mod tests {
#[doc = r" Internal CXX-Qt module, made public temporarily between API changes"]
pub mod cxx_qt_ffi {
use super::ffi::*;
use std::pin::Pin;
use cxx_qt::CxxQtType;

#[doc(hidden)]
Expand Down Expand Up @@ -498,7 +495,7 @@ mod tests {
fn rust(&self) -> &Self::Rust {
self.cxx_qt_ffi_rust()
}
fn rust_mut(self: core::pin::Pin<&mut Self>) -> Pin<&mut Self::Rust> {
fn rust_mut(self: core::pin::Pin<&mut Self>) -> core::pin::Pin<&mut Self::Rust> {
self.cxx_qt_ffi_rust_mut()
}
}
Expand All @@ -525,7 +522,7 @@ mod tests {
fn rust(&self) -> &Self::Rust {
self.cxx_qt_ffi_rust()
}
fn rust_mut(self: core::pin::Pin<&mut Self>) -> Pin<&mut Self::Rust> {
fn rust_mut(self: core::pin::Pin<&mut Self>) -> core::pin::Pin<&mut Self::Rust> {
self.cxx_qt_ffi_rust_mut()
}
}
Expand Down
3 changes: 1 addition & 2 deletions crates/cxx-qt-gen/test_outputs/inheritance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ use self::cxx_qt_inheritance::*;
pub mod cxx_qt_inheritance {
use super::inheritance::*;
use cxx_qt::CxxQtType;
use std::pin::Pin;
#[doc(hidden)]
type UniquePtr<T> = cxx::UniquePtr<T>;
type MyObjectRust = super::MyObjectRust;
Expand All @@ -95,7 +94,7 @@ pub mod cxx_qt_inheritance {
fn rust(&self) -> &Self::Rust {
self.cxx_qt_ffi_rust()
}
fn rust_mut(self: core::pin::Pin<&mut Self>) -> Pin<&mut Self::Rust> {
fn rust_mut(self: core::pin::Pin<&mut Self>) -> core::pin::Pin<&mut Self::Rust> {
self.cxx_qt_ffi_rust_mut()
}
}
Expand Down
9 changes: 4 additions & 5 deletions crates/cxx-qt-gen/test_outputs/invokables.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,6 @@ use self::cxx_qt_ffi::*;
pub mod cxx_qt_ffi {
use super::ffi::*;
use cxx_qt::CxxQtType;
use std::pin::Pin;
#[doc(hidden)]
type UniquePtr<T> = cxx::UniquePtr<T>;
type MyObjectRust = super::MyObjectRust;
Expand All @@ -192,13 +191,13 @@ pub mod cxx_qt_ffi {
f: F,
) -> std::result::Result<(), cxx::Exception>
where
F: FnOnce(std::pin::Pin<&mut MyObject>),
F: FnOnce(core::pin::Pin<&mut MyObject>),
F: Send + 'static,
{
#[allow(clippy::boxed_local)]
#[doc(hidden)]
fn func(
obj: std::pin::Pin<&mut MyObject>,
obj: core::pin::Pin<&mut MyObject>,
arg: std::boxed::Box<MyObjectCxxQtThreadQueuedFn>,
) {
(arg.inner)(obj)
Expand All @@ -219,7 +218,7 @@ pub mod cxx_qt_ffi {
}
#[doc(hidden)]
pub struct MyObjectCxxQtThreadQueuedFn {
inner: std::boxed::Box<dyn FnOnce(std::pin::Pin<&mut MyObject>) + Send>,
inner: std::boxed::Box<dyn FnOnce(core::pin::Pin<&mut MyObject>) + Send>,
}
impl cxx_qt::Locking for MyObject {}
#[doc(hidden)]
Expand Down Expand Up @@ -276,7 +275,7 @@ pub mod cxx_qt_ffi {
fn rust(&self) -> &Self::Rust {
self.cxx_qt_ffi_rust()
}
fn rust_mut(self: core::pin::Pin<&mut Self>) -> Pin<&mut Self::Rust> {
fn rust_mut(self: core::pin::Pin<&mut Self>) -> core::pin::Pin<&mut Self::Rust> {
self.cxx_qt_ffi_rust_mut()
}
}
Expand Down
Loading

0 comments on commit 956c74f

Please sign in to comment.